mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 18:44:31 +00:00
fix: bch remove bad address type
This commit is contained in:
parent
3e51624631
commit
127564f2ac
3 changed files with 33 additions and 59 deletions
|
@ -71,7 +71,6 @@ String constructDerivePath({
|
||||||
case 0x80: // bch mainnet wif
|
case 0x80: // bch mainnet wif
|
||||||
switch (derivePathType) {
|
switch (derivePathType) {
|
||||||
case DerivePathType.bip44:
|
case DerivePathType.bip44:
|
||||||
case DerivePathType.bip49:
|
|
||||||
coinType = 145; // bch mainnet
|
coinType = 145; // bch mainnet
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bch44: // bitcoin.com wallet specific
|
case DerivePathType.bch44: // bitcoin.com wallet specific
|
||||||
|
@ -95,9 +94,6 @@ String constructDerivePath({
|
||||||
case DerivePathType.bch44:
|
case DerivePathType.bch44:
|
||||||
purpose = 44;
|
purpose = 44;
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
|
||||||
purpose = 49;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw Exception("DerivePathType $derivePathType not supported");
|
throw Exception("DerivePathType $derivePathType not supported");
|
||||||
}
|
}
|
||||||
|
@ -283,10 +279,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
return DerivePathType.bip44;
|
return DerivePathType.bip44;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decodeBase58[0] == _network.scriptHash) {
|
|
||||||
// P2SH
|
|
||||||
return DerivePathType.bip49;
|
|
||||||
}
|
|
||||||
throw ArgumentError('Invalid version or Network mismatch');
|
throw ArgumentError('Invalid version or Network mismatch');
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -419,15 +411,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
addrType = isar_models.AddressType.p2pkh;
|
addrType = isar_models.AddressType.p2pkh;
|
||||||
addressString = bitbox.Address.toCashAddress(addressString);
|
addressString = bitbox.Address.toCashAddress(addressString);
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
|
||||||
addressString = P2SH(
|
|
||||||
data: PaymentData(
|
|
||||||
redeem: P2WPKH(data: data, network: _network).data),
|
|
||||||
network: _network)
|
|
||||||
.data
|
|
||||||
.address!;
|
|
||||||
addrType = isar_models.AddressType.p2sh;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw Exception("DerivePathType $type not supported");
|
throw Exception("DerivePathType $type not supported");
|
||||||
}
|
}
|
||||||
|
@ -518,7 +501,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
|
|
||||||
final deriveTypes = [
|
final deriveTypes = [
|
||||||
DerivePathType.bip44,
|
DerivePathType.bip44,
|
||||||
DerivePathType.bip49,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (coin != Coin.bitcoincashTestnet) {
|
if (coin != Coin.bitcoincashTestnet) {
|
||||||
|
@ -1397,10 +1379,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
// P2PKH
|
// P2PKH
|
||||||
_generateAddressForChain(0, 0, DerivePathType.bip44),
|
_generateAddressForChain(0, 0, DerivePathType.bip44),
|
||||||
_generateAddressForChain(1, 0, DerivePathType.bip44),
|
_generateAddressForChain(1, 0, DerivePathType.bip44),
|
||||||
|
|
||||||
// P2SH
|
|
||||||
_generateAddressForChain(0, 0, DerivePathType.bip49),
|
|
||||||
_generateAddressForChain(1, 0, DerivePathType.bip49),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await db.putAddresses(initialAddresses);
|
await db.putAddresses(initialAddresses);
|
||||||
|
@ -1408,7 +1386,7 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info);
|
Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a new internal or external chain address for the wallet using a BIP44 or BIP49 derivation path.
|
/// Generates a new internal or external chain address for the wallet using a BIP44 derivation path.
|
||||||
/// [chain] - Use 0 for receiving (external), 1 for change (internal). Should not be any other value!
|
/// [chain] - Use 0 for receiving (external), 1 for change (internal). Should not be any other value!
|
||||||
/// [index] - This can be any integer >= 0
|
/// [index] - This can be any integer >= 0
|
||||||
Future<isar_models.Address> _generateAddressForChain(
|
Future<isar_models.Address> _generateAddressForChain(
|
||||||
|
@ -1449,17 +1427,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
addrType = isar_models.AddressType.p2pkh;
|
addrType = isar_models.AddressType.p2pkh;
|
||||||
address = bitbox.Address.toCashAddress(address);
|
address = bitbox.Address.toCashAddress(address);
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
|
||||||
address = P2SH(
|
|
||||||
data: PaymentData(
|
|
||||||
redeem: P2WPKH(data: data, network: _network).data),
|
|
||||||
network: _network)
|
|
||||||
.data
|
|
||||||
.address!;
|
|
||||||
addrType = isar_models.AddressType.p2sh;
|
|
||||||
break;
|
|
||||||
case DerivePathType.bip84:
|
|
||||||
throw UnsupportedError("bip84 not supported by BCH");
|
|
||||||
default:
|
default:
|
||||||
throw Exception("DerivePathType $derivePathType not supported");
|
throw Exception("DerivePathType $derivePathType not supported");
|
||||||
}
|
}
|
||||||
|
@ -1502,13 +1469,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
coinType = coin == Coin.bitcoincash ? "0" : "1";
|
coinType = coin == Coin.bitcoincash ? "0" : "1";
|
||||||
purpose = "44";
|
purpose = "44";
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
|
||||||
type = isar_models.AddressType.p2sh;
|
|
||||||
coinType = coin == Coin.bitcoincash ? "145" : "1";
|
|
||||||
purpose = "49";
|
|
||||||
break;
|
|
||||||
case DerivePathType.bip84:
|
|
||||||
throw UnsupportedError("bip84 not supported by BCH");
|
|
||||||
default:
|
default:
|
||||||
throw Exception("DerivePathType $derivePathType not supported");
|
throw Exception("DerivePathType $derivePathType not supported");
|
||||||
}
|
}
|
||||||
|
@ -1537,9 +1497,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
case DerivePathType.bch44:
|
case DerivePathType.bch44:
|
||||||
key = "${walletId}_${chainId}DerivationsBch44P2PKH";
|
key = "${walletId}_${chainId}DerivationsBch44P2PKH";
|
||||||
break;
|
break;
|
||||||
case DerivePathType.bip49:
|
|
||||||
key = "${walletId}_${chainId}DerivationsP2SH";
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw UnsupportedError(
|
throw UnsupportedError(
|
||||||
"${derivePathType.name} not supported by ${coin.prettyName}");
|
"${derivePathType.name} not supported by ${coin.prettyName}");
|
||||||
|
@ -2721,20 +2678,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
||||||
redeemScript = null;
|
redeemScript = null;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DerivePathType.bip49:
|
|
||||||
final p2wpkh = P2WPKH(
|
|
||||||
data: PaymentData(
|
|
||||||
pubkey: Format.stringToUint8List(pubKey),
|
|
||||||
),
|
|
||||||
network: _network,
|
|
||||||
).data;
|
|
||||||
redeemScript = p2wpkh.output;
|
|
||||||
data = P2SH(
|
|
||||||
data: PaymentData(redeem: p2wpkh),
|
|
||||||
network: _network,
|
|
||||||
).data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Exception("DerivePathType unsupported");
|
throw Exception("DerivePathType unsupported");
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ abstract class Constants {
|
||||||
// Enable Logger.print statements
|
// Enable Logger.print statements
|
||||||
static const bool disableLogger = false;
|
static const bool disableLogger = false;
|
||||||
|
|
||||||
static const int currentHiveDbVersion = 8;
|
static const int currentHiveDbVersion = 9;
|
||||||
|
|
||||||
static const int rescanV1 = 1;
|
static const int rescanV1 = 1;
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,37 @@ class DbVersionMigrator with WalletDB {
|
||||||
// try to continue migrating
|
// try to continue migrating
|
||||||
return await migrate(8, secureStore: secureStore);
|
return await migrate(8, secureStore: secureStore);
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
// migrate
|
||||||
|
await Hive.openBox<dynamic>(DB.boxNameAllWalletsData);
|
||||||
|
final walletsService =
|
||||||
|
WalletsService(secureStorageInterface: secureStore);
|
||||||
|
final walletInfoList = await walletsService.walletNames;
|
||||||
|
await MainDB.instance.initMainDB();
|
||||||
|
for (final walletId in walletInfoList.keys) {
|
||||||
|
final info = walletInfoList[walletId]!;
|
||||||
|
if (info.coin == Coin.bitcoincash ||
|
||||||
|
info.coin == Coin.bitcoincashTestnet) {
|
||||||
|
final ids = await MainDB.instance
|
||||||
|
.getAddresses(walletId)
|
||||||
|
.filter()
|
||||||
|
.typeEqualTo(isar_models.AddressType.p2sh)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
|
|
||||||
|
await MainDB.instance.isar.writeTxn(() async {
|
||||||
|
await MainDB.instance.isar.addresses.deleteAll(ids);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update version
|
||||||
|
await DB.instance.put<dynamic>(
|
||||||
|
boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 9);
|
||||||
|
|
||||||
|
// try to continue migrating
|
||||||
|
return await migrate(9, secureStore: secureStore);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// finally return
|
// finally return
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue