Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
feat(SPV-938): upgrade to go-sdk (#102)
Browse files Browse the repository at this point in the history
Co-authored-by: Damian Orzepowski <damian.orzepowski@4chain.studio>
Co-authored-by: wregulski <wojciechregulski@outlook.com>
Co-authored-by: Wojciech Regulski <48433067+wregulski@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 5, 2024
1 parent 0bdc7d2 commit e82b83f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
27 changes: 15 additions & 12 deletions broadcast/internal/arc/arc_submit_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package arc

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand All @@ -13,7 +12,8 @@ import (
arc_utils "github.com/bitcoin-sv/go-broadcast-client/broadcast/internal/arc/utils"
"github.com/bitcoin-sv/go-broadcast-client/broadcast/internal/utils"
"github.com/bitcoin-sv/go-broadcast-client/httpclient"
"github.com/libsv/go-bt/v2"

trx "github.com/bitcoin-sv/go-sdk/transaction"
)

type SubmitTxRequest struct {
Expand Down Expand Up @@ -261,9 +261,9 @@ func beefTxRequest(rawTx string) (*SubmitTxRequest, error) {
}

func rawTxRequest(arc *ArcClient, rawTx string) (*SubmitTxRequest, error) {
transaction, err := bt.NewTxFromString(rawTx)
transaction, err := trx.NewTransactionFromHex(rawTx)
if err != nil {
return nil, utils.WithCause(errors.New("rawTxRequest: bt.NewTxFromString failed"), err)
return nil, utils.WithCause(errors.New("rawTxRequest: trx.NewTransactionFromHex() failed"), err)
}

for _, input := range transaction.Inputs {
Expand All @@ -272,14 +272,19 @@ func rawTxRequest(arc *ArcClient, rawTx string) (*SubmitTxRequest, error) {
}
}

hex, err := transaction.EFHex()
if err != nil {
return nil, utils.WithCause(errors.New("rawTxRequest: transaction.EFHex() failed"), err)
}

request := &SubmitTxRequest{
RawTx: hex.EncodeToString(transaction.ExtendedBytes()),
RawTx: hex,
}
return request, nil
}

func updateUtxoWithMissingData(arc *ArcClient, input *bt.Input) error {
txid := input.PreviousTxIDStr()
func updateUtxoWithMissingData(arc *ArcClient, input *trx.TransactionInput) error {
txid := input.SourceTXID
pld := httpclient.NewPayload(
httpclient.GET,
fmt.Sprintf("https://junglebus.gorillapool.io/v1/transaction/get/%s", txid),
Expand All @@ -303,14 +308,12 @@ func updateUtxoWithMissingData(arc *ArcClient, input *bt.Input) error {
return errors.New("junglebus responded with empty tx.Transaction[]")
}

actualTx, err := bt.NewTxFromBytes(tx.Transaction)
actualTx, err := trx.NewTransactionFromBytes(tx.Transaction)
if err != nil {
return utils.WithCause(errors.New("converting junglebusTransaction.Transaction to bt.Tx failed"), err)
return utils.WithCause(errors.New("converting junglebusTransaction.Transaction to trx.Transaction failed"), err)
}

o := actualTx.Outputs[input.PreviousTxOutIndex]
input.PreviousTxScript = o.LockingScript
input.PreviousTxSatoshis = o.Satoshis
input.SourceTransaction = actualTx
return nil
}

Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
module github.com/bitcoin-sv/go-broadcast-client

go 1.21.5
go 1.22

toolchain go1.22.5

require (
github.com/libsv/go-bt/v2 v2.2.5
github.com/bitcoin-sv/go-sdk v1.1.2
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
)

require (
github.com/kr/text v0.2.0 // indirect
github.com/libsv/go-bk v0.1.6 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/crypto v0.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

require (
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
github.com/bitcoin-sv/go-sdk v0.0.0-20240723152403-6fa5c8714bb9 h1:0FzZum72lt0J+u936VdT+pUVZQ4kLdnnVFEhOMO1+Rk=
github.com/bitcoin-sv/go-sdk v0.0.0-20240723152403-6fa5c8714bb9/go.mod h1:NOAkJLbjqKOLuxJmb9ABG86ExTZp4HS8+iygiDIUps4=
github.com/bitcoin-sv/go-sdk v1.1.2 h1:LBnvqQ1NZUrzaU2l7sMW7FMWii9yqmebairfA99ZAE8=
github.com/bitcoin-sv/go-sdk v1.1.2/go.mod h1:NOAkJLbjqKOLuxJmb9ABG86ExTZp4HS8+iygiDIUps4=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/libsv/go-bk v0.1.6 h1:c9CiT5+64HRDbzxPl1v/oiFmbvWZTuUYqywCf+MBs/c=
github.com/libsv/go-bk v0.1.6/go.mod h1:khJboDoH18FPUaZlzRFKzlVN84d4YfdmlDtdX4LAjQA=
github.com/libsv/go-bt/v2 v2.2.5 h1:VoggBLMRW9NYoFujqe5bSYKqnw5y+fYfufgERSoubog=
github.com/libsv/go-bt/v2 v2.2.5/go.mod h1:cV45+jDlPOLfhJLfpLmpQoWzrIvVth9Ao2ZO1f6CcqU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand All @@ -21,10 +24,12 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g=
github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand Down

0 comments on commit e82b83f

Please sign in to comment.