@@ -17,35 +17,29 @@ import 'package:blockchain_utils/blockchain_utils.dart';
1717/// - [outPuts] : List of Bitcoin outputs to be included in the transaction.
1818/// - [fee] : Transaction fee (BigInt) for processing the transaction.
1919/// - [network] : The target Bitcoin network.
20- /// - [utxosInfo] : List of UtxoWithAddress objects providing information about Unspent Transaction Outputs (UTXOs).
2120/// - [memo] : Optional memo or additional information associated with the transaction.
2221/// - [enableRBF] : Flag indicating whether Replace-By-Fee (RBF) is enabled. Default is false.
2322/// - [isFakeTransaction] : Flag indicating whether the transaction is a fake/mock transaction. Default is false.
2423/// - [inputOrdering] : Ordering preference for transaction inputs. Default is BIP-69.
2524/// - [outputOrdering] : Ordering preference for transaction outputs. Default is BIP-69.
2625///
2726/// Note: The constructor automatically validates the builder by calling the [_validateBuilder] method.
28- class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
29- final List <BitcoinBaseOutput > outPuts;
30- final BigInt fee;
31- final BasedUtxoNetwork network;
32- final List <UtxoWithAddress > utxosInfo;
27+ class BitcoinTransactionBuilder extends BasedBitcoinTransacationBuilder {
3328 final String ? memo;
3429 final bool enableRBF;
3530 final bool isFakeTransaction;
36- final BitcoinOrdering inputOrdering;
37- final BitcoinOrdering outputOrdering;
31+
3832 BitcoinTransactionBuilder ({
39- required this .outPuts,
40- required this .fee,
41- required this .network,
42- required List < UtxoWithAddress > utxos,
43- this .inputOrdering = BitcoinOrdering .bip69,
44- this .outputOrdering = BitcoinOrdering .bip69,
33+ required super .outPuts,
34+ required super .fee,
35+ required super .network,
36+ required super . utxos,
37+ super .inputOrdering = BitcoinOrdering .bip69,
38+ super .outputOrdering = BitcoinOrdering .bip69,
4539 this .memo,
4640 this .enableRBF = false ,
4741 this .isFakeTransaction = false ,
48- }) : utxosInfo = utxos {
42+ }) {
4943 _validateBuilder ();
5044 }
5145
@@ -55,14 +49,14 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
5549 throw const DartBitcoinPluginException (
5650 'invalid network for BitcoinCashNetwork and BSVNetwork use ForkedTransactionBuilder' );
5751 }
58- final token = utxosInfo .any ((element) => element.utxo.token != null );
52+ final token = utxos .any ((element) => element.utxo.token != null );
5953 final tokenInput = outPuts.whereType <BitcoinTokenOutput >();
6054 final burn = outPuts.whereType <BitcoinBurnableOutput >();
6155 if (token || tokenInput.isNotEmpty || burn.isNotEmpty) {
6256 throw const DartBitcoinPluginException (
6357 'Cash Token only work on Bitcoin cash network' );
6458 }
65- for (final i in utxosInfo ) {
59+ for (final i in utxos ) {
6660 /// Verify each input for its association with this network's address. Raise an exception if the address is incorrect.
6761 i.ownerDetails.address.toAddress (network);
6862 }
@@ -151,7 +145,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
151145 /// Returns:
152146 /// - bool: True if at least one UTXO in the list is a SegWit UTXO, false otherwise.
153147 bool _hasSegwit () {
154- for (final element in utxosInfo ) {
148+ for (final element in utxos ) {
155149 if (element.utxo.isSegwit) {
156150 return true ;
157151 }
@@ -166,7 +160,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
166160 /// Returns:
167161 /// - bool: True if at least one UTXO in the list is a P2TR UTXO, false otherwise.
168162 bool _hasTaproot () {
169- for (final element in utxosInfo ) {
163+ for (final element in utxos ) {
170164 if (element.utxo.isP2tr) {
171165 return true ;
172166 }
@@ -383,21 +377,20 @@ that demonstrate the right to spend the bitcoins associated with the correspondi
383377 }
384378
385379 Tuple <List <TxInput >, List <UtxoWithAddress >> _buildInputs () {
386- var sortedUtxos = List <UtxoWithAddress >.from (utxosInfo );
380+ final sortedUtxos = List <UtxoWithAddress >.from (utxos );
387381
388382 if (inputOrdering == BitcoinOrdering .shuffle) {
389- sortedUtxos = sortedUtxos. .shuffle ();
383+ sortedUtxos.shuffle ();
390384 } else if (inputOrdering == BitcoinOrdering .bip69) {
391- sortedUtxos = sortedUtxos
392- ..sort (
393- (a, b) {
394- final txidComparison = a.utxo.txHash.compareTo (b.utxo.txHash);
395- if (txidComparison == 0 ) {
396- return a.utxo.vout - b.utxo.vout;
397- }
398- return txidComparison;
399- },
400- );
385+ sortedUtxos.sort (
386+ (a, b) {
387+ final txidComparison = a.utxo.txHash.compareTo (b.utxo.txHash);
388+ if (txidComparison == 0 ) {
389+ return a.utxo.vout - b.utxo.vout;
390+ }
391+ return txidComparison;
392+ },
393+ );
401394 }
402395 final inputs = sortedUtxos.map ((e) => e.utxo.toInput ()).toList ();
403396 if (enableRBF && inputs.isNotEmpty) {
0 commit comments