ensure cashaddrs are converted to normal addresses for the tx builder to properly extract a script

This commit is contained in:
julian 2024-01-12 14:49:05 -06:00
parent 0c97fa6635
commit d5e8d3fe3e
3 changed files with 34 additions and 1 deletions

View file

@ -356,4 +356,18 @@ class BitcoincashWallet extends Bip39HDWallet
int estimateTxFee({required int vSize, required int feeRatePerKB}) {
return vSize * (feeRatePerKB / 1000).ceil();
}
@override
String normalizeAddress(String address) {
try {
if (bitbox.Address.detectFormat(address) ==
bitbox.Address.formatCashAddr) {
return bitbox.Address.toLegacyAddress(address);
} else {
return address;
}
} catch (_) {
return address;
}
}
}

View file

@ -351,4 +351,18 @@ class EcashWallet extends Bip39HDWallet
int estimateTxFee({required int vSize, required int feeRatePerKB}) {
return vSize * (feeRatePerKB / 1000).ceil();
}
@override
String normalizeAddress(String address) {
try {
if (bitbox.Address.detectFormat(address) ==
bitbox.Address.formatCashAddr) {
return bitbox.Address.toLegacyAddress(address);
} else {
return address;
}
} catch (_) {
return address;
}
}
}

View file

@ -697,7 +697,7 @@ mixin ElectrumXInterface on Bip39HDWallet {
// Add transaction output
for (var i = 0; i < txData.recipients!.length; i++) {
txb.addOutput(
txData.recipients![i].address,
normalizeAddress(txData.recipients![i].address),
txData.recipients![i].amount.raw.toInt(),
cryptoCurrency.networkParams.bech32Hrp,
);
@ -2021,5 +2021,10 @@ mixin ElectrumXInterface on Bip39HDWallet {
return result;
}
// lolcashaddrs
String normalizeAddress(String address) {
return address;
}
// ===========================================================================
}