various tweaks to get a btc testnet tx to send

This commit is contained in:
julian 2023-11-09 15:31:23 -06:00
parent 255d9a7813
commit baaf375942
2 changed files with 63 additions and 53 deletions

View file

@ -120,7 +120,7 @@ class _ConfirmTransactionViewState
); );
late String txid; late String txid;
Future<TxData> txidFuture; Future<TxData> txDataFuture;
final note = noteController.text; final note = noteController.text;
@ -137,7 +137,7 @@ class _ConfirmTransactionViewState
// txidFuture = (wallet as PaynymWalletInterface) // txidFuture = (wallet as PaynymWalletInterface)
// .broadcastNotificationTx(preparedTx: transactionInfo); // .broadcastNotificationTx(preparedTx: transactionInfo);
} else if (widget.isPaynymTransaction) { } else if (widget.isPaynymTransaction) {
txidFuture = wallet.confirmSend(txData: widget.txData); txDataFuture = wallet.confirmSend(txData: widget.txData);
} else { } else {
if ((coin == Coin.firo || coin == Coin.firoTestNet) && if ((coin == Coin.firo || coin == Coin.firoTestNet) &&
ref.read(publicPrivateBalanceStateProvider.state).state != ref.read(publicPrivateBalanceStateProvider.state).state !=
@ -148,26 +148,26 @@ class _ConfirmTransactionViewState
// .confirmSendPublic(txData: transactionInfo); // .confirmSendPublic(txData: transactionInfo);
} else { } else {
if (coin == Coin.epicCash) { if (coin == Coin.epicCash) {
txidFuture = wallet.confirmSend( txDataFuture = wallet.confirmSend(
txData: widget.txData.copyWith( txData: widget.txData.copyWith(
noteOnChain: onChainNoteController.text, noteOnChain: onChainNoteController.text,
), ),
); );
} else { } else {
txidFuture = wallet.confirmSend(txData: widget.txData); txDataFuture = wallet.confirmSend(txData: widget.txData);
} }
} }
} }
final results = await Future.wait([ final results = await Future.wait([
txidFuture, txDataFuture,
time, time,
]); ]);
sendProgressController.triggerSuccess?.call(); sendProgressController.triggerSuccess?.call();
await Future<void>.delayed(const Duration(seconds: 5)); await Future<void>.delayed(const Duration(seconds: 5));
txid = results.first as String; txid = (results.first as TxData).txid!;
ref.refresh(desktopUseUTXOs); ref.refresh(desktopUseUTXOs);
// save note // save note

View file

@ -159,6 +159,11 @@ mixin ElectrumXMixin on Bip39HDWallet {
if (isSendAll) { if (isSendAll) {
Logging.instance Logging.instance
.log("Attempting to send all $cryptoCurrency", level: LogLevel.Info); .log("Attempting to send all $cryptoCurrency", level: LogLevel.Info);
if (txData.recipients!.length != 1) {
throw Exception(
"Send all to more than one recipient not yet supported",
);
}
final int vSizeForOneOutput = buildTransaction( final int vSizeForOneOutput = buildTransaction(
utxoSigningData: utxoSigningData, utxoSigningData: utxoSigningData,
@ -188,8 +193,13 @@ mixin ElectrumXMixin on Bip39HDWallet {
} }
final int amount = satoshiAmountToSend - feeForOneOutput; final int amount = satoshiAmountToSend - feeForOneOutput;
final data = await buildTransaction( final data = buildTransaction(
txData: txData, txData: txData.copyWith(
recipients: _helperRecipientsConvert(
[recipientAddress],
[amount],
),
),
utxoSigningData: utxoSigningData, utxoSigningData: utxoSigningData,
); );
@ -479,6 +489,18 @@ mixin ElectrumXMixin on Bip39HDWallet {
); );
} }
final convertedNetwork = bitcoindart.NetworkType(
messagePrefix: cryptoCurrency.networkParams.messagePrefix,
bech32: cryptoCurrency.networkParams.bech32Hrp,
bip32: bitcoindart.Bip32Type(
public: cryptoCurrency.networkParams.pubHDPrefix,
private: cryptoCurrency.networkParams.privHDPrefix,
),
pubKeyHash: cryptoCurrency.networkParams.p2pkhPrefix,
scriptHash: cryptoCurrency.networkParams.p2shPrefix,
wif: cryptoCurrency.networkParams.wifPrefix,
);
final root = await getRootHDNode(); final root = await getRootHDNode();
for (final sd in signingData) { for (final sd in signingData) {
@ -510,21 +532,26 @@ mixin ElectrumXMixin on Bip39HDWallet {
"Failed to fetch signing data. Local db corrupt. Rescan wallet."); "Failed to fetch signing data. Local db corrupt. Rescan wallet.");
} }
final coinlib.Input input; // final coinlib.Input input;
final pubKey = keys.publicKey.data;
final bitcoindart.PaymentData data;
switch (sd.derivePathType) { switch (sd.derivePathType) {
case DerivePathType.bip44: case DerivePathType.bip44:
input = coinlib.P2PKHInput( // input = coinlib.P2PKHInput(
prevOut: coinlib.OutPoint.fromHex(sd.utxo.txid, sd.utxo.vout), // prevOut: coinlib.OutPoint.fromHex(sd.utxo.txid, sd.utxo.vout),
publicKey: keys.publicKey, // publicKey: keys.publicKey,
); // );
// data = P2PKH( data = bitcoindart
// data: PaymentData( .P2PKH(
// pubkey: Format.stringToUint8List(pubKey), data: bitcoindart.PaymentData(
// ), pubkey: pubKey,
// network: _network, ),
// ).data; network: convertedNetwork,
)
.data;
break; break;
// //
// case DerivePathType.bip49: // case DerivePathType.bip49:
@ -545,37 +572,30 @@ mixin ElectrumXMixin on Bip39HDWallet {
// break; // break;
case DerivePathType.bip84: case DerivePathType.bip84:
input = coinlib.P2WPKHInput( // input = coinlib.P2WPKHInput(
prevOut: coinlib.OutPoint.fromHex(sd.utxo.txid, sd.utxo.vout), // prevOut: coinlib.OutPoint.fromHex(sd.utxo.txid, sd.utxo.vout),
publicKey: keys.publicKey, // publicKey: keys.publicKey,
); // );
// data = P2WPKH( data = bitcoindart
// data: PaymentData( .P2WPKH(
// pubkey: Format.stringToUint8List(pubKey), data: bitcoindart.PaymentData(
// ), pubkey: pubKey,
// network: _network, ),
// ).data; network: convertedNetwork,
)
.data;
break; break;
default: default:
throw Exception("DerivePathType unsupported"); throw Exception("DerivePathType unsupported");
} }
sd.output = input.toBytes(); // sd.output = input.script!.compiled;
sd.output = data.output!;
sd.keyPair = bitcoindart.ECPair.fromPrivateKey( sd.keyPair = bitcoindart.ECPair.fromPrivateKey(
keys.privateKey.data, keys.privateKey.data,
compressed: keys.privateKey.compressed, compressed: keys.privateKey.compressed,
network: bitcoindart.NetworkType( network: convertedNetwork,
messagePrefix: cryptoCurrency.networkParams.messagePrefix,
bech32: cryptoCurrency.networkParams.bech32Hrp,
bip32: bitcoindart.Bip32Type(
public: cryptoCurrency.networkParams.pubHDPrefix,
private: cryptoCurrency.networkParams.privHDPrefix,
),
pubKeyHash: cryptoCurrency.networkParams.p2pkhPrefix,
scriptHash: cryptoCurrency.networkParams.p2shPrefix,
wif: cryptoCurrency.networkParams.wifPrefix,
),
); );
} }
@ -598,17 +618,7 @@ mixin ElectrumXMixin on Bip39HDWallet {
// TODO: use coinlib // TODO: use coinlib
final txb = bitcoindart.TransactionBuilder( final txb = bitcoindart.TransactionBuilder(
network: bitcoindart.NetworkType( network: bitcoindart.testnet,
messagePrefix: cryptoCurrency.networkParams.messagePrefix,
bech32: cryptoCurrency.networkParams.bech32Hrp,
bip32: bitcoindart.Bip32Type(
public: cryptoCurrency.networkParams.pubHDPrefix,
private: cryptoCurrency.networkParams.privHDPrefix,
),
pubKeyHash: cryptoCurrency.networkParams.p2pkhPrefix,
scriptHash: cryptoCurrency.networkParams.p2shPrefix,
wif: cryptoCurrency.networkParams.wifPrefix,
),
); );
txb.setVersion(1); txb.setVersion(1);
@ -1681,7 +1691,7 @@ mixin ElectrumXMixin on Bip39HDWallet {
); );
Logging.instance.log("prepare send: $result", level: LogLevel.Info); Logging.instance.log("prepare send: $result", level: LogLevel.Info);
if (txData.fee!.raw.toInt() < txData.vSize!) { if (result.fee!.raw.toInt() < result.vSize!) {
throw Exception( throw Exception(
"Error in fee calculation: Transaction fee cannot be less than vSize"); "Error in fee calculation: Transaction fee cannot be less than vSize");
} }