detect p2tr outputs

This commit is contained in:
sneurlax 2024-03-26 16:05:16 -05:00 committed by julian
parent f630c3f567
commit b50985aec7
2 changed files with 29 additions and 5 deletions

View file

@ -80,12 +80,22 @@ abstract class Bip39HDCurrency extends Bip39Currency {
} catch (err) {
// Bech32 decode fail
}
if (decodeBech32?.hrp != null) {
// P2TR Bech32m addresses have null hrp.
if (networkParams.bech32Hrp != decodeBech32!.hrp) {
throw ArgumentError('Invalid prefix or Network mismatch');
}
if (decodeBech32.version != 0) {
throw ArgumentError('Invalid address version');
}
} else {
// P2TR.
if (address.startsWith('bc1p') || address.startsWith('tb1p')) {
// P2TR (Taproot).
return DerivePathType.bip86;
}
}
// P2WPKH
return DerivePathType.bip84;
}

View file

@ -682,6 +682,20 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
// TODO: use coinlib
// Check if any txData.recipients are taproot/P2TR outputs.
bool hasTaprootOutput = false;
for (final recipient in txData.recipients!) {
if (cryptoCurrency.addressType(address: recipient.address) ==
DerivePathType.bip86) {
hasTaprootOutput = true;
}
}
if (hasTaprootOutput) {
// Use Coinlib to construct taproot transaction.
// TODO [prio=high]: Implement taproot transaction construction.
}
final txb = bitcoindart.TransactionBuilder(
network: bitcoindart.NetworkType(
messagePrefix: cryptoCurrency.networkParams.messagePrefix,