From c0db6dfa115957cfeb6989547bad3df1ee400560 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 19 Dec 2023 14:12:50 +0100 Subject: [PATCH] psbt: move to top-level module, use v2, remove btcutil dep --- btcutil/psbt/go.mod | 23 ------------ btcutil/psbt/go.sum | 30 ---------------- {btcutil/psbt => psbt}/bip32.go | 6 ++-- {btcutil/psbt => psbt}/bip32_test.go | 0 {btcutil/psbt => psbt}/creator.go | 0 {btcutil/psbt => psbt}/extractor.go | 0 {btcutil/psbt => psbt}/finalizer.go | 0 psbt/go.mod | 46 ++++++++++++++++++++++++ psbt/go.sum | 20 +++++++++++ {btcutil/psbt => psbt}/partial_input.go | 0 {btcutil/psbt => psbt}/partial_output.go | 0 {btcutil/psbt => psbt}/partialsig.go | 0 {btcutil/psbt => psbt}/psbt.go | 0 {btcutil/psbt => psbt}/psbt_test.go | 7 +++- {btcutil/psbt => psbt}/signer.go | 0 {btcutil/psbt => psbt}/sort.go | 0 {btcutil/psbt => psbt}/sort_test.go | 0 {btcutil/psbt => psbt}/taproot.go | 0 {btcutil/psbt => psbt}/types.go | 0 {btcutil/psbt => psbt}/updater.go | 9 ++--- {btcutil/psbt => psbt}/utils.go | 0 {btcutil/psbt => psbt}/utils_test.go | 0 22 files changed, 80 insertions(+), 61 deletions(-) delete mode 100644 btcutil/psbt/go.mod delete mode 100644 btcutil/psbt/go.sum rename {btcutil/psbt => psbt}/bip32.go (97%) rename {btcutil/psbt => psbt}/bip32_test.go (100%) rename {btcutil/psbt => psbt}/creator.go (100%) rename {btcutil/psbt => psbt}/extractor.go (100%) rename {btcutil/psbt => psbt}/finalizer.go (100%) create mode 100644 psbt/go.mod create mode 100644 psbt/go.sum rename {btcutil/psbt => psbt}/partial_input.go (100%) rename {btcutil/psbt => psbt}/partial_output.go (100%) rename {btcutil/psbt => psbt}/partialsig.go (100%) rename {btcutil/psbt => psbt}/psbt.go (100%) rename {btcutil/psbt => psbt}/psbt_test.go (99%) rename {btcutil/psbt => psbt}/signer.go (100%) rename {btcutil/psbt => psbt}/sort.go (100%) rename {btcutil/psbt => psbt}/sort_test.go (100%) rename {btcutil/psbt => psbt}/taproot.go (100%) rename {btcutil/psbt => psbt}/types.go (100%) rename {btcutil/psbt => psbt}/updater.go (98%) rename {btcutil/psbt => psbt}/utils.go (100%) rename {btcutil/psbt => psbt}/utils_test.go (100%) diff --git a/btcutil/psbt/go.mod b/btcutil/psbt/go.mod deleted file mode 100644 index 26a60576..00000000 --- a/btcutil/psbt/go.mod +++ /dev/null @@ -1,23 +0,0 @@ -module github.com/btcsuite/btcd/btcutil/psbt - -go 1.25 - -require ( - github.com/btcsuite/btcd v0.24.2 - github.com/btcsuite/btcd/btcec/v2 v2.4.0 - github.com/btcsuite/btcd/btcutil v1.2.0 - github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0 - github.com/davecgh/go-spew v1.1.1 - github.com/stretchr/testify v1.8.4 -) - -require ( - github.com/btcsuite/btclog v1.0.0 // indirect - github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect - github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.33.0 // indirect - golang.org/x/sys v0.30.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/btcutil/psbt/go.sum b/btcutil/psbt/go.sum deleted file mode 100644 index d344aae1..00000000 --- a/btcutil/psbt/go.sum +++ /dev/null @@ -1,30 +0,0 @@ -github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY= -github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg= -github.com/btcsuite/btcd/btcec/v2 v2.4.0 h1:9JgnRkOL8J1UKuGlpJs7oL5tFRgrBgyM/uhwfS+cUiI= -github.com/btcsuite/btcd/btcec/v2 v2.4.0/go.mod h1:64BXFSNzV1koQHPqljB4LaD6lZPQEQNZ38zMImajCRo= -github.com/btcsuite/btcd/btcutil v1.2.0 h1:p3+S2g3Q+7G5NOh4Ji+2UrBOrg5Z0Q4ykzShWG1Dhgs= -github.com/btcsuite/btcd/btcutil v1.2.0/go.mod h1:/Taflm113pYjUpbWKKQEfa6XOtI/+WS8awxeMZpY75k= -github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0 h1:yMIg99+4aBvqfl/HzJRKfxTX9rGfikoI9uvFzterhc8= -github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0/go.mod h1:Y72Ren9gfhlEvnwnT78BGcSNO2UMphTKLn9AorF+5rg= -github.com/btcsuite/btclog v1.0.0 h1:sEkpKJMmfGiyZjADwEIgB1NSwMyfdD1FB8v6+w1T0Ns= -github.com/btcsuite/btclog v1.0.0/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ= -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/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8= -github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= -github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee h1:FPP9HDkBbPyniu+u7FHZg+kKFX1WW0gxOGteJ0h3AJk= -github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee/go.mod h1:N6sz6HwJAenJ6d+/xmSl0ikfV05ZrVGmjt1ryy/WOtE= -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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= -golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/btcutil/psbt/bip32.go b/psbt/bip32.go similarity index 97% rename from btcutil/psbt/bip32.go rename to psbt/bip32.go index 4f9bb57d..f1727338 100644 --- a/btcutil/psbt/bip32.go +++ b/psbt/bip32.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/binary" - "github.com/btcsuite/btcd/btcutil/base58" - "github.com/btcsuite/btcd/btcutil/hdkeychain" - "github.com/btcsuite/btcd/chaincfg/chainhash" + "github.com/btcsuite/btcd/address/v2/base58" + "github.com/btcsuite/btcd/btcutil/v2/hdkeychain" + "github.com/btcsuite/btcd/chainhash/v2" ) const ( diff --git a/btcutil/psbt/bip32_test.go b/psbt/bip32_test.go similarity index 100% rename from btcutil/psbt/bip32_test.go rename to psbt/bip32_test.go diff --git a/btcutil/psbt/creator.go b/psbt/creator.go similarity index 100% rename from btcutil/psbt/creator.go rename to psbt/creator.go diff --git a/btcutil/psbt/extractor.go b/psbt/extractor.go similarity index 100% rename from btcutil/psbt/extractor.go rename to psbt/extractor.go diff --git a/btcutil/psbt/finalizer.go b/psbt/finalizer.go similarity index 100% rename from btcutil/psbt/finalizer.go rename to psbt/finalizer.go diff --git a/psbt/go.mod b/psbt/go.mod new file mode 100644 index 00000000..bf86db8b --- /dev/null +++ b/psbt/go.mod @@ -0,0 +1,46 @@ +module github.com/btcsuite/btcd/psbt/v2 + +go 1.23.2 + +require ( + github.com/btcsuite/btcd/address/v2 v2.0.0 + github.com/btcsuite/btcd/btcec/v2 v2.3.2 + github.com/btcsuite/btcd/btcutil/v2 v2.0.0 + github.com/btcsuite/btcd/chainhash/v2 v2.0.0 + github.com/btcsuite/btcd/txscript/v2 v2.0.0 + github.com/btcsuite/btcd/wire/v2 v2.0.0 + github.com/davecgh/go-spew v1.1.1 + github.com/stretchr/testify v1.10.0 +) + +require ( + github.com/btcsuite/btcd/chaincfg/v2 v2.0.0 // indirect + github.com/btcsuite/btclog v1.0.0 // indirect + github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/crypto v0.40.0 // indirect + golang.org/x/sys v0.35.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +// TODO(guggero): Remove this as soon as we have a tagged version of btcec. +replace github.com/btcsuite/btcd/btcec/v2 => ../btcec + +// TODO(guggero): Remove this as soon as we have a tagged version of btcutil. +replace github.com/btcsuite/btcd/btcutil/v2 => ../btcutil + +// TODO(guggero): Remove this as soon as we have a tagged version of chaincfg. +replace github.com/btcsuite/btcd/chaincfg/v2 => ../chaincfg + +// TODO(guggero): Remove this as soon as we have a tagged version of chainhash. +replace github.com/btcsuite/btcd/chainhash/v2 => ../chainhash + +// TODO(guggero): Remove this as soon as we have a tagged version of address. +replace github.com/btcsuite/btcd/address/v2 => ../address + +// TODO(guggero): Remove this as soon as we have a tagged version of txscript. +replace github.com/btcsuite/btcd/txscript/v2 => ../txscript + +// TODO(guggero): Remove this as soon as we have a tagged version of wire. +replace github.com/btcsuite/btcd/wire/v2 => ../wire diff --git a/psbt/go.sum b/psbt/go.sum new file mode 100644 index 00000000..f8b25f4c --- /dev/null +++ b/psbt/go.sum @@ -0,0 +1,20 @@ +github.com/btcsuite/btclog v1.0.0 h1:sEkpKJMmfGiyZjADwEIgB1NSwMyfdD1FB8v6+w1T0Ns= +github.com/btcsuite/btclog v1.0.0/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ= +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/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8= +github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= +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/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= +golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= +golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= +golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/btcutil/psbt/partial_input.go b/psbt/partial_input.go similarity index 100% rename from btcutil/psbt/partial_input.go rename to psbt/partial_input.go diff --git a/btcutil/psbt/partial_output.go b/psbt/partial_output.go similarity index 100% rename from btcutil/psbt/partial_output.go rename to psbt/partial_output.go diff --git a/btcutil/psbt/partialsig.go b/psbt/partialsig.go similarity index 100% rename from btcutil/psbt/partialsig.go rename to psbt/partialsig.go diff --git a/btcutil/psbt/psbt.go b/psbt/psbt.go similarity index 100% rename from btcutil/psbt/psbt.go rename to psbt/psbt.go diff --git a/btcutil/psbt/psbt_test.go b/psbt/psbt_test.go similarity index 99% rename from btcutil/psbt/psbt_test.go rename to psbt/psbt_test.go index 1e0f4fe3..1583b626 100644 --- a/btcutil/psbt/psbt_test.go +++ b/psbt/psbt_test.go @@ -21,6 +21,11 @@ import ( "github.com/stretchr/testify/require" ) +const ( + // satoshiPerBitcoin is the number of satoshi in one bitcoin (1 BTC). + satoshiPerBitcoin = 1e8 +) + // Test vectors from: // // https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#test-vectors @@ -1588,7 +1593,7 @@ func TestWitnessForNonWitnessUtxo(t *testing.T) { }}, TxOut: []*wire.TxOut{{ PkScript: outPkScript, - Value: 1.9 * btcutil.SatoshiPerBitcoin, + Value: 1.9 * satoshiPerBitcoin, }}, }, Inputs: []PInput{{}}, diff --git a/btcutil/psbt/signer.go b/psbt/signer.go similarity index 100% rename from btcutil/psbt/signer.go rename to psbt/signer.go diff --git a/btcutil/psbt/sort.go b/psbt/sort.go similarity index 100% rename from btcutil/psbt/sort.go rename to psbt/sort.go diff --git a/btcutil/psbt/sort_test.go b/psbt/sort_test.go similarity index 100% rename from btcutil/psbt/sort_test.go rename to psbt/sort_test.go diff --git a/btcutil/psbt/taproot.go b/psbt/taproot.go similarity index 100% rename from btcutil/psbt/taproot.go rename to psbt/taproot.go diff --git a/btcutil/psbt/types.go b/psbt/types.go similarity index 100% rename from btcutil/psbt/types.go rename to psbt/types.go diff --git a/btcutil/psbt/updater.go b/psbt/updater.go similarity index 98% rename from btcutil/psbt/updater.go rename to psbt/updater.go index 26329f8a..33562c37 100644 --- a/btcutil/psbt/updater.go +++ b/psbt/updater.go @@ -14,9 +14,10 @@ import ( "bytes" "crypto/sha256" + "github.com/btcsuite/btcd/address/v2" "github.com/btcsuite/btcd/txscript/v2" "github.com/btcsuite/btcd/wire/v2" - "github.com/btcsuite/btcutil/v2" + "github.com/btcsuite/btcd/btcutil/v2" ) // Updater encapsulates the role 'Updater' as specified in BIP174; it accepts @@ -125,7 +126,7 @@ func (u *Updater) addPartialSignature(inIndex int, sig []byte, if pInput.RedeemScript != nil { outIndex := u.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Index scriptPubKey := pInput.NonWitnessUtxo.TxOut[outIndex].PkScript - scriptHash := btcutil.Hash160(pInput.RedeemScript) + scriptHash := address.Hash160(pInput.RedeemScript) scriptHashScript, err := txscript.NewScriptBuilder(). AddOp(txscript.OP_HASH160). @@ -155,7 +156,7 @@ func (u *Updater) addPartialSignature(inIndex int, sig []byte, var script []byte if pInput.RedeemScript != nil { - scriptHash := btcutil.Hash160(pInput.RedeemScript) + scriptHash := address.Hash160(pInput.RedeemScript) scriptHashScript, err := txscript.NewScriptBuilder(). AddOp(txscript.OP_HASH160). AddData(scriptHash). @@ -195,7 +196,7 @@ func (u *Updater) addPartialSignature(inIndex int, sig []byte, } } else { // Otherwise, this is a p2wkh input. - pubkeyHash := btcutil.Hash160(pubkey) + pubkeyHash := address.Hash160(pubkey) pubkeyHashScript, err := txscript.NewScriptBuilder(). AddOp(txscript.OP_0). AddData(pubkeyHash). diff --git a/btcutil/psbt/utils.go b/psbt/utils.go similarity index 100% rename from btcutil/psbt/utils.go rename to psbt/utils.go diff --git a/btcutil/psbt/utils_test.go b/psbt/utils_test.go similarity index 100% rename from btcutil/psbt/utils_test.go rename to psbt/utils_test.go