66 "strings"
77
88 "github.com/bitcoinsv/bsvd/bsvec"
9- "github.com/libsv/libsv/transaction"
10- "github.com/libsv/libsv/transaction/output"
11- "github.com/libsv/libsv/transaction/signature"
9+ "github.com/libsv/go-bt"
1210)
1311
1412const (
@@ -56,16 +54,16 @@ type PayToAddress struct {
5654type OpReturnData [][]byte
5755
5856// TxFromHex will return a libsv.tx from a raw hex string
59- func TxFromHex (rawHex string ) (* transaction. Transaction , error ) {
60- return transaction . NewFromString (rawHex )
57+ func TxFromHex (rawHex string ) (* bt. Tx , error ) {
58+ return bt . NewTxFromString (rawHex )
6159}
6260
6361// CreateTxWithChange will automatically create the change output and calculate fees
6462//
6563// Use this if you don't want to figure out fees/change for a tx
6664func CreateTxWithChange (utxos []* Utxo , payToAddresses []* PayToAddress , opReturns []OpReturnData ,
6765 changeAddress string , standardRate , dataRate * FeeAmount ,
68- privateKey * bsvec.PrivateKey ) (* transaction. Transaction , error ) {
66+ privateKey * bsvec.PrivateKey ) (* bt. Tx , error ) {
6967
7068 // Missing utxo(s) or change address
7169 if len (utxos ) == 0 {
@@ -139,7 +137,7 @@ func CreateTxWithChange(utxos []*Utxo, payToAddresses []*PayToAddress, opReturns
139137//
140138// Use this if you don't want to figure out fees/change for a tx
141139func CreateTxWithChangeUsingWif (utxos []* Utxo , payToAddresses []* PayToAddress , opReturns []OpReturnData ,
142- changeAddress string , standardRate , dataRate * FeeAmount , wif string ) (* transaction. Transaction , error ) {
140+ changeAddress string , standardRate , dataRate * FeeAmount , wif string ) (* bt. Tx , error ) {
143141
144142 // Decode the WIF
145143 privateKey , err := WifToPrivateKey (wif )
@@ -159,10 +157,10 @@ func CreateTxWithChangeUsingWif(utxos []*Utxo, payToAddresses []*PayToAddress, o
159157// Get the raw hex version: tx.ToString()
160158// Get the tx id: tx.GetTxID()
161159func CreateTx (utxos []* Utxo , addresses []* PayToAddress ,
162- opReturns []OpReturnData , privateKey * bsvec.PrivateKey ) (* transaction. Transaction , error ) {
160+ opReturns []OpReturnData , privateKey * bsvec.PrivateKey ) (* bt. Tx , error ) {
163161
164162 // Start creating a new transaction
165- tx := transaction . New ()
163+ tx := bt . NewTx ()
166164
167165 // Accumulate the total satoshis from all utxo(s)
168166 var totalSatoshis uint64
@@ -184,9 +182,9 @@ func CreateTx(utxos []*Utxo, addresses []*PayToAddress,
184182 }
185183
186184 // Loop any op returns
187- var outPut * output .Output
185+ var outPut * bt .Output
188186 for _ , op := range opReturns {
189- if outPut , err = output . NewOpReturnParts (op ); err != nil {
187+ if outPut , err = bt . NewOpReturnPartsOutput (op ); err != nil {
190188 return nil , err
191189 }
192190 tx .AddOutput (outPut )
@@ -205,7 +203,7 @@ func CreateTx(utxos []*Utxo, addresses []*PayToAddress,
205203 // Sign the transaction
206204 if privateKey != nil {
207205
208- signer := signature .InternalSigner {PrivateKey : privateKey , SigHashFlag : 0 }
206+ signer := bt .InternalSigner {PrivateKey : privateKey , SigHashFlag : 0 }
209207 if err = tx .SignAuto (& signer ); err != nil {
210208 return nil , err
211209 }
@@ -223,7 +221,7 @@ func CreateTx(utxos []*Utxo, addresses []*PayToAddress,
223221// Get the raw hex version: tx.ToString()
224222// Get the tx id: tx.GetTxID()
225223func CreateTxUsingWif (utxos []* Utxo , addresses []* PayToAddress ,
226- opReturns []OpReturnData , wif string ) (* transaction. Transaction , error ) {
224+ opReturns []OpReturnData , wif string ) (* bt. Tx , error ) {
227225
228226 // Decode the WIF
229227 privateKey , err := WifToPrivateKey (wif )
@@ -241,7 +239,7 @@ func CreateTxUsingWif(utxos []*Utxo, addresses []*PayToAddress,
241239// Rate(s) can be derived from MinerAPI (default is DefaultDataRate and DefaultStandardRate)
242240// If rate is nil it will use default rates (0.5 sat per byte)
243241// Reference: https://tncpw.co/c215a75c
244- func CalculateFeeForTx (tx * transaction. Transaction , standardRate , dataRate * FeeAmount ) uint64 {
242+ func CalculateFeeForTx (tx * bt. Tx , standardRate , dataRate * FeeAmount ) uint64 {
245243
246244 // Set the totals
247245 var totalFee uint64
0 commit comments