mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 22:58:49 +00:00
query/filter bch addresses using derivation path components
This commit is contained in:
parent
74ca8e1e07
commit
5145d4fc01
1 changed files with 14 additions and 11 deletions
|
@ -160,6 +160,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
.filter()
|
.filter()
|
||||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||||
|
.derivationPath((q) => q.not().valueStartsWith("m/44'/0'"))
|
||||||
.sortByDerivationIndexDesc()
|
.sortByDerivationIndexDesc()
|
||||||
.findFirst()) ??
|
.findFirst()) ??
|
||||||
await _generateAddressForChain(0, 0, DerivePathTypeExt.primaryFor(coin));
|
await _generateAddressForChain(0, 0, DerivePathTypeExt.primaryFor(coin));
|
||||||
|
@ -173,6 +174,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
.filter()
|
.filter()
|
||||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||||
|
.derivationPath((q) => q.not().valueStartsWith("m/44'/0'"))
|
||||||
.sortByDerivationIndexDesc()
|
.sortByDerivationIndexDesc()
|
||||||
.findFirst()) ??
|
.findFirst()) ??
|
||||||
await _generateAddressForChain(1, 0, DerivePathTypeExt.primaryFor(coin));
|
await _generateAddressForChain(1, 0, DerivePathTypeExt.primaryFor(coin));
|
||||||
|
@ -395,13 +397,9 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
isar_models.AddressType addrType;
|
isar_models.AddressType addrType;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DerivePathType.bip44:
|
case DerivePathType.bip44:
|
||||||
addressString = P2PKH(data: data, network: _network).data.address!;
|
|
||||||
addrType = isar_models.AddressType.p2pkh;
|
|
||||||
addressString = bitbox.Address.toCashAddress(addressString);
|
|
||||||
break;
|
|
||||||
case DerivePathType.bch44:
|
case DerivePathType.bch44:
|
||||||
addressString = P2PKH(data: data, network: _network).data.address!;
|
addressString = P2PKH(data: data, network: _network).data.address!;
|
||||||
addrType = isar_models.AddressType.unknown;
|
addrType = isar_models.AddressType.p2pkh;
|
||||||
addressString = bitbox.Address.toCashAddress(addressString);
|
addressString = bitbox.Address.toCashAddress(addressString);
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
case DerivePathType.bip49:
|
||||||
|
@ -1489,13 +1487,9 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
|
|
||||||
switch (derivePathType) {
|
switch (derivePathType) {
|
||||||
case DerivePathType.bip44:
|
case DerivePathType.bip44:
|
||||||
address = P2PKH(data: data, network: _network).data.address!;
|
|
||||||
addrType = isar_models.AddressType.p2pkh;
|
|
||||||
address = bitbox.Address.toCashAddress(address);
|
|
||||||
break;
|
|
||||||
case DerivePathType.bch44:
|
case DerivePathType.bch44:
|
||||||
address = P2PKH(data: data, network: _network).data.address!;
|
address = P2PKH(data: data, network: _network).data.address!;
|
||||||
addrType = isar_models.AddressType.unknown;
|
addrType = isar_models.AddressType.p2pkh;
|
||||||
address = bitbox.Address.toCashAddress(address);
|
address = bitbox.Address.toCashAddress(address);
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
case DerivePathType.bip49:
|
||||||
|
@ -1547,15 +1541,23 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
: isar_models.AddressSubType.change;
|
: isar_models.AddressSubType.change;
|
||||||
|
|
||||||
isar_models.AddressType type;
|
isar_models.AddressType type;
|
||||||
|
String coinType;
|
||||||
|
String purpose;
|
||||||
switch (derivePathType) {
|
switch (derivePathType) {
|
||||||
case DerivePathType.bip44:
|
case DerivePathType.bip44:
|
||||||
type = isar_models.AddressType.p2pkh;
|
type = isar_models.AddressType.p2pkh;
|
||||||
|
coinType = coin == Coin.bitcoincash ? "145" : "1";
|
||||||
|
purpose = "44";
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bch44:
|
case DerivePathType.bch44:
|
||||||
type = isar_models.AddressType.unknown;
|
type = isar_models.AddressType.p2pkh;
|
||||||
|
coinType = coin == Coin.bitcoincash ? "0" : "1";
|
||||||
|
purpose = "44";
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
case DerivePathType.bip49:
|
||||||
type = isar_models.AddressType.p2sh;
|
type = isar_models.AddressType.p2sh;
|
||||||
|
coinType = coin == Coin.bitcoincash ? "145" : "1";
|
||||||
|
purpose = "49";
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip84:
|
case DerivePathType.bip84:
|
||||||
throw UnsupportedError("bip84 not supported by BCH");
|
throw UnsupportedError("bip84 not supported by BCH");
|
||||||
|
@ -1568,6 +1570,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
.filter()
|
.filter()
|
||||||
.typeEqualTo(type)
|
.typeEqualTo(type)
|
||||||
.subTypeEqualTo(subType)
|
.subTypeEqualTo(subType)
|
||||||
|
.derivationPath((q) => q.valueStartsWith("m/$purpose'/$coinType"))
|
||||||
.sortByDerivationIndexDesc()
|
.sortByDerivationIndexDesc()
|
||||||
.findFirst();
|
.findFirst();
|
||||||
return address!.value;
|
return address!.value;
|
||||||
|
|
Loading…
Reference in a new issue