@@ -19,7 +19,7 @@ import (
1919 "github.com/BoostyLabs/blockchain/bitcoin"
2020 "github.com/BoostyLabs/blockchain/bitcoin/ord/inscriptions"
2121 "github.com/BoostyLabs/blockchain/bitcoin/ord/runes"
22- "github.com/BoostyLabs/blockchain/internal /numbers"
22+ "github.com/BoostyLabs/blockchain/pkg /numbers"
2323)
2424
2525var (
4747 nonDustBitcoinAmount = big .NewInt (546 )
4848)
4949
50+ // NonDustBitcoinAmount provides public usage of variable nonDustBitcoinAmount
51+ func NonDustBitcoinAmount () * big.Int { return big .NewInt (546 ) }
52+
5053const (
5154 // recipientOutput defines runes output for recipient (transferring) by base rune tx.
5255 recipientOutput uint32 = 1
@@ -357,7 +360,7 @@ func (b *TxBuilder) buildBaseTransferRuneTx(params BaseRunesTransferParams) (res
357360 runeUTXOs , totalRuneAmount , err := PrepareRuneUTXOs (params .RunesSender .UTXOs , totalAllocatingRuneAmount , params .RuneID )
358361 if err != nil {
359362 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
360- return result , errIns .setCauser (CauserSender )
363+ return result , errIns .SetCauser (CauserSender )
361364 }
362365
363366 return result , err
@@ -440,7 +443,7 @@ func (b *TxBuilder) buildBaseTransferRuneTx(params BaseRunesTransferParams) (res
440443 }).Prepare ()
441444 if err != nil {
442445 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
443- return result , errIns .setCauser (CauserFeePayer )
446+ return result , errIns .SetCauser (CauserFeePayer )
444447 }
445448
446449 return result , err
@@ -473,31 +476,31 @@ func (b *TxBuilder) buildBaseTransferRuneTx(params BaseRunesTransferParams) (res
473476
474477 // recipient runes output (#1).
475478 if isRunesTransferred {
476- err = b .addOutput (tx , nonDustBitcoinAmount , prepareUTXOsResult .TotalAmount , params .RunesRecipientAddress )
479+ err = b .AddOutput (tx , nonDustBitcoinAmount , prepareUTXOsResult .TotalAmount , params .RunesRecipientAddress )
477480 if err != nil {
478481 return result , err
479482 }
480483 }
481484
482485 // change runes output (#2).
483486 if runestone .Pointer != nil {
484- err = b .addOutput (tx , nonDustBitcoinAmount , prepareUTXOsResult .TotalAmount , params .RunesSender .Address )
487+ err = b .AddOutput (tx , nonDustBitcoinAmount , prepareUTXOsResult .TotalAmount , params .RunesSender .Address )
485488 if err != nil {
486489 return result , err
487490 }
488491 }
489492
490493 // service commission output (#3).
491494 if params .SatoshiCommissionAmount != nil && numbers .IsPositive (params .SatoshiCommissionAmount ) {
492- err = b .addOutput (tx , params .SatoshiCommissionAmount , prepareUTXOsResult .TotalAmount , params .CommissionRecipientAddress )
495+ err = b .AddOutput (tx , params .SatoshiCommissionAmount , prepareUTXOsResult .TotalAmount , params .CommissionRecipientAddress )
493496 if err != nil {
494497 return result , err
495498 }
496499 }
497500
498501 // change btc output (#4).
499502 if numbers .IsPositive (prepareUTXOsResult .TotalAmount ) && numbers .IsGreater (prepareUTXOsResult .TotalAmount , nonDustBitcoinAmount ) {
500- err = b .addOutput (tx , prepareUTXOsResult .TotalAmount , prepareUTXOsResult .TotalAmount , params .FeePayer .Address )
503+ err = b .AddOutput (tx , prepareUTXOsResult .TotalAmount , prepareUTXOsResult .TotalAmount , params .FeePayer .Address )
501504 if err != nil {
502505 return result , err
503506 }
@@ -686,7 +689,7 @@ func (b *TxBuilder) buildBaseTransferBTCTx(params BaseBTCTransferParams) (result
686689 }).PrepareTransferOnly ()
687690 if err != nil {
688691 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
689- return result , errIns .setCauser (CauserSender )
692+ return result , errIns .SetCauser (CauserSender )
690693 }
691694
692695 return result , err
@@ -713,7 +716,7 @@ func (b *TxBuilder) buildBaseTransferBTCTx(params BaseBTCTransferParams) (result
713716 }).Prepare ()
714717 if err != nil {
715718 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
716- return result , errIns .setCauser (CauserFeePayer )
719+ return result , errIns .SetCauser (CauserFeePayer )
717720 }
718721
719722 return result , err
@@ -734,7 +737,7 @@ func (b *TxBuilder) buildBaseTransferBTCTx(params BaseBTCTransferParams) (result
734737 }).Prepare ()
735738 if err != nil {
736739 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
737- return result , errIns .setCauser (CauserSender )
740+ return result , errIns .SetCauser (CauserSender )
738741 }
739742
740743 return result , err
@@ -769,30 +772,30 @@ func (b *TxBuilder) buildBaseTransferBTCTx(params BaseBTCTransferParams) (result
769772 bitcoinAmount .Sub (bitcoinAmount , fee )
770773
771774 // recipient btc output (#0).
772- err = b .addOutput (tx , params .TransferSatoshiAmount , bitcoinAmount , params .RecipientAddress )
775+ err = b .AddOutput (tx , params .TransferSatoshiAmount , bitcoinAmount , params .RecipientAddress )
773776 if err != nil {
774777 return result , err
775778 }
776779
777780 // service commission output (#1).
778781 if params .SatoshiCommissionAmount != nil && numbers .IsPositive (params .SatoshiCommissionAmount ) {
779- err = b .addOutput (tx , params .SatoshiCommissionAmount , bitcoinAmount , params .CommissionReceiverAddress )
782+ err = b .AddOutput (tx , params .SatoshiCommissionAmount , bitcoinAmount , params .CommissionReceiverAddress )
780783 if err != nil {
781784 return result , err
782785 }
783786 }
784787
785788 // sender's change btc output (#2).
786789 if ! numbers .IsLess (senderChange , nonDustBitcoinAmount ) {
787- err = b .addOutput (tx , senderChange , bitcoinAmount , params .Sender .Address )
790+ err = b .AddOutput (tx , senderChange , bitcoinAmount , params .Sender .Address )
788791 if err != nil {
789792 return result , err
790793 }
791794 }
792795
793796 // fee payer's change btc output (#3).
794797 if differentFeePayer && ! numbers .IsLess (feePayerChange , nonDustBitcoinAmount ) {
795- err = b .addOutput (tx , feePayerChange , bitcoinAmount , params .FeePayer .Address )
798+ err = b .AddOutput (tx , feePayerChange , bitcoinAmount , params .FeePayer .Address )
796799 if err != nil {
797800 return result , err
798801 }
@@ -1012,7 +1015,7 @@ func (b *TxBuilder) buildBaseInscriptionTx(params BaseInscriptionTxParams) (resu
10121015 }).Prepare ()
10131016 if err != nil {
10141017 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
1015- return result , errIns .setCauser (CauserSender )
1018+ return result , errIns .SetCauser (CauserSender )
10161019 }
10171020
10181021 return result , err
@@ -1034,22 +1037,22 @@ func (b *TxBuilder) buildBaseInscriptionTx(params BaseInscriptionTxParams) (resu
10341037 bitcoinAmount .Sub (bitcoinAmount , senderUTXOsResult .RoughEstimate )
10351038
10361039 // inscription commitment output (#0).
1037- err = b .addOutput (tx , depositAmount , bitcoinAmount , inscriptionAddress )
1040+ err = b .AddOutput (tx , depositAmount , bitcoinAmount , inscriptionAddress )
10381041 if err != nil {
10391042 return result , err
10401043 }
10411044
10421045 // service commission output (#1).
10431046 if params .SatoshiCommissionAmount != nil && numbers .IsPositive (params .SatoshiCommissionAmount ) {
1044- err = b .addOutput (tx , params .SatoshiCommissionAmount , bitcoinAmount , params .CommissionReceiverAddress )
1047+ err = b .AddOutput (tx , params .SatoshiCommissionAmount , bitcoinAmount , params .CommissionReceiverAddress )
10451048 if err != nil {
10461049 return result , err
10471050 }
10481051 }
10491052
10501053 // sender's change btc output (#2).
10511054 if numbers .IsGreater (bitcoinAmount , nonDustBitcoinAmount ) {
1052- err = b .addOutput (tx , bitcoinAmount , bitcoinAmount , params .Sender .Address )
1055+ err = b .AddOutput (tx , bitcoinAmount , bitcoinAmount , params .Sender .Address )
10531056 if err != nil {
10541057 return result , err
10551058 }
@@ -1251,8 +1254,8 @@ func (b *TxBuilder) buildRuneEtchTx(params BaseRuneEtchTxParams) (result BaseRun
12511254 if numbers .IsGreater (transferAmount , params .InscriptionReveal .UTXOs [0 ].Amount ) {
12521255 if params .AdditionalPayments == nil {
12531256 return result , InsufficientNativeBalanceError .
1254- clarify (transferAmount , params .InscriptionReveal .UTXOs [0 ].Amount ).
1255- setCauser (CauserSender )
1257+ Clarify (transferAmount , params .InscriptionReveal .UTXOs [0 ].Amount ).
1258+ SetCauser (CauserSender )
12561259 }
12571260
12581261 prepareUTXOsResult , err = (& PrepareUTXOsParams {
@@ -1263,7 +1266,7 @@ func (b *TxBuilder) buildRuneEtchTx(params BaseRuneEtchTxParams) (result BaseRun
12631266 }).Prepare ()
12641267 if err != nil {
12651268 if errIns := new (InsufficientError ); errors .As (err , & errIns ) {
1266- return result , errIns .setCauser (CauserFeePayer )
1269+ return result , errIns .SetCauser (CauserFeePayer )
12671270 }
12681271
12691272 return result , err
@@ -1288,15 +1291,15 @@ func (b *TxBuilder) buildRuneEtchTx(params BaseRuneEtchTxParams) (result BaseRun
12881291
12891292 // recipient runes output (#1 - psf).
12901293 for i := 0 ; i < runeOutputs ; i ++ {
1291- err = b .addOutput (tx , nonDustBitcoinAmount , bitcoinAmount , params .RunesRecipientAddress )
1294+ err = b .AddOutput (tx , nonDustBitcoinAmount , bitcoinAmount , params .RunesRecipientAddress )
12921295 if err != nil {
12931296 return result , err
12941297 }
12951298 }
12961299
12971300 // change btc output (#psf+1).
12981301 if numbers .IsPositive (bitcoinAmount ) && numbers .IsGreater (bitcoinAmount , nonDustBitcoinAmount ) {
1299- err = b .addOutput (tx , bitcoinAmount , bitcoinAmount , params .SatoshiChangeAddress )
1302+ err = b .AddOutput (tx , bitcoinAmount , bitcoinAmount , params .SatoshiChangeAddress )
13001303 if err != nil {
13011304 return result , err
13021305 }
@@ -1437,7 +1440,7 @@ func (params *PrepareUTXOsParams) prepare(action func(utxoNum int, result *Prepa
14371440 result .RoughEstimate .Div (result .RoughEstimate , big .NewInt (1000 )) // sat.
14381441 need := new (big.Int ).Add (result .RoughEstimate , params .TransferAmount )
14391442
1440- return result , InsufficientNativeBalanceError .clarify (need , big .NewInt (0 ))
1443+ return result , InsufficientNativeBalanceError .Clarify (need , big .NewInt (0 ))
14411444}
14421445
14431446// Prepare selects utxos to cover transfer amount with rough estimated fee.
@@ -1524,7 +1527,7 @@ func PrepareRuneUTXOs(utxos []bitcoin.UTXO, transferAmount *big.Int, runeID rune
15241527 return usedUTXOs , totalAmount , nil
15251528 }
15261529
1527- return nil , nil , InsufficientRuneBalanceError .clarify (transferAmount , big .NewInt (0 ))
1530+ return nil , nil , InsufficientRuneBalanceError .Clarify (transferAmount , big .NewInt (0 ))
15281531}
15291532
15301533// SelectUTXO is a partly greedy selection algorithm for UTXOs with 'requiredUTXOs' parameter.
@@ -1567,14 +1570,14 @@ func SelectUTXO(utxos []bitcoin.UTXO, amountFn func(*bitcoin.UTXO) *big.Int, min
15671570 }
15681571
15691572 if numbers .IsGreater (minAmount , totalAmount ) {
1570- return nil , nil , insufficientBalanceError .clarify (minAmount , totalAmount )
1573+ return nil , nil , insufficientBalanceError .Clarify (minAmount , totalAmount )
15711574 }
15721575
15731576 return usedUTXOs , totalAmount , nil
15741577}
15751578
1576- // addOutput adds output to transaction, subtracts amount from unallocated amount.
1577- func (b * TxBuilder ) addOutput (tx * wire.MsgTx , amount , unallocatedAmount * big.Int , address string ) error {
1579+ // AddOutput adds output to transaction, subtracts amount from unallocated amount.
1580+ func (b * TxBuilder ) AddOutput (tx * wire.MsgTx , amount , unallocatedAmount * big.Int , address string ) error {
15781581 if numbers .IsLess (unallocatedAmount , amount ) {
15791582 return fmt .Errorf ("the rest of the unallocated btc amount (%s) is less than the output allocating amount (%s)" ,
15801583 unallocatedAmount .String (), amount .String ())
0 commit comments