fix to be much less confusing

This commit is contained in:
Matthew Fosse 2024-04-26 14:29:38 -07:00
parent 653f3974e4
commit cb3289c99b
2 changed files with 11 additions and 16 deletions

View file

@ -4,7 +4,7 @@ Map<DerivationType, List<DerivationInfo>> bitcoin_derivations = {
DerivationType.electrum: [ DerivationType.electrum: [
DerivationInfo( DerivationInfo(
derivationType: DerivationType.electrum, derivationType: DerivationType.electrum,
derivationPath: "m/0'/0", derivationPath: "m/0'",
description: "Electrum", description: "Electrum",
scriptType: "p2wpkh", scriptType: "p2wpkh",
), ),

View file

@ -321,27 +321,21 @@ class CWBitcoin extends Bitcoin {
scriptType: dInfo.scriptType, scriptType: dInfo.scriptType,
); );
String derivationPath = dInfoCopy.derivationPath!; String rootPath = dInfoCopy.derivationPath!;
int derivationDepth = _countOccurrences(derivationPath, "/"); int rootDepth = _countOccurrences(rootPath, "/");
String pathForAccount0Index0 = rootPath;
// the correct derivation depth is dependant on the derivation type: // for BIP44/BIP49, we need to specify the index 0 for the first address:
// the derivation paths defined in bitcoin_derivations are at the ROOT level, i.e.: if (rootDepth == 3) {
// electrum's format doesn't specify subaddresses, just subaccounts: pathForAccount0Index0 += "/0/0";
} else {
// for BIP44 pathForAccount0Index0 += "/0";
if (derivationDepth == 3) {
// we add "/0/0" so that we generate account 0, index 0 and correctly get balance
derivationPath += "/0/0";
// we don't support sub-ACCOUNTS in bitcoin like we do monero, and so the path dInfoCopy
// expects should be ACCOUNT 0, index unspecified:
dInfoCopy.derivationPath = dInfoCopy.derivationPath! + "/0";
} }
// var hd = bip32.BIP32.fromSeed(seedBytes).derivePath(derivationPath);
final hd = btc.HDWallet.fromSeed( final hd = btc.HDWallet.fromSeed(
seedBytes, seedBytes,
network: networkType, network: networkType,
).derivePath(derivationPath); ).derivePath(pathForAccount0Index0);
String? address; String? address;
switch (dInfoCopy.scriptType) { switch (dInfoCopy.scriptType) {
@ -365,6 +359,7 @@ class CWBitcoin extends Bitcoin {
dInfoCopy.balance = balance.entries.first.value.toString(); dInfoCopy.balance = balance.entries.first.value.toString();
dInfoCopy.address = address; dInfoCopy.address = address;
dInfoCopy.transactionsCount = history.length; dInfoCopy.transactionsCount = history.length;
dInfoCopy.derivationPath = pathForAccount0Index0;
list.add(dInfoCopy); list.add(dInfoCopy);
} catch (e) { } catch (e) {