Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electrum sp refactors #1781

Open
wants to merge 100 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
e47846b
feat: begin delegated scan, big refactors
rafael-xmr Oct 4, 2024
7339b78
refactor: init
rafael-xmr Oct 28, 2024
64caf84
fix: restore flow slow, checking unspents
rafael-xmr Oct 29, 2024
433686b
feat: derivationinfo to address records
rafael-xmr Oct 30, 2024
f3a0ff7
feat: init electrum worker
rafael-xmr Oct 30, 2024
02fabf8
feat: electrum worker types
rafael-xmr Oct 31, 2024
4a4250a
feat: tx history worker
rafael-xmr Nov 1, 2024
a3e131d
feat: all address derivations
rafael-xmr Nov 4, 2024
c9a5023
feat: unspents and tweaks subscribe method
rafael-xmr Nov 5, 2024
a4561d2
chore: deps
rafael-xmr Nov 5, 2024
7964b2a
chore: deps
rafael-xmr Nov 5, 2024
884a822
fix: fee and addresses
rafael-xmr Nov 6, 2024
28804b8
Improve sending tx for electrum (#1790)
OmarHatem28 Nov 6, 2024
243f734
Merge branch 'main' into electrum-sp-refactors
OmarHatem28 Nov 6, 2024
57f4860
fix: tx dates
rafael-xmr Nov 7, 2024
a169db7
Merge remote-tracking branch 'origin/electrum-sp-refactors' into elec…
rafael-xmr Nov 7, 2024
6e8b3d7
misc
rafael-xmr Nov 7, 2024
d4b0165
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 12, 2024
3950f6c
refactor: misc
rafael-xmr Nov 16, 2024
cc853b9
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 16, 2024
75aaa6f
chore: build scripts
rafael-xmr Nov 17, 2024
378e160
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 17, 2024
aa6f932
chore: build errors
rafael-xmr Nov 17, 2024
b9f76bd
fix: btc create
rafael-xmr Nov 17, 2024
9bb3d9f
fix: btc restore
rafael-xmr Nov 17, 2024
c35dec0
feat: restore & scan imp
rafael-xmr Nov 23, 2024
b7ff9ab
fix: api & create
rafael-xmr Nov 23, 2024
e16a218
feat: fix rescan & stop, new card
rafael-xmr Nov 24, 2024
d30c852
chore: build
rafael-xmr Nov 24, 2024
74bae5d
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 27, 2024
3ee697b
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 27, 2024
95bb566
a
rafael-xmr Nov 27, 2024
046d30b
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 28, 2024
a2bbd6a
fix: change addr
rafael-xmr Nov 28, 2024
143e5d7
Revert 95bb566d09a7146c3b0b7b9a3183c1e969da6ee8
rafael-xmr Nov 28, 2024
cde88c0
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Nov 29, 2024
a97b552
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Dec 9, 2024
8264d38
fix: null check
rafael-xmr Dec 9, 2024
183fd89
chore: deps
rafael-xmr Dec 9, 2024
b927af9
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Dec 9, 2024
f702a19
chore: printVs
rafael-xmr Dec 9, 2024
6cbb4c6
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Dec 16, 2024
51590a6
feat: tx broadcast, error handling, remove electrum.dart
rafael-xmr Dec 19, 2024
dded5a7
Merge branch 'main' into electrum-sp-refactors
OmarHatem28 Dec 20, 2024
1646a67
fix: scan
rafael-xmr Dec 20, 2024
321bc1e
Merge remote-tracking branch 'origin/electrum-sp-refactors' into elec…
rafael-xmr Dec 20, 2024
a07be3d
chore: prints
rafael-xmr Dec 20, 2024
fb5aa9d
feat: fee estimation, review comments
rafael-xmr Dec 26, 2024
5284fd8
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Dec 26, 2024
cf9d64b
chore: build
rafael-xmr Dec 26, 2024
081a250
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Dec 27, 2024
bcf9aae
refactor: reviews
rafael-xmr Dec 30, 2024
6019370
refactor: reviews
rafael-xmr Jan 2, 2025
da478f3
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 2, 2025
4594990
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 7, 2025
c21d163
refactor: reviewing [skip ci]
rafael-xmr Jan 7, 2025
ad607e0
refactor: reviewing [skip ci]
rafael-xmr Jan 8, 2025
de773b3
refactor: reduce unneeded [skip ci]
rafael-xmr Jan 8, 2025
a6c021e
feat: fixes & improvements around fee types [skip ci]
rafael-xmr Jan 8, 2025
a09cb62
refactor: misc [skip ci]
rafael-xmr Jan 8, 2025
7436140
Merge branch 'main' into electrum-sp-refactors
OmarHatem28 Jan 9, 2025
1c5be4c
feat: merging bitcoin_base & blockchain_utils
rafael-xmr Jan 10, 2025
c10b9c2
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 13, 2025
d7d12f0
fix: review comments and backward compatibility
rafael-xmr Jan 14, 2025
24a0b45
Merge remote-tracking branch 'origin/electrum-sp-refactors' into elec…
rafael-xmr Jan 14, 2025
73fe865
chore: deps
rafael-xmr Jan 14, 2025
91f0f87
Update pubspec.yaml
rafael-xmr Jan 14, 2025
83ba770
refactor: reviewing [skip ci]
rafael-xmr Jan 14, 2025
092f499
Merge remote-tracking branch 'origin/electrum-sp-refactors' into elec…
rafael-xmr Jan 14, 2025
3a3d4f6
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors…
rafael-xmr Jan 14, 2025
7a18a89
refactor: minor unneeded [skip ci]
rafael-xmr Jan 14, 2025
a2bf180
feat: batch requests
rafael-xmr Jan 15, 2025
5b60350
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 15, 2025
f1345fa
chore: print
rafael-xmr Jan 15, 2025
f3e96c6
chore: temp fix
rafael-xmr Jan 15, 2025
7ef28df
Revert "chore: temp fix"
rafael-xmr Jan 15, 2025
c3fdc5e
feat: improve batch request even further, make initial faster
rafael-xmr Jan 16, 2025
ec48810
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 16, 2025
e3058c9
feat(batch): fix initial sync + date update
rafael-xmr Jan 16, 2025
06762e7
feat: batch in sequences, misc reviews
rafael-xmr Jan 21, 2025
ba7bf95
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 21, 2025
aa5cb8d
feat: subscription batch, addresses & scripthashes
rafael-xmr Jan 22, 2025
47386d2
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 22, 2025
3cc7fba
fix(worker): server capability for tx verbose
rafael-xmr Jan 23, 2025
7da30d8
fallback to electrum get fees if mempool api failed
OmarHatem28 Jan 23, 2025
309dca9
feat: misc reviews
rafael-xmr Jan 24, 2025
be1b964
fix: address list
rafael-xmr Jan 24, 2025
d8ea6db
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 27, 2025
e7cae89
chore: merge
rafael-xmr Jan 27, 2025
5ae8b44
chore: prints
rafael-xmr Jan 27, 2025
dacbe83
fix: scan & address book
rafael-xmr Jan 27, 2025
7ed38b7
fix: sp label index
rafael-xmr Jan 28, 2025
6e80279
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Jan 28, 2025
d5b6295
Merge branch 'main' into electrum-sp-refactors
rafael-xmr Feb 5, 2025
f1d47ac
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Feb 10, 2025
8a590bf
fix: cant sync, change addr switch [skip ci]
rafael-xmr Feb 10, 2025
4015d32
feat: more address gen improvements [skip ci]
rafael-xmr Feb 11, 2025
da37e11
feat: fix missing addrs
rafael-xmr Feb 14, 2025
8966116
Merge remote-tracking branch 'origin/main' into electrum-sp-refactors
rafael-xmr Feb 14, 2025
b9f70cf
misc
rafael-xmr Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: batch in sequences, misc reviews
rafael-xmr committed Jan 21, 2025
commit 06762e7abc391c744cb075d44c6b1c212d189c3f
54 changes: 11 additions & 43 deletions cw_bitcoin/lib/bitcoin_wallet.dart
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ import 'package:cw_bitcoin/pending_bitcoin_transaction.dart';
import 'package:cw_bitcoin/psbt_transaction_builder.dart';
import 'package:cw_bitcoin/bitcoin_unspent.dart';
import 'package:cw_bitcoin/electrum_transaction_info.dart';
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
import 'package:cw_bitcoin/wallet_seed_bytes.dart';
import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_bitcoin/electrum_derivations.dart';
import 'package:cw_bitcoin/bitcoin_wallet_addresses.dart';
@@ -45,45 +43,32 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
bool allowedToSwitchNodesForScanning = false;

BitcoinWalletBase({
required String password,
required WalletInfo walletInfo,
required Box<UnspentCoinsInfo> unspentCoinsInfo,
required EncryptionFileUtils encryptionFileUtils,
List<int>? seedBytes,
String? mnemonic,
String? xpub,
required super.password,
required super.walletInfo,
required super.unspentCoinsInfo,
required super.encryptionFileUtils,
super.mnemonic,
super.xpub,
String? addressPageType,
BasedUtxoNetwork? networkParam,
List<BitcoinAddressRecord>? initialAddresses,
ElectrumBalance? initialBalance,
super.initialBalance,
Map<String, int>? initialRegularAddressIndex,
Map<String, int>? initialChangeAddressIndex,
String? passphrase,
super.passphrase,
List<BitcoinSilentPaymentAddressRecord>? initialSilentAddresses,
int initialSilentAddressIndex = 0,
bool? alwaysScan,
super.hdWallets,
super.alwaysScan,
super.initialUnspentCoins,
super.didInitialSync,
}) : super(
mnemonic: mnemonic,
passphrase: passphrase,
xpub: xpub,
password: password,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
network: networkParam == null
? BitcoinNetwork.mainnet
: networkParam == BitcoinNetwork.mainnet
? BitcoinNetwork.mainnet
: BitcoinNetwork.testnet,
initialAddresses: initialAddresses,
initialBalance: initialBalance,
seedBytes: seedBytes,
encryptionFileUtils: encryptionFileUtils,
currency:
networkParam == BitcoinNetwork.testnet ? CryptoCurrency.tbtc : CryptoCurrency.btc,
alwaysScan: alwaysScan,
) {
walletAddresses = BitcoinWalletAddresses(
walletInfo,
@@ -115,8 +100,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
Map<String, int>? initialChangeAddressIndex,
int initialSilentAddressIndex = 0,
}) async {
final walletSeedBytes = await WalletSeedBytes.getSeedBytes(walletInfo, mnemonic, passphrase);

return BitcoinWallet(
mnemonic: mnemonic,
passphrase: passphrase ?? "",
@@ -128,8 +111,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
initialSilentAddressIndex: initialSilentAddressIndex,
initialBalance: initialBalance,
encryptionFileUtils: encryptionFileUtils,
seedBytes: walletSeedBytes.seedBytes,
hdWallets: walletSeedBytes.hdWallets,
initialRegularAddressIndex: initialRegularAddressIndex,
initialChangeAddressIndex: initialChangeAddressIndex,
addressPageType: addressPageType,
@@ -188,36 +169,23 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
walletInfo.derivationInfo!.derivationPath ??= snp?.derivationPath ?? electrum_path;
walletInfo.derivationInfo!.derivationType ??= snp?.derivationType ?? DerivationType.electrum;

List<int>? seedBytes = null;
final Map<CWBitcoinDerivationType, Bip32Slip10Secp256k1> hdWallets = {};
final mnemonic = keysData.mnemonic;
final passphrase = keysData.passphrase;

if (mnemonic != null) {
final walletSeedBytes = await WalletSeedBytes.getSeedBytes(walletInfo, mnemonic, passphrase);
seedBytes = walletSeedBytes.seedBytes;
hdWallets.addAll(walletSeedBytes.hdWallets);
}

return BitcoinWallet(
mnemonic: mnemonic,
mnemonic: keysData.mnemonic,
xpub: keysData.xPub,
password: password,
passphrase: passphrase,
passphrase: keysData.passphrase,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
initialAddresses: snp?.addresses,
initialSilentAddresses: snp?.silentAddresses,
initialSilentAddressIndex: snp?.silentAddressIndex ?? 0,
initialBalance: snp?.balance,
encryptionFileUtils: encryptionFileUtils,
seedBytes: seedBytes,
initialRegularAddressIndex: snp?.regularAddressIndex,
initialChangeAddressIndex: snp?.changeAddressIndex,
addressPageType: snp?.addressPageType,
networkParam: network,
alwaysScan: alwaysScan,
hdWallets: hdWallets,
initialUnspentCoins: snp?.unspentCoins,
didInitialSync: snp?.didInitialSync,
);
11 changes: 9 additions & 2 deletions cw_bitcoin/lib/bitcoin_wallet_addresses.dart
Original file line number Diff line number Diff line change
@@ -9,8 +9,6 @@ part 'bitcoin_wallet_addresses.g.dart';

class BitcoinWalletAddresses = BitcoinWalletAddressesBase with _$BitcoinWalletAddresses;

const OLD_SP_SPEND_PATH = "m/352'/1'/0'/0'/0";

abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with Store {
BitcoinWalletAddressesBase(
WalletInfo walletInfo, {
@@ -31,6 +29,15 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
silentPaymentWallets = [silentPaymentWallet!];
}

static const OLD_SP_SPEND_PATH = "m/352'/1'/0'/0'/0";
static const BITCOIN_ADDRESS_TYPES = [
SegwitAddressType.p2wpkh,
P2pkhAddressType.p2pkh,
SegwitAddressType.p2tr,
SegwitAddressType.p2wsh,
P2shAddressType.p2wpkhInP2sh,
];

@observable
SilentPaymentOwner? silentPaymentWallet;
final ObservableList<BitcoinSilentPaymentAddressRecord> silentPaymentAddresses;
36 changes: 25 additions & 11 deletions cw_bitcoin/lib/electrum_transaction_info.dart
Original file line number Diff line number Diff line change
@@ -46,6 +46,8 @@ class ElectrumTransactionBundle {
class ElectrumTransactionInfo extends TransactionInfo {
bool isReceivedSilentPayment;
int? time;
List<BtcTransaction>? ins;
BtcTransaction? original;

ElectrumTransactionInfo(
this.type, {
@@ -65,6 +67,8 @@ class ElectrumTransactionInfo extends TransactionInfo {
String? to,
this.isReceivedSilentPayment = false,
Map<String, dynamic>? additionalInfo,
this.ins,
this.original,
}) {
this.id = id;
this.height = height;
@@ -156,17 +160,19 @@ class ElectrumTransactionInfo extends TransactionInfo {
List<String> inputAddresses = [];
List<String> outputAddresses = [];

for (var i = 0; i < bundle.originalTransaction.inputs.length; i++) {
final input = bundle.originalTransaction.inputs[i];
final inputTransaction = bundle.ins[i];
final outTransaction = inputTransaction.outputs[input.txIndex];
inputAmount += outTransaction.amount.toInt();
if (addresses.contains(
BitcoinAddressUtils.addressFromOutputScript(outTransaction.scriptPubKey, network))) {
direction = TransactionDirection.outgoing;
inputAddresses.add(
BitcoinAddressUtils.addressFromOutputScript(outTransaction.scriptPubKey, network),
);
if (bundle.ins.length > 0) {
for (var i = 0; i < bundle.originalTransaction.inputs.length; i++) {
final input = bundle.originalTransaction.inputs[i];
final inputTransaction = bundle.ins[i];
final outTransaction = inputTransaction.outputs[input.txIndex];
inputAmount += outTransaction.amount.toInt();
if (addresses.contains(
BitcoinAddressUtils.addressFromOutputScript(outTransaction.scriptPubKey, network))) {
direction = TransactionDirection.outgoing;
inputAddresses.add(
BitcoinAddressUtils.addressFromOutputScript(outTransaction.scriptPubKey, network),
);
}
}
}

@@ -226,6 +232,8 @@ class ElectrumTransactionInfo extends TransactionInfo {
confirmations: bundle.confirmations,
time: bundle.time,
isDateValidated: bundle.isDateValidated,
ins: bundle.ins,
original: bundle.originalTransaction,
);
}

@@ -253,6 +261,10 @@ class ElectrumTransactionInfo extends TransactionInfo {
time: data['time'] as int?,
isDateValidated: data['isDateValidated'] as bool?,
additionalInfo: data['additionalInfo'] as Map<String, dynamic>?,
ins:
(data['ins'] as List<dynamic>?)?.map((e) => BtcTransaction.fromRaw(e as String)).toList(),
original:
data['original'] != null ? BtcTransaction.fromRaw(data['original'] as String) : null,
);
}

@@ -312,6 +324,8 @@ class ElectrumTransactionInfo extends TransactionInfo {
m['isReceivedSilentPayment'] = isReceivedSilentPayment;
m['additionalInfo'] = additionalInfo;
m['isDateValidated'] = isDateValidated;
m['ins'] = ins?.map((e) => e.toHex()).toList();
m['original'] = original?.toHex();
return m;
}

Loading