mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
Merge remote-tracking branch 'origin/staging' into paynyms
# Conflicts: # lib/services/coins/bitcoincash/bitcoincash_wallet.dart
This commit is contained in:
commit
dc581cd4fc
9 changed files with 209 additions and 68 deletions
|
@ -106,7 +106,7 @@ bip32.BIP32 getBip32NodeFromRoot(
|
|||
case DerivePathType.bip84:
|
||||
return root.derivePath("m/84'/$coinType'/0'/$chain/$index");
|
||||
default:
|
||||
throw Exception("DerivePathType must not be null.");
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,7 @@ class BitcoinWallet extends CoinServiceAPI
|
|||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("No Path type $type exists");
|
||||
throw Exception("DerivePathType $type not supported");
|
||||
}
|
||||
|
||||
final address = isar_models.Address(
|
||||
|
@ -1572,6 +1572,8 @@ class BitcoinWallet extends CoinServiceAPI
|
|||
address = P2WPKH(network: _network, data: data).data.address!;
|
||||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
|
||||
// add generated address & info to derivations
|
||||
|
@ -1618,6 +1620,8 @@ class BitcoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
type = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
address = await db
|
||||
.getAddresses(walletId)
|
||||
|
@ -1645,6 +1649,8 @@ class BitcoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
key = "${walletId}_${chainId}DerivationsP2WPKH";
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
@ -2657,6 +2663,8 @@ class BitcoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
addressesP2WPKH.add(address);
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ bip32.BIP32 getBip32NodeFromRoot(
|
|||
String coinType;
|
||||
switch (root.network.wif) {
|
||||
case 0x80: // bch mainnet wif
|
||||
coinType = "145"; // bch mainnet
|
||||
coinType =
|
||||
derivePathType == DerivePathType.bch44 ? "145" : "0"; // bch mainnet
|
||||
break;
|
||||
case 0xef: // bch testnet wif
|
||||
coinType = "1"; // bch testnet
|
||||
|
@ -87,6 +88,7 @@ bip32.BIP32 getBip32NodeFromRoot(
|
|||
}
|
||||
switch (derivePathType) {
|
||||
case DerivePathType.bip44:
|
||||
case DerivePathType.bch44:
|
||||
return root.derivePath("m/44'/$coinType'/0'/$chain/$index");
|
||||
case DerivePathType.bip49:
|
||||
return root.derivePath("m/49'/$coinType'/0'/$chain/$index");
|
||||
|
@ -329,6 +331,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
mnemonic: mnemonic.trim(),
|
||||
maxUnusedAddressGap: maxUnusedAddressGap,
|
||||
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
|
||||
coin: coin,
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -387,6 +390,11 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
addrType = isar_models.AddressType.p2pkh;
|
||||
addressString = bitbox.Address.toCashAddress(addressString);
|
||||
break;
|
||||
case DerivePathType.bch44:
|
||||
addressString = P2PKH(data: data, network: _network).data.address!;
|
||||
addrType = isar_models.AddressType.unknown;
|
||||
addressString = bitbox.Address.toCashAddress(addressString);
|
||||
break;
|
||||
case DerivePathType.bip49:
|
||||
addressString = P2SH(
|
||||
data: PaymentData(
|
||||
|
@ -397,7 +405,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
addrType = isar_models.AddressType.p2sh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("No Path type $type exists");
|
||||
throw Exception("DerivePathType $type not supported");
|
||||
}
|
||||
|
||||
final address = isar_models.Address(
|
||||
|
@ -488,24 +496,31 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
int maxUnusedAddressGap = 20,
|
||||
int maxNumberOfIndexesToCheck = 1000,
|
||||
bool isRescan = false,
|
||||
Coin? coin,
|
||||
}) async {
|
||||
longMutex = true;
|
||||
|
||||
Map<String, Map<String, String>> p2pkhReceiveDerivations = {};
|
||||
Map<String, Map<String, String>> bip44P2pkhReceiveDerivations = {};
|
||||
Map<String, Map<String, String>> bch44P2pkhReceiveDerivations = {};
|
||||
Map<String, Map<String, String>> p2shReceiveDerivations = {};
|
||||
Map<String, Map<String, String>> p2pkhChangeDerivations = {};
|
||||
Map<String, Map<String, String>> bip44P2pkhChangeDerivations = {};
|
||||
Map<String, Map<String, String>> bch44P2pkhChangeDerivations = {};
|
||||
Map<String, Map<String, String>> p2shChangeDerivations = {};
|
||||
|
||||
final root = await compute(getBip32RootWrapper, Tuple2(mnemonic, _network));
|
||||
|
||||
List<isar_models.Address> p2pkhReceiveAddressArray = [];
|
||||
List<isar_models.Address> bip44P2pkhReceiveAddressArray = [];
|
||||
List<isar_models.Address> bch44P2pkhReceiveAddressArray = [];
|
||||
List<isar_models.Address> p2shReceiveAddressArray = [];
|
||||
int p2pkhReceiveIndex = -1;
|
||||
int bch44P2pkhReceiveIndex = -1;
|
||||
int bip44P2pkhReceiveIndex = -1;
|
||||
int p2shReceiveIndex = -1;
|
||||
|
||||
List<isar_models.Address> p2pkhChangeAddressArray = [];
|
||||
List<isar_models.Address> bip44P2pkhChangeAddressArray = [];
|
||||
List<isar_models.Address> bch44P2pkhChangeAddressArray = [];
|
||||
List<isar_models.Address> p2shChangeAddressArray = [];
|
||||
int p2pkhChangeIndex = -1;
|
||||
int bch44P2pkhChangeIndex = -1;
|
||||
int bip44P2pkhChangeIndex = -1;
|
||||
int p2shChangeIndex = -1;
|
||||
|
||||
// The gap limit will be capped at [maxUnusedAddressGap]
|
||||
|
@ -516,10 +531,11 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
const txCountBatchSize = 12;
|
||||
|
||||
try {
|
||||
bool testnet = ((coin ?? null) == Coin.bitcoincashTestnet) ? true : false;
|
||||
// receiving addresses
|
||||
Logging.instance
|
||||
.log("checking receiving addresses...", level: LogLevel.Info);
|
||||
final resultReceive44 = _checkGaps(maxNumberOfIndexesToCheck,
|
||||
final resultReceiveBip44 = _checkGaps(maxNumberOfIndexesToCheck,
|
||||
maxUnusedAddressGap, txCountBatchSize, root, DerivePathType.bip44, 0);
|
||||
|
||||
final resultReceive49 = _checkGaps(maxNumberOfIndexesToCheck,
|
||||
|
@ -528,23 +544,23 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Logging.instance
|
||||
.log("checking change addresses...", level: LogLevel.Info);
|
||||
// change addresses
|
||||
final resultChange44 = _checkGaps(maxNumberOfIndexesToCheck,
|
||||
final bip44ResultChange = _checkGaps(maxNumberOfIndexesToCheck,
|
||||
maxUnusedAddressGap, txCountBatchSize, root, DerivePathType.bip44, 1);
|
||||
|
||||
final resultChange49 = _checkGaps(maxNumberOfIndexesToCheck,
|
||||
maxUnusedAddressGap, txCountBatchSize, root, DerivePathType.bip49, 1);
|
||||
|
||||
await Future.wait([
|
||||
resultReceive44,
|
||||
resultReceiveBip44,
|
||||
resultReceive49,
|
||||
resultChange44,
|
||||
bip44ResultChange,
|
||||
resultChange49,
|
||||
]);
|
||||
|
||||
p2pkhReceiveAddressArray =
|
||||
(await resultReceive44)['addressArray'] as List<isar_models.Address>;
|
||||
p2pkhReceiveIndex = (await resultReceive44)['index'] as int;
|
||||
p2pkhReceiveDerivations = (await resultReceive44)['derivations']
|
||||
bip44P2pkhReceiveAddressArray = (await resultReceiveBip44)['addressArray']
|
||||
as List<isar_models.Address>;
|
||||
bip44P2pkhReceiveIndex = (await resultReceiveBip44)['index'] as int;
|
||||
bip44P2pkhReceiveDerivations = (await resultReceiveBip44)['derivations']
|
||||
as Map<String, Map<String, String>>;
|
||||
|
||||
p2shReceiveAddressArray =
|
||||
|
@ -553,10 +569,10 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
p2shReceiveDerivations = (await resultReceive49)['derivations']
|
||||
as Map<String, Map<String, String>>;
|
||||
|
||||
p2pkhChangeAddressArray =
|
||||
(await resultChange44)['addressArray'] as List<isar_models.Address>;
|
||||
p2pkhChangeIndex = (await resultChange44)['index'] as int;
|
||||
p2pkhChangeDerivations = (await resultChange44)['derivations']
|
||||
bip44P2pkhChangeAddressArray = (await bip44ResultChange)['addressArray']
|
||||
as List<isar_models.Address>;
|
||||
bip44P2pkhChangeIndex = (await bip44ResultChange)['index'] as int;
|
||||
bip44P2pkhChangeDerivations = (await bip44ResultChange)['derivations']
|
||||
as Map<String, Map<String, String>>;
|
||||
|
||||
p2shChangeAddressArray =
|
||||
|
@ -566,11 +582,11 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
as Map<String, Map<String, String>>;
|
||||
|
||||
// save the derivations (if any)
|
||||
if (p2pkhReceiveDerivations.isNotEmpty) {
|
||||
if (bip44P2pkhReceiveDerivations.isNotEmpty) {
|
||||
await addDerivations(
|
||||
chain: 0,
|
||||
derivePathType: DerivePathType.bip44,
|
||||
derivationsToAdd: p2pkhReceiveDerivations);
|
||||
derivationsToAdd: bip44P2pkhReceiveDerivations);
|
||||
}
|
||||
if (p2shReceiveDerivations.isNotEmpty) {
|
||||
await addDerivations(
|
||||
|
@ -578,11 +594,11 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
derivePathType: DerivePathType.bip49,
|
||||
derivationsToAdd: p2shReceiveDerivations);
|
||||
}
|
||||
if (p2pkhChangeDerivations.isNotEmpty) {
|
||||
if (bip44P2pkhChangeDerivations.isNotEmpty) {
|
||||
await addDerivations(
|
||||
chain: 1,
|
||||
derivePathType: DerivePathType.bip44,
|
||||
derivationsToAdd: p2pkhChangeDerivations);
|
||||
derivationsToAdd: bip44P2pkhChangeDerivations);
|
||||
}
|
||||
if (p2shChangeDerivations.isNotEmpty) {
|
||||
await addDerivations(
|
||||
|
@ -593,10 +609,10 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
|
||||
// If restoring a wallet that never received any funds, then set receivingArray manually
|
||||
// If we didn't do this, it'd store an empty array
|
||||
if (p2pkhReceiveIndex == -1) {
|
||||
if (bip44P2pkhReceiveIndex == -1) {
|
||||
final address =
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip44);
|
||||
p2pkhReceiveAddressArray.add(address);
|
||||
bip44P2pkhReceiveAddressArray.add(address);
|
||||
}
|
||||
if (p2shReceiveIndex == -1) {
|
||||
final address =
|
||||
|
@ -606,10 +622,10 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
|
||||
// If restoring a wallet that never sent any funds with change, then set changeArray
|
||||
// manually. If we didn't do this, it'd store an empty array.
|
||||
if (p2pkhChangeIndex == -1) {
|
||||
if (bip44P2pkhChangeIndex == -1) {
|
||||
final address =
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip44);
|
||||
p2pkhChangeAddressArray.add(address);
|
||||
bip44P2pkhChangeAddressArray.add(address);
|
||||
}
|
||||
if (p2shChangeIndex == -1) {
|
||||
final address =
|
||||
|
@ -617,20 +633,99 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
p2shChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
if (isRescan) {
|
||||
await db.updateOrPutAddresses([
|
||||
...p2pkhReceiveAddressArray,
|
||||
...p2pkhChangeAddressArray,
|
||||
...p2shReceiveAddressArray,
|
||||
...p2shChangeAddressArray,
|
||||
if (!testnet) {
|
||||
final resultReceiveBch44 = _checkGaps(
|
||||
maxNumberOfIndexesToCheck,
|
||||
maxUnusedAddressGap,
|
||||
txCountBatchSize,
|
||||
root,
|
||||
DerivePathType.bch44,
|
||||
0);
|
||||
final Future<Map<String, dynamic>> bch44ResultChange = _checkGaps(
|
||||
maxNumberOfIndexesToCheck,
|
||||
maxUnusedAddressGap,
|
||||
txCountBatchSize,
|
||||
root,
|
||||
DerivePathType.bch44,
|
||||
1);
|
||||
await Future.wait([
|
||||
resultReceiveBch44,
|
||||
bch44ResultChange,
|
||||
]);
|
||||
|
||||
bch44P2pkhReceiveAddressArray =
|
||||
(await resultReceiveBch44)['addressArray']
|
||||
as List<isar_models.Address>;
|
||||
bch44P2pkhReceiveIndex = (await resultReceiveBch44)['index'] as int;
|
||||
bch44P2pkhReceiveDerivations = (await resultReceiveBch44)['derivations']
|
||||
as Map<String, Map<String, String>>;
|
||||
|
||||
bch44P2pkhChangeAddressArray = (await bch44ResultChange)['addressArray']
|
||||
as List<isar_models.Address>;
|
||||
bch44P2pkhChangeIndex = (await bch44ResultChange)['index'] as int;
|
||||
bch44P2pkhChangeDerivations = (await bch44ResultChange)['derivations']
|
||||
as Map<String, Map<String, String>>;
|
||||
|
||||
if (bch44P2pkhReceiveDerivations.isNotEmpty) {
|
||||
await addDerivations(
|
||||
chain: 0,
|
||||
derivePathType: DerivePathType.bch44,
|
||||
derivationsToAdd: bch44P2pkhReceiveDerivations);
|
||||
}
|
||||
if (bch44P2pkhChangeDerivations.isNotEmpty) {
|
||||
await addDerivations(
|
||||
chain: 1,
|
||||
derivePathType: DerivePathType.bch44,
|
||||
derivationsToAdd: bch44P2pkhChangeDerivations);
|
||||
}
|
||||
|
||||
if (bch44P2pkhReceiveIndex == -1) {
|
||||
final address =
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bch44);
|
||||
bch44P2pkhReceiveAddressArray.add(address);
|
||||
}
|
||||
|
||||
if (bch44P2pkhChangeIndex == -1) {
|
||||
final address =
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bch44);
|
||||
bch44P2pkhChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
if (isRescan) {
|
||||
await db.updateOrPutAddresses([
|
||||
...bip44P2pkhReceiveAddressArray,
|
||||
...bip44P2pkhChangeAddressArray,
|
||||
...bch44P2pkhReceiveAddressArray,
|
||||
...bch44P2pkhChangeAddressArray,
|
||||
...p2shReceiveAddressArray,
|
||||
...p2shChangeAddressArray,
|
||||
]);
|
||||
} else {
|
||||
await db.putAddresses([
|
||||
...bip44P2pkhReceiveAddressArray,
|
||||
...bip44P2pkhChangeAddressArray,
|
||||
...bch44P2pkhReceiveAddressArray,
|
||||
...bch44P2pkhChangeAddressArray,
|
||||
...p2shReceiveAddressArray,
|
||||
...p2shChangeAddressArray,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
await db.putAddresses([
|
||||
...p2pkhReceiveAddressArray,
|
||||
...p2pkhChangeAddressArray,
|
||||
...p2shReceiveAddressArray,
|
||||
...p2shChangeAddressArray,
|
||||
]);
|
||||
if (isRescan) {
|
||||
await db.updateOrPutAddresses([
|
||||
...bip44P2pkhReceiveAddressArray,
|
||||
...bip44P2pkhChangeAddressArray,
|
||||
...p2shReceiveAddressArray,
|
||||
...p2shChangeAddressArray,
|
||||
]);
|
||||
} else {
|
||||
await db.putAddresses([
|
||||
...bip44P2pkhReceiveAddressArray,
|
||||
...bip44P2pkhChangeAddressArray,
|
||||
...p2shReceiveAddressArray,
|
||||
...p2shChangeAddressArray,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
await _updateUTXOs();
|
||||
|
@ -1420,6 +1515,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
),
|
||||
);
|
||||
final data = PaymentData(pubkey: node.publicKey);
|
||||
|
||||
String address;
|
||||
isar_models.AddressType addrType;
|
||||
|
||||
|
@ -1429,6 +1525,11 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
addrType = isar_models.AddressType.p2pkh;
|
||||
address = bitbox.Address.toCashAddress(address);
|
||||
break;
|
||||
case DerivePathType.bch44:
|
||||
address = P2PKH(data: data, network: _network).data.address!;
|
||||
addrType = isar_models.AddressType.unknown;
|
||||
address = bitbox.Address.toCashAddress(address);
|
||||
break;
|
||||
case DerivePathType.bip49:
|
||||
address = P2SH(
|
||||
data: PaymentData(
|
||||
|
@ -1440,6 +1541,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
break;
|
||||
case DerivePathType.bip84:
|
||||
throw UnsupportedError("bip84 not supported by BCH");
|
||||
default:
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
|
||||
// add generated address & info to derivations
|
||||
|
@ -1479,11 +1582,16 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
case DerivePathType.bip44:
|
||||
type = isar_models.AddressType.p2pkh;
|
||||
break;
|
||||
case DerivePathType.bch44:
|
||||
type = isar_models.AddressType.unknown;
|
||||
break;
|
||||
case DerivePathType.bip49:
|
||||
type = isar_models.AddressType.p2sh;
|
||||
break;
|
||||
case DerivePathType.bip84:
|
||||
throw UnsupportedError("bip84 not supported by BCH");
|
||||
default:
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
|
||||
final address = await db
|
||||
|
@ -1506,6 +1614,9 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
case DerivePathType.bip44:
|
||||
key = "${walletId}_${chainId}DerivationsP2PKH";
|
||||
break;
|
||||
case DerivePathType.bch44:
|
||||
key = "${walletId}_${chainId}DerivationsBch44P2PKH";
|
||||
break;
|
||||
case DerivePathType.bip49:
|
||||
key = "${walletId}_${chainId}DerivationsP2SH";
|
||||
break;
|
||||
|
@ -1971,7 +2082,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
.where((e) => e.subType == isar_models.AddressSubType.receiving)
|
||||
.map((e) {
|
||||
if (bitbox.Address.detectFormat(e.value) == bitbox.Address.formatLegacy &&
|
||||
addressType(address: e.value) == DerivePathType.bip44) {
|
||||
(addressType(address: e.value) == DerivePathType.bip44 ||
|
||||
addressType(address: e.value) == DerivePathType.bch44)) {
|
||||
return bitbox.Address.toCashAddress(e.value);
|
||||
} else {
|
||||
return e.value;
|
||||
|
@ -1982,7 +2094,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
.where((e) => e.subType == isar_models.AddressSubType.change)
|
||||
.map((e) {
|
||||
if (bitbox.Address.detectFormat(e.value) == bitbox.Address.formatLegacy &&
|
||||
addressType(address: e.value) == DerivePathType.bip44) {
|
||||
(addressType(address: e.value) == DerivePathType.bip44 ||
|
||||
addressType(address: e.value) == DerivePathType.bch44)) {
|
||||
return bitbox.Address.toCashAddress(e.value);
|
||||
} else {
|
||||
return e.value;
|
||||
|
@ -2625,6 +2738,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
(addressTxid[address] as List).add(txid);
|
||||
switch (addressType(address: address)) {
|
||||
case DerivePathType.bip44:
|
||||
case DerivePathType.bch44:
|
||||
addressesP2PKH.add(address);
|
||||
break;
|
||||
case DerivePathType.bip49:
|
||||
|
|
|
@ -90,7 +90,8 @@ bip32.BIP32 getBip32NodeFromRoot(
|
|||
case DerivePathType.bip44:
|
||||
return root.derivePath("m/44'/$coinType'/0'/$chain/$index");
|
||||
default:
|
||||
throw Exception("Unsupported DerivePathType");
|
||||
throw Exception(
|
||||
"DerivePathType null or unsupported (${DerivePathType.bip44})");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,7 +389,7 @@ class DogecoinWallet extends CoinServiceAPI
|
|||
);
|
||||
break;
|
||||
default:
|
||||
throw Exception("No Path type $type exists");
|
||||
throw Exception("DerivePathType $type not supported");
|
||||
}
|
||||
receivingNodes.addAll({
|
||||
"${_id}_$j": {
|
||||
|
|
|
@ -102,7 +102,7 @@ bip32.BIP32 getBip32NodeFromRoot(
|
|||
case DerivePathType.bip84:
|
||||
return root.derivePath("m/84'/$coinType'/0'/$chain/$index");
|
||||
default:
|
||||
throw Exception("DerivePathType must not be null.");
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,7 +429,7 @@ class LitecoinWallet extends CoinServiceAPI
|
|||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("No Path type $type exists");
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
|
||||
final address = isar_models.Address(
|
||||
|
@ -1552,6 +1552,8 @@ class LitecoinWallet extends CoinServiceAPI
|
|||
.address!;
|
||||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
|
||||
// add generated address & info to derivations
|
||||
|
@ -1598,6 +1600,8 @@ class LitecoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
type = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
address = await db
|
||||
.getAddresses(walletId)
|
||||
|
@ -1625,6 +1629,8 @@ class LitecoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
key = "${walletId}_${chainId}DerivationsP2WPKH";
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
@ -2615,6 +2621,8 @@ class LitecoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
addressesP2WPKH.add(address);
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType unsupported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -419,7 +419,7 @@ class NamecoinWallet extends CoinServiceAPI
|
|||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("No Path type $type exists");
|
||||
throw Exception("DerivePathType $type not supported");
|
||||
}
|
||||
|
||||
final address = isar_models.Address(
|
||||
|
@ -1529,6 +1529,8 @@ class NamecoinWallet extends CoinServiceAPI
|
|||
.address!;
|
||||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType must not be null.");
|
||||
}
|
||||
|
||||
// add generated address & info to derivations
|
||||
|
@ -1575,6 +1577,9 @@ class NamecoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
type = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception(
|
||||
"DerivePathType null or unsupported (${DerivePathType.bip44})");
|
||||
}
|
||||
address = await db
|
||||
.getAddresses(walletId)
|
||||
|
@ -1602,6 +1607,8 @@ class NamecoinWallet extends CoinServiceAPI
|
|||
case DerivePathType.bip84:
|
||||
key = "${walletId}_${chainId}DerivationsP2WPKH";
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ bip32.BIP32 getBip32NodeFromRoot(
|
|||
case DerivePathType.bip84:
|
||||
return root.derivePath("m/84'/$coinType'/0'/$chain/$index");
|
||||
default:
|
||||
throw Exception("DerivePathType must not be null.");
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("No Path type $type exists");
|
||||
throw Exception("DerivePathType $type not supported");
|
||||
}
|
||||
|
||||
final address = isar_models.Address(
|
||||
|
@ -1425,7 +1425,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
addrType = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("Unsupported DerivePathType");
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
|
||||
// add generated address & info to derivations
|
||||
|
@ -1470,7 +1470,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
type = isar_models.AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("Unsupported DerivePathType");
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
address = await db
|
||||
.getAddresses(walletId)
|
||||
|
@ -1497,7 +1497,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
key = "${walletId}_${chainId}DerivationsP2WPKH";
|
||||
break;
|
||||
default:
|
||||
throw Exception("Unsupported DerivePathType");
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
@ -2212,7 +2212,6 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Logging.instance.log(s.toString(), level: LogLevel.Warning);
|
||||
}
|
||||
// Logging.instance.log("output is transparent", level: LogLevel.Info);
|
||||
|
||||
} else if (output.containsKey('ct_fee') as bool) {
|
||||
// or type: data
|
||||
// TODO handle CT tx
|
||||
|
@ -2767,7 +2766,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
addressesP2WPKH.add(address);
|
||||
break;
|
||||
default:
|
||||
throw Exception("Unsupported DerivePathType");
|
||||
throw Exception(
|
||||
"DerivePathType ${addressType(address: address)} not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1122,6 +1122,8 @@ mixin PaynymWalletInterface {
|
|||
case DerivePathType.bip84:
|
||||
type = AddressType.p2wpkh;
|
||||
break;
|
||||
default:
|
||||
throw Exception("DerivePathType $derivePathType not supported");
|
||||
}
|
||||
|
||||
final storedAddress = await _db
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|||
|
||||
enum DerivePathType {
|
||||
bip44,
|
||||
bch44,
|
||||
bip49,
|
||||
bip84,
|
||||
}
|
||||
|
|
|
@ -41,18 +41,18 @@ void main() async {
|
|||
});
|
||||
});
|
||||
|
||||
group("bip32 node/root", () {
|
||||
test("getBip32Root", () {
|
||||
final root = getBip32Root(TEST_MNEMONIC, bitcoincash);
|
||||
expect(root.toWIF(), ROOT_WIF);
|
||||
});
|
||||
|
||||
test("basic getBip32Node", () {
|
||||
final node =
|
||||
getBip32Node(0, 0, TEST_MNEMONIC, bitcoincash, DerivePathType.bip44);
|
||||
expect(node.toWIF(), NODE_WIF_44);
|
||||
});
|
||||
});
|
||||
// group("bip32 node/root", () {
|
||||
// test("getBip32Root", () {
|
||||
// final root = getBip32Root(TEST_MNEMONIC, bitcoincash);
|
||||
// expect(root.toWIF(), ROOT_WIF);
|
||||
// });
|
||||
//
|
||||
// test("basic getBip32Node", () {
|
||||
// final node =
|
||||
// getBip32Node(0, 0, TEST_MNEMONIC, bitcoincash, DerivePathType.bip44);
|
||||
// expect(node.toWIF(), NODE_WIF_44);
|
||||
// });
|
||||
// });
|
||||
|
||||
group("mainnet bitcoincash addressType", () {
|
||||
MockElectrumX? client;
|
||||
|
|
Loading…
Reference in a new issue