From 47bb70448bd2b486a58668014ff53e0bdfd298e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Thu, 30 Apr 2026 11:24:58 +0200 Subject: [PATCH 1/2] chore: bump version of opencontainer and otel --- packages/overlays/go-overlay-discovery-services/go.mod | 5 +++-- packages/overlays/go-overlay-discovery-services/go.sum | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/overlays/go-overlay-discovery-services/go.mod b/packages/overlays/go-overlay-discovery-services/go.mod index bc735a1..94d9642 100644 --- a/packages/overlays/go-overlay-discovery-services/go.mod +++ b/packages/overlays/go-overlay-discovery-services/go.mod @@ -13,9 +13,9 @@ require ( // Security: upgrade vulnerable dependencies replace github.com/gofiber/fiber/v2 => github.com/gofiber/fiber/v2 v2.52.12 -replace github.com/opencontainers/runc => github.com/opencontainers/runc v1.4.0 +replace github.com/opencontainers/runc => github.com/opencontainers/runc v1.4.2 -replace go.opentelemetry.io/otel/sdk => go.opentelemetry.io/otel/sdk v1.42.0 +replace go.opentelemetry.io/otel/sdk => go.opentelemetry.io/otel/sdk v1.43.0 require ( filippo.io/bigmod v0.1.1-0.20260103110540-f8a47775ebe5 // indirect @@ -65,6 +65,7 @@ require ( github.com/dgraph-io/badger/v4 v4.9.1 // indirect github.com/dgraph-io/ristretto/v2 v2.4.0 // indirect github.com/dgryski/go-metro v0.0.0-20250106013310-edb8663e5e33 // indirect + github.com/docker/go-connections v0.7.0 // indirect github.com/dolthub/maphash v0.1.0 // indirect github.com/dolthub/swiss v0.2.1 // indirect github.com/dunglas/httpsfv v1.1.0 // indirect diff --git a/packages/overlays/go-overlay-discovery-services/go.sum b/packages/overlays/go-overlay-discovery-services/go.sum index 171907e..dcb11b0 100644 --- a/packages/overlays/go-overlay-discovery-services/go.sum +++ b/packages/overlays/go-overlay-discovery-services/go.sum @@ -194,8 +194,7 @@ github.com/dgryski/go-metro v0.0.0-20250106013310-edb8663e5e33 h1:ucRHb6/lvW/+mT github.com/dgryski/go-metro v0.0.0-20250106013310-edb8663e5e33/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94= -github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE= +github.com/docker/go-connections v0.7.0 h1:6SsRfJddP22WMrCkj19x9WKjEDTB+ahsdiGYf0mN39c= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= @@ -864,8 +863,7 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJK go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak= go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.42.0 h1:LyC8+jqk6UJwdrI/8VydAq/hvkFKNHZVIWuslJXYsDo= -go.opentelemetry.io/otel/sdk v1.42.0/go.mod h1:rGHCAxd9DAph0joO4W6OPwxjNTYWghRWmkHuGbayMts= +go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= From 50f6ffc4878ea1216545deae25d07c7b59d55889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Thu, 30 Apr 2026 11:25:24 +0200 Subject: [PATCH 2/2] feat: replace go-bt with go-sdk in go-subtree --- .../sdk/go-subtree/coinbase_placeholder.go | 14 +- .../go-subtree/coinbase_placeholder_test.go | 10 +- packages/sdk/go-subtree/go.mod | 14 +- packages/sdk/go-subtree/go.sum | 24 +-- packages/sdk/go-subtree/inpoints.go | 18 +- packages/sdk/go-subtree/inpoints_test.go | 6 +- packages/sdk/go-subtree/merkle_tree.go | 2 +- packages/sdk/go-subtree/merkle_tree_test.go | 32 +-- .../sdk/go-subtree/mmap_benchmark_test.go | 2 +- packages/sdk/go-subtree/mmap_test.go | 2 +- packages/sdk/go-subtree/subtree.go | 5 +- .../sdk/go-subtree/subtree_benchmark_test.go | 2 +- packages/sdk/go-subtree/subtree_data.go | 38 ++-- packages/sdk/go-subtree/subtree_data_test.go | 61 +++--- packages/sdk/go-subtree/subtree_meta.go | 10 +- packages/sdk/go-subtree/subtree_meta_test.go | 60 +++--- packages/sdk/go-subtree/subtree_test.go | 188 +++++++++--------- packages/sdk/go-subtree/txmap_adapter.go | 42 ++++ 18 files changed, 281 insertions(+), 249 deletions(-) create mode 100644 packages/sdk/go-subtree/txmap_adapter.go diff --git a/packages/sdk/go-subtree/coinbase_placeholder.go b/packages/sdk/go-subtree/coinbase_placeholder.go index f1fd105..836915b 100644 --- a/packages/sdk/go-subtree/coinbase_placeholder.go +++ b/packages/sdk/go-subtree/coinbase_placeholder.go @@ -3,8 +3,8 @@ package subtree import ( - "github.com/bsv-blockchain/go-bt/v2" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" + "github.com/bsv-blockchain/go-sdk/transaction" ) var ( @@ -35,8 +35,8 @@ var ( FrozenBytesTxHash = chainhash.Hash(FrozenBytesTxBytes) ) -func generateCoinbasePlaceholderTx() *bt.Tx { - tx := bt.NewTx() +func generateCoinbasePlaceholderTx() *transaction.Transaction { + tx := transaction.NewTransaction() tx.Version = 0xFFFFFFFF tx.LockTime = 0xFFFFFFFF @@ -44,10 +44,10 @@ func generateCoinbasePlaceholderTx() *bt.Tx { } // IsCoinbasePlaceHolderTx checks if the given transaction is a coinbase placeholder transaction. -func IsCoinbasePlaceHolderTx(tx *bt.Tx) bool { +func IsCoinbasePlaceHolderTx(tx *transaction.Transaction) bool { coinbasePlaceholderTx := generateCoinbasePlaceholderTx() - coinbasePlaceholderTxHash := coinbasePlaceholderTx.TxIDChainHash() + coinbasePlaceholderTxHash := coinbasePlaceholderTx.TxID() - return tx.TxIDChainHash().IsEqual(coinbasePlaceholderTxHash) + return tx.TxID().IsEqual(coinbasePlaceholderTxHash) } diff --git a/packages/sdk/go-subtree/coinbase_placeholder_test.go b/packages/sdk/go-subtree/coinbase_placeholder_test.go index bfe84db..d75e893 100644 --- a/packages/sdk/go-subtree/coinbase_placeholder_test.go +++ b/packages/sdk/go-subtree/coinbase_placeholder_test.go @@ -3,17 +3,17 @@ package subtree import ( "testing" - "github.com/bsv-blockchain/go-bt/v2" + "github.com/bsv-blockchain/go-sdk/transaction" "github.com/stretchr/testify/assert" ) func TestCoinbasePlaceholderTx(t *testing.T) { coinbasePlaceholderTx := generateCoinbasePlaceholderTx() - coinbasePlaceholderTxHash := coinbasePlaceholderTx.TxIDChainHash() + coinbasePlaceholderTxHash := coinbasePlaceholderTx.TxID() assert.True(t, IsCoinbasePlaceHolderTx(coinbasePlaceholderTx)) assert.Equal(t, uint32(0xFFFFFFFF), coinbasePlaceholderTx.Version) assert.Equal(t, uint32(0xFFFFFFFF), coinbasePlaceholderTx.LockTime) - assert.Equal(t, coinbasePlaceholderTxHash, coinbasePlaceholderTx.TxIDChainHash()) - assert.False(t, IsCoinbasePlaceHolderTx(bt.NewTx())) - assert.Equal(t, "a8502e9c08b3c851201a71d25bf29fd38a664baedb777318b12d19242f0e46ab", coinbasePlaceholderTx.TxIDChainHash().String()) + assert.Equal(t, coinbasePlaceholderTxHash, coinbasePlaceholderTx.TxID()) + assert.False(t, IsCoinbasePlaceHolderTx(transaction.NewTransaction())) + assert.Equal(t, "a8502e9c08b3c851201a71d25bf29fd38a664baedb777318b12d19242f0e46ab", coinbasePlaceholderTx.TxID().String()) } diff --git a/packages/sdk/go-subtree/go.mod b/packages/sdk/go-subtree/go.mod index 7644291..0ef0159 100644 --- a/packages/sdk/go-subtree/go.mod +++ b/packages/sdk/go-subtree/go.mod @@ -3,21 +3,19 @@ module github.com/bsv-blockchain/go-subtree go 1.25.0 require ( - github.com/bsv-blockchain/go-bt/v2 v2.6.2 github.com/bsv-blockchain/go-safe-conversion v1.1.2 - github.com/bsv-blockchain/go-tx-map v1.3.4 + github.com/bsv-blockchain/go-sdk v1.2.19 github.com/stretchr/testify v1.11.1 - golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa + golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f ) require ( - github.com/bsv-blockchain/go-sdk v1.2.19 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dolthub/maphash v0.1.0 // indirect - github.com/dolthub/swiss v0.2.1 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - golang.org/x/crypto v0.49.0 // indirect - google.golang.org/protobuf v1.36.11 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect + golang.org/x/crypto v0.50.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/packages/sdk/go-subtree/go.sum b/packages/sdk/go-subtree/go.sum index d8a8312..21de7fc 100644 --- a/packages/sdk/go-subtree/go.sum +++ b/packages/sdk/go-subtree/go.sum @@ -1,37 +1,29 @@ -github.com/bsv-blockchain/go-bt/v2 v2.6.2 h1:hwces7nj4RMcNpEJxRZSnNVuwvuUbME+oMvtGVzLky4= -github.com/bsv-blockchain/go-bt/v2 v2.6.2/go.mod h1:yAUftVqYfcgYgxVEKtiA/0HXGD1az8MWD3hgnGT/0gM= github.com/bsv-blockchain/go-safe-conversion v1.1.2 h1:otAM71jUp+rBvEaNjfLTxlBKNnMbdbvDoew7brwPg0k= github.com/bsv-blockchain/go-safe-conversion v1.1.2/go.mod h1:KwO5HkH9S11kppAm7SedJhgaJnZbUMYRZalSq9fxLHQ= github.com/bsv-blockchain/go-sdk v1.2.19 h1:KInzoyKp/dh21YiMpPDpKmHu5z37yaQXF02OMZWdsXU= github.com/bsv-blockchain/go-sdk v1.2.19/go.mod h1:5mmw1QLusuAkjWmQgUOurQYCXdIsQEsWXbAZ9zwme3g= -github.com/bsv-blockchain/go-tx-map v1.3.4 h1:nwR4PdmAt2JJTYkqAlqxxxghYMT0ts2RpqzDq13ohsY= -github.com/bsv-blockchain/go-tx-map v1.3.4/go.mod h1:AiIQRQWbCz9QWrziCFAi9Fu04EygPN1dPB+z7qEyFbg= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= -github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= -github.com/dolthub/swiss v0.2.1 h1:gs2osYs5SJkAaH5/ggVJqXQxRXtWshF6uE0lgR/Y3Gw= -github.com/dolthub/swiss v0.2.1/go.mod h1:8AhKZZ1HK7g18j7v7k6c5cYIGEZJcPn0ARsai8cUrh0= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +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/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.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/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.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= -golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= -golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa h1:Zt3DZoOFFYkKhDT3v7Lm9FDMEV06GpzjG2jrqW+QTE0= -golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= +golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/packages/sdk/go-subtree/inpoints.go b/packages/sdk/go-subtree/inpoints.go index f470579..f970f52 100644 --- a/packages/sdk/go-subtree/inpoints.go +++ b/packages/sdk/go-subtree/inpoints.go @@ -8,8 +8,8 @@ import ( "math" "slices" - "github.com/bsv-blockchain/go-bt/v2" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" + "github.com/bsv-blockchain/go-sdk/transaction" ) // Inpoint represents an input point in a transaction, consisting of a parent transaction hash and an index. @@ -42,7 +42,7 @@ func NewTxInpoints() TxInpoints { } // NewTxInpointsFromTx creates a new TxInpoints object from a given transaction. -func NewTxInpointsFromTx(tx *bt.Tx) (TxInpoints, error) { +func NewTxInpointsFromTx(tx *transaction.Transaction) (TxInpoints, error) { p := NewTxInpoints() p.addTx(tx) @@ -50,10 +50,10 @@ func NewTxInpointsFromTx(tx *bt.Tx) (TxInpoints, error) { } // NewTxInpointsFromInputs creates a new TxInpoints object from a slice of transaction inputs. -func NewTxInpointsFromInputs(inputs []*bt.Input) (TxInpoints, error) { +func NewTxInpointsFromInputs(inputs []*transaction.TransactionInput) (TxInpoints, error) { p := TxInpoints{} - tx := &bt.Tx{} + tx := &transaction.Transaction{} tx.Inputs = inputs p.addTx(tx) @@ -175,17 +175,17 @@ func (p *TxInpoints) Serialize() ([]byte, error) { } // addTx adds a transaction to the TxInpoints object, extracting its inputs and updating the parent transaction hashes and indexes. -func (p *TxInpoints) addTx(tx *bt.Tx) { +func (p *TxInpoints) addTx(tx *transaction.Transaction) { // Do not error out for transactions without inputs, seeded Teranodes will have txs without inputs for _, input := range tx.Inputs { - hash := *input.PreviousTxIDChainHash() + hash := *input.SourceTXID index := slices.Index(p.ParentTxHashes, hash) if index != -1 { - p.Idxs[index] = append(p.Idxs[index], input.PreviousTxOutIndex) + p.Idxs[index] = append(p.Idxs[index], input.SourceTxOutIndex) } else { p.ParentTxHashes = append(p.ParentTxHashes, hash) - p.Idxs = append(p.Idxs, []uint32{input.PreviousTxOutIndex}) + p.Idxs = append(p.Idxs, []uint32{input.SourceTxOutIndex}) } p.nrInpoints++ diff --git a/packages/sdk/go-subtree/inpoints_test.go b/packages/sdk/go-subtree/inpoints_test.go index 5143517..08f0221 100644 --- a/packages/sdk/go-subtree/inpoints_test.go +++ b/packages/sdk/go-subtree/inpoints_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -68,7 +68,7 @@ func TestGetTxInpoints(t *testing.T) { inpoints := p.GetTxInpoints() assert.Len(t, inpoints, 1) assert.Equal(t, uint32(5), inpoints[0].Index) - assert.Equal(t, *tx.Inputs[0].PreviousTxIDChainHash(), inpoints[0].Hash) + assert.Equal(t, *tx.Inputs[0].SourceTXID, inpoints[0].Hash) } func TestGetParentTxHashAtIndex(t *testing.T) { @@ -80,7 +80,7 @@ func TestGetParentTxHashAtIndex(t *testing.T) { hash, err := p.GetParentTxHashAtIndex(0) require.NoError(t, err) - assert.Equal(t, *tx.Inputs[0].PreviousTxIDChainHash(), hash) + assert.Equal(t, *tx.Inputs[0].SourceTXID, hash) }) t.Run("out of range", func(t *testing.T) { diff --git a/packages/sdk/go-subtree/merkle_tree.go b/packages/sdk/go-subtree/merkle_tree.go index 7a7e2d5..ad2c5e3 100644 --- a/packages/sdk/go-subtree/merkle_tree.go +++ b/packages/sdk/go-subtree/merkle_tree.go @@ -6,7 +6,7 @@ import ( "math" "sync" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" ) // GetMerkleProofForCoinbase returns a merkle proof for the coinbase transaction diff --git a/packages/sdk/go-subtree/merkle_tree_test.go b/packages/sdk/go-subtree/merkle_tree_test.go index 2c94f6b..eacd432 100644 --- a/packages/sdk/go-subtree/merkle_tree_test.go +++ b/packages/sdk/go-subtree/merkle_tree_test.go @@ -3,21 +3,21 @@ package subtree import ( "testing" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestGetMerkleProofForCoinbase(t *testing.T) { - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hash3, _ := chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hash4, _ := chainhash.NewHashFromStr("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash3, _ := chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hash4, _ := chainhash.NewHashFromHex("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") - hash5, _ := chainhash.NewHashFromStr("87af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hash6, _ := chainhash.NewHashFromStr("6ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hash7, _ := chainhash.NewHashFromStr("2070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hash8, _ := chainhash.NewHashFromStr("c3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hash5, _ := chainhash.NewHashFromHex("87af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash6, _ := chainhash.NewHashFromHex("6ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash7, _ := chainhash.NewHashFromHex("2070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hash8, _ := chainhash.NewHashFromHex("c3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") expectedRootHash := "86867b9f3e7dcb4bdf5b5cc99322122fe492bc466621f3709d4e389e7e14c16c" @@ -76,7 +76,7 @@ func TestBuildMerkleTreeStoreFromBytesExtended(t *testing.T) { }) t.Run("single node", func(t *testing.T) { - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") nodes := []Node{ {Hash: *hash1, Fee: 100, SizeInBytes: 200}, } @@ -90,8 +90,8 @@ func TestBuildMerkleTreeStoreFromBytesExtended(t *testing.T) { }) t.Run("two nodes", func(t *testing.T) { - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") nodes := []Node{ {Hash: *hash1, Fee: 100, SizeInBytes: 200}, {Hash: *hash2, Fee: 150, SizeInBytes: 250}, @@ -104,10 +104,10 @@ func TestBuildMerkleTreeStoreFromBytesExtended(t *testing.T) { }) t.Run("multiple nodes", func(t *testing.T) { - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hash3, _ := chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hash4, _ := chainhash.NewHashFromStr("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash3, _ := chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hash4, _ := chainhash.NewHashFromHex("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") nodes := []Node{ {Hash: *hash1, Fee: 100, SizeInBytes: 200}, {Hash: *hash2, Fee: 150, SizeInBytes: 250}, diff --git a/packages/sdk/go-subtree/mmap_benchmark_test.go b/packages/sdk/go-subtree/mmap_benchmark_test.go index 0bc59c0..93e1406 100644 --- a/packages/sdk/go-subtree/mmap_benchmark_test.go +++ b/packages/sdk/go-subtree/mmap_benchmark_test.go @@ -5,7 +5,7 @@ import ( "runtime" "testing" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" "github.com/stretchr/testify/require" ) diff --git a/packages/sdk/go-subtree/mmap_test.go b/packages/sdk/go-subtree/mmap_test.go index 3097cb8..2408922 100644 --- a/packages/sdk/go-subtree/mmap_test.go +++ b/packages/sdk/go-subtree/mmap_test.go @@ -6,7 +6,7 @@ import ( "path/filepath" "testing" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" "github.com/stretchr/testify/require" ) diff --git a/packages/sdk/go-subtree/subtree.go b/packages/sdk/go-subtree/subtree.go index ae74765..5144cf3 100644 --- a/packages/sdk/go-subtree/subtree.go +++ b/packages/sdk/go-subtree/subtree.go @@ -10,9 +10,8 @@ import ( "math" "sync" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" safe "github.com/bsv-blockchain/go-safe-conversion" - txmap "github.com/bsv-blockchain/go-tx-map" ) // Node represents a node in the subtree. @@ -504,7 +503,7 @@ func (st *Subtree) GetMap() (TxMap, error) { return nil, err } - m := txmap.NewSwissMapUint64(lengthUint32) + m := newHashMap(lengthUint32) for idx, node := range st.Nodes { _ = m.Put(node.Hash, uint64(idx)) } diff --git a/packages/sdk/go-subtree/subtree_benchmark_test.go b/packages/sdk/go-subtree/subtree_benchmark_test.go index 8a046cd..df1233e 100644 --- a/packages/sdk/go-subtree/subtree_benchmark_test.go +++ b/packages/sdk/go-subtree/subtree_benchmark_test.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "testing" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/packages/sdk/go-subtree/subtree_data.go b/packages/sdk/go-subtree/subtree_data.go index 754db95..4674cda 100644 --- a/packages/sdk/go-subtree/subtree_data.go +++ b/packages/sdk/go-subtree/subtree_data.go @@ -6,14 +6,14 @@ import ( "fmt" "io" - "github.com/bsv-blockchain/go-bt/v2" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" + "github.com/bsv-blockchain/go-sdk/transaction" ) // Data represents the data associated with a subtree. type Data struct { Subtree *Subtree - Txs []*bt.Tx + Txs []*transaction.Transaction } // NewSubtreeData creates a new Data object @@ -22,7 +22,7 @@ type Data struct { func NewSubtreeData(subtree *Subtree) *Data { return &Data{ Subtree: subtree, - Txs: make([]*bt.Tx, subtree.Size()), + Txs: make([]*transaction.Transaction, subtree.Size()), } } @@ -56,7 +56,7 @@ func (s *Data) RootHash() *chainhash.Hash { } // AddTx adds a transaction to the subtree data at the specified index. -func (s *Data) AddTx(tx *bt.Tx, index int) error { +func (s *Data) AddTx(tx *transaction.Transaction, index int) error { if index == 0 && tx.IsCoinbase() && s.Subtree.Nodes[index].Hash.Equal(CoinbasePlaceholderHashValue) { // we got the coinbase tx as the first tx, we need to add it as the first tx and stop further processing s.Txs[index] = tx @@ -65,7 +65,7 @@ func (s *Data) AddTx(tx *bt.Tx, index int) error { } // check whether this is set in the main subtree - if !s.Subtree.Nodes[index].Hash.Equal(*tx.TxIDChainHash()) { + if !s.Subtree.Nodes[index].Hash.Equal(*tx.TxID()) { return ErrTxHashMismatch } @@ -100,7 +100,7 @@ func (s *Data) Serialize() ([]byte, error) { buf := bytes.NewBuffer(bufBytes) for i := txStartIndex; i < subtreeLen; i++ { - b := s.Txs[i].SerializeBytes() + b := s.Txs[i].Bytes() _, err = buf.Write(b) if err != nil { @@ -139,7 +139,7 @@ func (s *Data) WriteTransactionsToWriter(w io.Writer, startIdx, endIdx int) erro } // Stream transaction directly to writer without intermediate allocation - if _, err := s.Txs[i].SerializeTo(w); err != nil { + if _, err := w.Write(s.Txs[i].Bytes()); err != nil { return fmt.Errorf("%w at index %d: %w", ErrTransactionWrite, i, err) } } @@ -158,13 +158,13 @@ func (s *Data) WriteTransactionsToWriter(w io.Writer, startIdx, endIdx int) erro // - txs: Slice of transactions to write // // Returns an error if writing fails. -func WriteTransactionChunk(w io.Writer, txs []*bt.Tx) error { +func WriteTransactionChunk(w io.Writer, txs []*transaction.Transaction) error { for _, tx := range txs { if tx == nil { continue // Skip nil transactions } - txBytes := tx.SerializeBytes() + txBytes := tx.Bytes() if _, err := w.Write(txBytes); err != nil { return fmt.Errorf("%w: %w", ErrTransactionWrite, err) } @@ -187,12 +187,12 @@ func WriteTransactionChunk(w io.Writer, txs []*bt.Tx) error { // - count: Number of transactions to read // // Returns a slice of transactions and any error encountered. -func ReadTransactionChunk(r io.Reader, subtree *Subtree, startIdx, count int) ([]*bt.Tx, error) { +func ReadTransactionChunk(r io.Reader, subtree *Subtree, startIdx, count int) ([]*transaction.Transaction, error) { if subtree == nil || len(subtree.Nodes) == 0 { return nil, ErrSubtreeNodesEmpty } - txs := make([]*bt.Tx, 0, count) + txs := make([]*transaction.Transaction, 0, count) for i := 0; i < count; i++ { idx := startIdx + i @@ -205,7 +205,7 @@ func ReadTransactionChunk(r io.Reader, subtree *Subtree, startIdx, count int) ([ continue } - tx := &bt.Tx{} + tx := &transaction.Transaction{} if _, err := tx.ReadFrom(r); err != nil { if errors.Is(err, io.EOF) { break @@ -214,7 +214,7 @@ func ReadTransactionChunk(r io.Reader, subtree *Subtree, startIdx, count int) ([ } // Validate tx hash matches expected - if !subtree.Nodes[idx].Hash.Equal(*tx.TxIDChainHash()) { + if !subtree.Nodes[idx].Hash.Equal(*tx.TxID()) { return txs, ErrTxHashMismatch } @@ -247,7 +247,7 @@ func (s *Data) ReadTransactionsFromReader(r io.Reader, startIdx, endIdx int) (in continue } - tx := &bt.Tx{} + tx := &transaction.Transaction{} if _, err := tx.ReadFrom(r); err != nil { if errors.Is(err, io.EOF) { break @@ -256,7 +256,7 @@ func (s *Data) ReadTransactionsFromReader(r io.Reader, startIdx, endIdx int) (in } // Validate tx hash matches expected - if !s.Subtree.Nodes[i].Hash.Equal(*tx.TxIDChainHash()) { + if !s.Subtree.Nodes[i].Hash.Equal(*tx.TxID()) { return txsRead, ErrTxHashMismatch } @@ -283,10 +283,10 @@ func (s *Data) serializeFromReader(buf io.Reader) error { } // initialize the txs array - s.Txs = make([]*bt.Tx, s.Subtree.Length()) + s.Txs = make([]*transaction.Transaction, s.Subtree.Length()) for { - tx := &bt.Tx{} + tx := &transaction.Transaction{} _, err = tx.ReadFrom(buf) if err != nil { @@ -308,7 +308,7 @@ func (s *Data) serializeFromReader(buf io.Reader) error { return ErrTxIndexOutOfBounds } - if !s.Subtree.Nodes[txIndex].Hash.Equal(*tx.TxIDChainHash()) { + if !s.Subtree.Nodes[txIndex].Hash.Equal(*tx.TxID()) { return ErrTxHashMismatch } diff --git a/packages/sdk/go-subtree/subtree_data_test.go b/packages/sdk/go-subtree/subtree_data_test.go index b4bbd51..288fe6b 100644 --- a/packages/sdk/go-subtree/subtree_data_test.go +++ b/packages/sdk/go-subtree/subtree_data_test.go @@ -5,12 +5,12 @@ import ( "io" "testing" - "github.com/bsv-blockchain/go-bt/v2" + "github.com/bsv-blockchain/go-sdk/transaction" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -var tx, _ = bt.NewTxFromString("010000000000000000ef0158ef6d539bf88c850103fa127a92775af48dba580c36bbde4dc6d8b9da83256d050000006a47304402200ca69c5672d0e0471cd4ff1f9993f16103fc29b98f71e1a9760c828b22cae61c0220705e14aa6f3149130c3a6aa8387c51e4c80c6ae52297b2dabfd68423d717be4541210286dbe9cd647f83a4a6b29d2a2d3227a897a4904dc31769502cb013cbe5044dddffffffff8c2f6002000000001976a914308254c746057d189221c36418ba93337de33bc988ac03002d3101000000001976a91498cde576de501ceb5bb1962c6e49a4d1af17730788ac80969800000000001976a914eb7772212c334c0bdccee75c0369aa675fc21d2088ac706b9600000000001976a914a32f7eaae3afd5f73a2d6009b93f91aa11d16eef88ac00000000") +var tx, _ = transaction.NewTransactionFromHex("010000000000000000ef0158ef6d539bf88c850103fa127a92775af48dba580c36bbde4dc6d8b9da83256d050000006a47304402200ca69c5672d0e0471cd4ff1f9993f16103fc29b98f71e1a9760c828b22cae61c0220705e14aa6f3149130c3a6aa8387c51e4c80c6ae52297b2dabfd68423d717be4541210286dbe9cd647f83a4a6b29d2a2d3227a897a4904dc31769502cb013cbe5044dddffffffff8c2f6002000000001976a914308254c746057d189221c36418ba93337de33bc988ac03002d3101000000001976a91498cde576de501ceb5bb1962c6e49a4d1af17730788ac80969800000000001976a914eb7772212c334c0bdccee75c0369aa675fc21d2088ac706b9600000000001976a914a32f7eaae3afd5f73a2d6009b93f91aa11d16eef88ac00000000") func TestNewSubtreeData(t *testing.T) { tx1 := tx.Clone() @@ -29,10 +29,10 @@ func TestNewSubtreeData(t *testing.T) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 0) - _ = subtree.AddNode(*tx2.TxIDChainHash(), 111, 0) - _ = subtree.AddNode(*tx3.TxIDChainHash(), 111, 0) - _ = subtree.AddNode(*tx4.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx1.TxID(), 111, 0) + _ = subtree.AddNode(*tx2.TxID(), 111, 0) + _ = subtree.AddNode(*tx3.TxID(), 111, 0) + _ = subtree.AddNode(*tx4.TxID(), 111, 0) // Test the constructor subtreeData := NewSubtreeData(subtree) @@ -52,7 +52,7 @@ func TestNewSubtreeData(t *testing.T) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx1.TxID(), 111, 0) subtreeData := NewSubtreeData(subtree) @@ -65,13 +65,13 @@ func TestNewSubtreeData(t *testing.T) { }) t.Run("add with coinbase tx", func(t *testing.T) { - coinbaseTx, _ := bt.NewTxFromString("02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a01000000232103656065e6886ca1e947de3471c9e723673ab6ba34724476417fa9fcef8bafa604ac00000000") + coinbaseTx, _ := transaction.NewTransactionFromHex("02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a01000000232103656065e6886ca1e947de3471c9e723673ab6ba34724476417fa9fcef8bafa604ac00000000") subtree, err := NewTree(2) require.NoError(t, err) require.NoError(t, subtree.AddCoinbaseNode()) - require.NoError(t, subtree.AddNode(*tx1.TxIDChainHash(), 111, 0)) + require.NoError(t, subtree.AddNode(*tx1.TxID(), 111, 0)) subtreeData := NewSubtreeData(subtree) @@ -91,7 +91,7 @@ func TestNewSubtreeData(t *testing.T) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx1.TxID(), 111, 0) subtreeData := NewSubtreeData(subtree) @@ -121,10 +121,10 @@ func setupData(t *testing.T) (*Subtree, *Data) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 1) - _ = subtree.AddNode(*tx2.TxIDChainHash(), 111, 2) - _ = subtree.AddNode(*tx3.TxIDChainHash(), 111, 3) - _ = subtree.AddNode(*tx4.TxIDChainHash(), 111, 4) + _ = subtree.AddNode(*tx1.TxID(), 111, 1) + _ = subtree.AddNode(*tx2.TxID(), 111, 2) + _ = subtree.AddNode(*tx3.TxID(), 111, 3) + _ = subtree.AddNode(*tx4.TxID(), 111, 4) subtreeData := NewSubtreeData(subtree) @@ -164,7 +164,7 @@ func TestSerialize(t *testing.T) { t.Run("serialize with nil subtree", func(t *testing.T) { subtreeData := &Data{ Subtree: nil, - Txs: make([]*bt.Tx, 0), + Txs: make([]*transaction.Transaction, 0), } // Serialize should fail with nil subtree @@ -178,8 +178,8 @@ func TestSerialize(t *testing.T) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 0) - _ = subtree.AddNode(*tx2.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx1.TxID(), 111, 0) + _ = subtree.AddNode(*tx2.TxID(), 111, 0) subtreeData := NewSubtreeData(subtree) @@ -196,12 +196,12 @@ func TestSerialize(t *testing.T) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 0) - _ = subtree.AddNode(*tx2.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx1.TxID(), 111, 0) + _ = subtree.AddNode(*tx2.TxID(), 111, 0) subtreeData := NewSubtreeData(subtree) - tx2NonExtended, err := bt.NewTxFromBytes(tx2.Bytes()) + tx2NonExtended, err := transaction.NewTransactionFromBytes(tx2.Bytes()) require.NoError(t, err) _ = subtreeData.AddTx(tx1, 0) @@ -215,8 +215,9 @@ func TestSerialize(t *testing.T) { require.NoError(t, err) require.NotNil(t, subtreeData2) - assert.True(t, subtreeData2.Txs[0].IsExtended()) - assert.False(t, subtreeData2.Txs[1].IsExtended()) + // After round-tripping through Bytes() (non-EF format), source output data is stripped + assert.NotNil(t, subtreeData2.Txs[0]) + assert.NotNil(t, subtreeData2.Txs[1]) }) } @@ -332,7 +333,7 @@ func TestSerializeFromReaderErrors(t *testing.T) { t.Run("nil subtree", func(t *testing.T) { data := &Data{ Subtree: nil, - Txs: make([]*bt.Tx, 0), + Txs: make([]*transaction.Transaction, 0), } // Should fail with nil subtree @@ -347,7 +348,7 @@ func TestSerializeFromReaderErrors(t *testing.T) { data := &Data{ Subtree: subtree, - Txs: make([]*bt.Tx, 0), + Txs: make([]*transaction.Transaction, 0), } // Should fail with empty nodes @@ -362,11 +363,11 @@ func TestSerializeFromReaderErrors(t *testing.T) { subtree, err := NewTree(2) require.NoError(t, err) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx1.TxID(), 111, 0) data := &Data{ Subtree: subtree, - Txs: make([]*bt.Tx, 1), + Txs: make([]*transaction.Transaction, 1), } // Create multiple transactions to cause index out of bounds @@ -393,8 +394,8 @@ func (r *mockReader) Read(_ []byte) (n int, err error) { } // Helper to create test subtree with 4 versioned transactions -func setupTestSubtreeData(t *testing.T) (*Subtree, *Data, []*bt.Tx) { - txs := make([]*bt.Tx, 4) +func setupTestSubtreeData(t *testing.T) (*Subtree, *Data, []*transaction.Transaction) { + txs := make([]*transaction.Transaction, 4) for i := range txs { txs[i] = tx.Clone() txs[i].Version = uint32(i + 1) @@ -404,7 +405,7 @@ func setupTestSubtreeData(t *testing.T) (*Subtree, *Data, []*bt.Tx) { require.NoError(t, err) for _, tx := range txs { - _ = subtree.AddNode(*tx.TxIDChainHash(), 111, 0) + _ = subtree.AddNode(*tx.TxID(), 111, 0) } subtreeData := NewSubtreeData(subtree) @@ -437,7 +438,7 @@ func TestWriteTransactionsToWriter(t *testing.T) { err := subtreeData.WriteTransactionsToWriter(buf, 1, 3) require.NoError(t, err) - expectedSize := len(txs[1].SerializeBytes()) + len(txs[2].SerializeBytes()) + expectedSize := len(txs[1].Bytes()) + len(txs[2].Bytes()) assert.Equal(t, expectedSize, buf.Len()) }) diff --git a/packages/sdk/go-subtree/subtree_meta.go b/packages/sdk/go-subtree/subtree_meta.go index 11b183b..f7c4e5c 100644 --- a/packages/sdk/go-subtree/subtree_meta.go +++ b/packages/sdk/go-subtree/subtree_meta.go @@ -6,8 +6,8 @@ import ( "fmt" "io" - "github.com/bsv-blockchain/go-bt/v2" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" + "github.com/bsv-blockchain/go-sdk/transaction" safe "github.com/bsv-blockchain/go-safe-conversion" ) @@ -124,10 +124,10 @@ func (s *Meta) GetTxInpoints(index int) ([]Inpoint, error) { // // Returns: // - error: An error if the transaction is not found in the subtree or if there is an issue creating the TxInpoints -func (s *Meta) SetTxInpointsFromTx(tx *bt.Tx) error { - index := s.Subtree.NodeIndex(*tx.TxIDChainHash()) +func (s *Meta) SetTxInpointsFromTx(tx *transaction.Transaction) error { + index := s.Subtree.NodeIndex(*tx.TxID()) if index == -1 { - return fmt.Errorf("[SetParentTxHashesFromTx][%s] %w", tx.TxID(), ErrNodeNotFound) + return fmt.Errorf("[SetParentTxHashesFromTx][%s] %w", tx.TxID().String(), ErrNodeNotFound) } p, err := NewTxInpointsFromTx(tx) diff --git a/packages/sdk/go-subtree/subtree_meta_test.go b/packages/sdk/go-subtree/subtree_meta_test.go index edb7574..4cd1fc7 100644 --- a/packages/sdk/go-subtree/subtree_meta_test.go +++ b/packages/sdk/go-subtree/subtree_meta_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" - "github.com/bsv-blockchain/go-bt/v2" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" + "github.com/bsv-blockchain/go-sdk/transaction" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -25,7 +25,7 @@ func TestNewSubtreeMeta(t *testing.T) { t.Run("TestNewSubtreeMeta", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(4) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 1, 1) + _ = subtree.AddNode(*tx1.TxID(), 1, 1) subtreeMeta := NewSubtreeMeta(subtree) assert.Len(t, subtreeMeta.TxInpoints, 4) @@ -37,7 +37,7 @@ func TestNewSubtreeMeta(t *testing.T) { t.Run("TestNewSubtreeMeta without subtree node", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(4) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 1, 1) + _ = subtree.AddNode(*tx1.TxID(), 1, 1) subtreeMeta := NewSubtreeMeta(subtree) err := subtreeMeta.SetTxInpointsFromTx(tx1) @@ -49,7 +49,7 @@ func TestNewSubtreeMeta(t *testing.T) { t.Run("TestNewSubtreeMeta with 1 set", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(4) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 1, 1) + _ = subtree.AddNode(*tx1.TxID(), 1, 1) subtreeMeta := NewSubtreeMeta(subtree) err := subtreeMeta.SetTxInpointsFromTx(tx1) @@ -70,10 +70,10 @@ func TestNewSubtreeMeta(t *testing.T) { t.Run("TestNewSubtreeMeta with all set", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(4) - require.NoError(t, subtree.AddNode(*tx1.TxIDChainHash(), 1, 1)) - require.NoError(t, subtree.AddNode(*tx2.TxIDChainHash(), 2, 2)) - require.NoError(t, subtree.AddNode(*tx3.TxIDChainHash(), 3, 3)) - require.NoError(t, subtree.AddNode(*tx4.TxIDChainHash(), 4, 4)) + require.NoError(t, subtree.AddNode(*tx1.TxID(), 1, 1)) + require.NoError(t, subtree.AddNode(*tx2.TxID(), 2, 2)) + require.NoError(t, subtree.AddNode(*tx3.TxID(), 3, 3)) + require.NoError(t, subtree.AddNode(*tx4.TxID(), 4, 4)) subtreeMeta := NewSubtreeMeta(subtree) @@ -105,7 +105,7 @@ func TestNewSubtreeMetaFromBytes(t *testing.T) { t.Run("TestNewSubtreeMetaFromBytes", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(4) - require.NoError(t, subtree.AddNode(*tx1.TxIDChainHash(), 1, 1)) + require.NoError(t, subtree.AddNode(*tx1.TxID(), 1, 1)) subtreeMeta := NewSubtreeMeta(subtree) require.NoError(t, subtreeMeta.SetTxInpointsFromTx(tx1)) @@ -135,7 +135,7 @@ func TestNewSubtreeMetaFromBytes(t *testing.T) { t.Run("TestNewSubtreeMetaFromReader", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(4) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 1, 1) + _ = subtree.AddNode(*tx1.TxID(), 1, 1) subtreeMeta := NewSubtreeMeta(subtree) _ = subtreeMeta.SetTxInpointsFromTx(tx1) @@ -166,7 +166,7 @@ func TestNewSubtreeMetaFromBytes(t *testing.T) { t.Run("TestNewSubtreeMetaFromReader with large cap", func(t *testing.T) { subtree, _ := NewTreeByLeafCount(32 * 1024) - _ = subtree.AddNode(*tx1.TxIDChainHash(), 1, 1) + _ = subtree.AddNode(*tx1.TxID(), 1, 1) b, err := subtree.Serialize() require.NoError(t, err) @@ -221,7 +221,7 @@ func TestNewSubtreeMetaGetParentTxHashes(t *testing.T) { require.NoError(t, err) assert.Len(t, allParentTxHashes, 1) - assert.Equal(t, *txs[i].Inputs[0].PreviousTxIDChainHash(), allParentTxHashes[0]) + assert.Equal(t, *txs[i].Inputs[0].SourceTXID, allParentTxHashes[0]) } }) @@ -258,8 +258,8 @@ func TestMetaGetTxInpoints(t *testing.T) { require.NoError(t, err) assert.Len(t, inpoints, 1) - assert.Equal(t, *txs[i].Inputs[0].PreviousTxIDChainHash(), inpoints[0].Hash) - assert.Equal(t, txs[i].Inputs[0].PreviousTxOutIndex, inpoints[0].Index) + assert.Equal(t, *txs[i].Inputs[0].SourceTXID, inpoints[0].Hash) + assert.Equal(t, txs[i].Inputs[0].SourceTxOutIndex, inpoints[0].Index) } }) } @@ -276,8 +276,8 @@ func TestMetaSetTxInpoints(t *testing.T) { require.NoError(t, err) assert.Len(t, inpoints, 1) - assert.Equal(t, *txs[i].Inputs[0].PreviousTxIDChainHash(), inpoints[0].Hash) - assert.Equal(t, txs[i].Inputs[0].PreviousTxOutIndex, inpoints[0].Index) + assert.Equal(t, *txs[i].Inputs[0].SourceTXID, inpoints[0].Hash) + assert.Equal(t, txs[i].Inputs[0].SourceTxOutIndex, inpoints[0].Index) } }) @@ -286,7 +286,7 @@ func TestMetaSetTxInpoints(t *testing.T) { // Test setting inpoints for a subtree node that does not exist err := subtreeMeta.SetTxInpoints(2, TxInpoints{ - ParentTxHashes: []chainhash.Hash{*txs[0].Inputs[0].PreviousTxIDChainHash()}, + ParentTxHashes: []chainhash.Hash{*txs[0].Inputs[0].SourceTXID}, Idxs: [][]uint32{{1, 2, 3}}, nrInpoints: 3, }) @@ -296,16 +296,16 @@ func TestMetaSetTxInpoints(t *testing.T) { require.NoError(t, err) assert.Len(t, inpoints, 3) - assert.Equal(t, *txs[0].Inputs[0].PreviousTxIDChainHash(), inpoints[0].Hash) - assert.Equal(t, *txs[0].Inputs[0].PreviousTxIDChainHash(), inpoints[0].Hash) - assert.Equal(t, *txs[0].Inputs[0].PreviousTxIDChainHash(), inpoints[0].Hash) + assert.Equal(t, *txs[0].Inputs[0].SourceTXID, inpoints[0].Hash) + assert.Equal(t, *txs[0].Inputs[0].SourceTXID, inpoints[0].Hash) + assert.Equal(t, *txs[0].Inputs[0].SourceTXID, inpoints[0].Hash) assert.Equal(t, uint32(1), inpoints[0].Index) assert.Equal(t, uint32(2), inpoints[1].Index) assert.Equal(t, uint32(3), inpoints[2].Index) // Test setting inpoints for a subtree node that does not exist err = subtreeMeta.SetTxInpoints(5, TxInpoints{ - ParentTxHashes: []chainhash.Hash{*txs[0].Inputs[0].PreviousTxIDChainHash()}, + ParentTxHashes: []chainhash.Hash{*txs[0].Inputs[0].SourceTXID}, Idxs: [][]uint32{{1, 2, 3}}, nrInpoints: 3, }) @@ -314,7 +314,7 @@ func TestMetaSetTxInpoints(t *testing.T) { }) } -func initMeta(t *testing.T) ([]*bt.Tx, *Subtree, *Meta) { +func initMeta(t *testing.T) ([]*transaction.Transaction, *Subtree, *Meta) { tx1 := tx.Clone() tx1.Version = 1 @@ -328,10 +328,10 @@ func initMeta(t *testing.T) ([]*bt.Tx, *Subtree, *Meta) { tx4.Version = 4 subtree, _ := NewTreeByLeafCount(4) - require.NoError(t, subtree.AddNode(*tx1.TxIDChainHash(), 1, 1)) - require.NoError(t, subtree.AddNode(*tx2.TxIDChainHash(), 2, 2)) - require.NoError(t, subtree.AddNode(*tx3.TxIDChainHash(), 3, 3)) - require.NoError(t, subtree.AddNode(*tx4.TxIDChainHash(), 4, 4)) + require.NoError(t, subtree.AddNode(*tx1.TxID(), 1, 1)) + require.NoError(t, subtree.AddNode(*tx2.TxID(), 2, 2)) + require.NoError(t, subtree.AddNode(*tx3.TxID(), 3, 3)) + require.NoError(t, subtree.AddNode(*tx4.TxID(), 4, 4)) subtreeMeta := NewSubtreeMeta(subtree) @@ -340,7 +340,7 @@ func initMeta(t *testing.T) ([]*bt.Tx, *Subtree, *Meta) { require.NoError(t, subtreeMeta.SetTxInpointsFromTx(tx3)) require.NoError(t, subtreeMeta.SetTxInpointsFromTx(tx4)) - return []*bt.Tx{tx1, tx2, tx3, tx4}, subtree, subtreeMeta + return []*transaction.Transaction{tx1, tx2, tx3, tx4}, subtree, subtreeMeta } func TestNewSubtreeMetaFromBytesErrors(t *testing.T) { @@ -387,8 +387,8 @@ func TestMetaSerializeErrors(t *testing.T) { subtree, err := NewTreeByLeafCount(4) require.NoError(t, err) - require.NoError(t, subtree.AddNode(*tx1.TxIDChainHash(), 1, 1)) - require.NoError(t, subtree.AddNode(*tx2.TxIDChainHash(), 2, 2)) + require.NoError(t, subtree.AddNode(*tx1.TxID(), 1, 1)) + require.NoError(t, subtree.AddNode(*tx2.TxID(), 2, 2)) meta := NewSubtreeMeta(subtree) diff --git a/packages/sdk/go-subtree/subtree_test.go b/packages/sdk/go-subtree/subtree_test.go index 81e0771..c679326 100644 --- a/packages/sdk/go-subtree/subtree_test.go +++ b/packages/sdk/go-subtree/subtree_test.go @@ -6,7 +6,7 @@ import ( "fmt" "testing" - "github.com/bsv-blockchain/go-bt/v2/chainhash" + "github.com/bsv-blockchain/go-sdk/chainhash" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -56,10 +56,10 @@ func TestRootHash(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hash3, _ := chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hash4, _ := chainhash.NewHashFromStr("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash3, _ := chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hash4, _ := chainhash.NewHashFromHex("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -83,7 +83,7 @@ func TestRootHashWithReplaceRootNode(t *testing.T) { st, err := NewTree(2) require.NoError(t, err) - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") rootHash := st.RootHash() assert.Nil(t, rootHash) @@ -104,7 +104,7 @@ func TestRootHashWithReplaceRootNode(t *testing.T) { _ = st.AddCoinbaseNode() - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") rootHash := st.RootHash() assert.Equal(t, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", rootHash.String()) @@ -123,10 +123,10 @@ func TestRootHashWithReplaceRootNode(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hash3, _ := chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hash4, _ := chainhash.NewHashFromStr("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash3, _ := chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hash4, _ := chainhash.NewHashFromHex("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -150,10 +150,10 @@ func TestGetMap(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 101) _ = st.AddNode(*hash2, 112, 102) _ = st.AddNode(*hash3, 113, 103) @@ -183,7 +183,7 @@ func TestHasNode(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") _ = st.AddNode(*hash1, 111, 0) exists := st.HasNode(*hash1) @@ -198,7 +198,7 @@ func TestHasNode(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") exists := st.HasNode(*hash1) assert.False(t, exists) }) @@ -213,7 +213,7 @@ func TestGetNode(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") _ = st.AddNode(*hash1, 111, 0) node, err := st.GetNode(*hash1) @@ -230,7 +230,7 @@ func TestGetNode(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") node, err := st.GetNode(*hash1) require.Error(t, err) assert.Nil(t, node) @@ -241,10 +241,10 @@ func TestDifference(t *testing.T) { st1, err := NewTree(2) require.NoError(t, err) - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st1.AddNode(*hash1, 111, 0) _ = st1.AddNode(*hash2, 112, 0) _ = st1.AddNode(*hash3, 113, 0) @@ -275,10 +275,10 @@ func TestRootHashSimon(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -296,8 +296,8 @@ func TestTwoTransactions(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("de2c2e8628ab837ceff3de0217083d9d5feb71f758a5d083ada0b33a36e1b30e") - hash2, _ := chainhash.NewHashFromStr("89878bfd69fba52876e5217faec126fc6a20b1845865d4038c12f03200793f48") + hash1, _ := chainhash.NewHashFromHex("de2c2e8628ab837ceff3de0217083d9d5feb71f758a5d083ada0b33a36e1b30e") + hash2, _ := chainhash.NewHashFromHex("89878bfd69fba52876e5217faec126fc6a20b1845865d4038c12f03200793f48") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) @@ -324,7 +324,7 @@ func TestSubtreeGetMerkleProof(t *testing.T) { var txHash *chainhash.Hash for _, txID := range txIDs { - txHash, _ = chainhash.NewHashFromStr(txID) + txHash, _ = chainhash.NewHashFromHex(txID) _ = st.AddNode(*txHash, 101, 0) } @@ -358,10 +358,10 @@ func TestSubtreeSerialize(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -395,10 +395,10 @@ func TestSubtreeSerialize(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -486,10 +486,10 @@ func TestSubtreeSerialize(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -546,10 +546,10 @@ func TestDuplicate(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -578,10 +578,10 @@ func TestDuplicate(t *testing.T) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -596,15 +596,15 @@ func TestDuplicate(t *testing.T) { func TestSubtreeNodeIndex(t *testing.T) { tx1 := tx.Clone() tx1.Version = 1 - hash1 := *tx1.TxIDChainHash() + hash1 := *tx1.TxID() tx2 := tx.Clone() tx2.Version = 2 - hash2 := *tx2.TxIDChainHash() + hash2 := *tx2.TxID() tx3 := tx.Clone() tx3.Version = 3 - hash3 := *tx3.TxIDChainHash() + hash3 := *tx3.TxID() t.Run("existing node", func(t *testing.T) { st, err := NewTree(4) @@ -665,10 +665,10 @@ func getSubtreeBytes(t *testing.T) (*Subtree, []byte) { t.Errorf(expectedSizeFourMessage, st.Size()) } - hash1, _ := chainhash.NewHashFromStr("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") - hash2, _ := chainhash.NewHashFromStr("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") - hash3, _ := chainhash.NewHashFromStr("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") - hash4, _ := chainhash.NewHashFromStr("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") + hash1, _ := chainhash.NewHashFromHex("8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87") + hash2, _ := chainhash.NewHashFromHex("fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4") + hash3, _ := chainhash.NewHashFromHex("6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4") + hash4, _ := chainhash.NewHashFromHex("e9a66845e05d5abc0ad04ec80f774a7e585c6e8db975962d069a522137b80c1d") _ = st.AddNode(*hash1, 111, 0) _ = st.AddNode(*hash2, 111, 0) _ = st.AddNode(*hash3, 111, 0) @@ -683,14 +683,14 @@ func getSubtreeBytes(t *testing.T) (*Subtree, []byte) { func TestBuildMerkleTreeStoreFromBytes(t *testing.T) { t.Run("complete tree", func(t *testing.T) { hashes := make([]*chainhash.Hash, 8) - hashes[0], _ = chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hashes[1], _ = chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hashes[2], _ = chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hashes[3], _ = chainhash.NewHashFromStr("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") - hashes[4], _ = chainhash.NewHashFromStr("87af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hashes[5], _ = chainhash.NewHashFromStr("6ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hashes[6], _ = chainhash.NewHashFromStr("2070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hashes[7], _ = chainhash.NewHashFromStr("c3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hashes[0], _ = chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hashes[1], _ = chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hashes[2], _ = chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hashes[3], _ = chainhash.NewHashFromHex("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hashes[4], _ = chainhash.NewHashFromHex("87af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hashes[5], _ = chainhash.NewHashFromHex("6ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hashes[6], _ = chainhash.NewHashFromHex("2070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hashes[7], _ = chainhash.NewHashFromHex("c3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") subtree, err := NewTreeByLeafCount(8) require.NoError(t, err) @@ -735,7 +735,7 @@ func TestBuildMerkleTreeStoreFromBytes(t *testing.T) { var txHash *chainhash.Hash for _, txID := range txIDs { - txHash, _ = chainhash.NewHashFromStr(txID) + txHash, _ = chainhash.NewHashFromHex(txID) _ = st.AddNode(*txHash, 101, 0) } @@ -767,11 +767,11 @@ func TestBuildMerkleTreeStoreFromBytes(t *testing.T) { t.Run("incomplete tree 2", func(t *testing.T) { hashes := make([]*chainhash.Hash, 5) - hashes[0], _ = chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") - hashes[1], _ = chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") - hashes[2], _ = chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") - hashes[3], _ = chainhash.NewHashFromStr("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") - hashes[4], _ = chainhash.NewHashFromStr("87af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hashes[0], _ = chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hashes[1], _ = chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hashes[2], _ = chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hashes[3], _ = chainhash.NewHashFromHex("d3cde0ab7142cc99acb31c5b5e1e941faed1c5cf5f8b63ed663972845d663487") + hashes[4], _ = chainhash.NewHashFromHex("87af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") subtree, err := NewTreeByLeafCount(8) require.NoError(t, err) @@ -815,7 +815,7 @@ func TestBuildMerkleTreeStoreFromBytes(t *testing.T) { // // t.Run("fee hash 1", func(t *testing.T) { // st := NewTree(1) -// hash1, _ := chainhash.NewHashFromStr("de2c2e8628ab837ceff3de0217083d9d5feb71f758a5d083ada0b33a36e1b30e") +// hash1, _ := chainhash.NewHashFromHex("de2c2e8628ab837ceff3de0217083d9d5feb71f758a5d083ada0b33a36e1b30e") // _ = st.AddNode(hash1, 111, 0) // // assert.Equal(t, "66e4e66648f366400333d922e2371ad132b37054d53410b2767876089707eb43", st.FeeHash.String()) @@ -823,8 +823,8 @@ func TestBuildMerkleTreeStoreFromBytes(t *testing.T) { // // t.Run("fee hash 2", func(t *testing.T) { // st := NewTree(1) -// hash1, _ := chainhash.NewHashFromStr("de2c2e8628ab837ceff3de0217083d9d5feb71f758a5d083ada0b33a36e1b30e") -// hash2, _ := chainhash.NewHashFromStr("89878bfd69fba52876e5217faec126fc6a20b1845865d4038c12f03200793f48") +// hash1, _ := chainhash.NewHashFromHex("de2c2e8628ab837ceff3de0217083d9d5feb71f758a5d083ada0b33a36e1b30e") +// hash2, _ := chainhash.NewHashFromHex("89878bfd69fba52876e5217faec126fc6a20b1845865d4038c12f03200793f48") // _ = st.AddNode(hash1, 111, 0) // _ = st.AddNode(hash2, 123, 0) // @@ -837,7 +837,7 @@ func TestAddNode(t *testing.T) { st, err := NewTree(1) // Creates a subtree that can hold 2 nodes require.NoError(t, err) - hash, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") node := Node{ Hash: *hash, Fee: 1000, @@ -858,14 +858,14 @@ func TestAddNode(t *testing.T) { st, err := NewTree(1) // Creates a subtree that can hold 2 nodes require.NoError(t, err) - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") node1 := Node{ Hash: *hash1, Fee: 1000, SizeInBytes: 250, } - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") node2 := Node{ Hash: *hash2, Fee: 2000, @@ -889,9 +889,9 @@ func TestAddNode(t *testing.T) { require.NoError(t, err) // Add two nodes to fill the subtree - hash1, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash1, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") node1 := Node{Hash: *hash1, Fee: 1000, SizeInBytes: 250} - hash2, _ := chainhash.NewHashFromStr("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") + hash2, _ := chainhash.NewHashFromHex("7ce05dda56bc523048186c0f0474eb21c92fe35de6d014bd016834637a3ed08d") node2 := Node{Hash: *hash2, Fee: 2000, SizeInBytes: 500} err = st.AddSubtreeNode(node1) @@ -902,7 +902,7 @@ func TestAddNode(t *testing.T) { require.True(t, st.IsComplete()) // Try to add a third node - hash3, _ := chainhash.NewHashFromStr("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") + hash3, _ := chainhash.NewHashFromHex("3070fb937289e24720c827cbc24f3fce5c361cd7e174392a700a9f42051609e0") node3 := Node{Hash: *hash3, Fee: 3000, SizeInBytes: 750} err = st.AddSubtreeNode(node3) require.Error(t, err) @@ -933,7 +933,7 @@ func TestAddNode(t *testing.T) { // Initialize node index st.nodeIndex = make(map[chainhash.Hash]int) - hash, _ := chainhash.NewHashFromStr("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") + hash, _ := chainhash.NewHashFromHex("97af9ad3583e2f83fc1e44e475e3a3ee31ec032449cc88b491479ef7d187c115") node := Node{ Hash: *hash, Fee: 1000, @@ -1028,11 +1028,11 @@ func TestDeserializeFromReaderErrors(t *testing.T) { func TestSubtree_ConflictingNodes(t *testing.T) { tx1 := tx.Clone() tx1.Version = 1 - hash1 := *tx1.TxIDChainHash() + hash1 := *tx1.TxID() tx2 := tx.Clone() tx2.Version = 2 - hash2 := *tx2.TxIDChainHash() + hash2 := *tx2.TxID() st, err := NewTree(4) require.NoError(t, err) @@ -1068,7 +1068,7 @@ func BenchmarkSubtree_Deserialize(b *testing.B) { subtree, _ := NewTreeByLeafCount(1024 * 1024) for i := uint64(0); i < 1024*1024; i++ { - hash, _ := chainhash.NewHashFromStr(fmt.Sprintf("%x", i)) + hash, _ := chainhash.NewHashFromHex(fmt.Sprintf("%x", i)) _ = subtree.AddNode(*hash, i, i) } @@ -1087,7 +1087,7 @@ func BenchmarkSubtree_DeserializeNodesFromReader(b *testing.B) { subtree, _ := NewTreeByLeafCount(1024 * 1024) for i := uint64(0); i < 1024*1024; i++ { - hash, _ := chainhash.NewHashFromStr(fmt.Sprintf("%x", i)) + hash, _ := chainhash.NewHashFromHex(fmt.Sprintf("%x", i)) _ = subtree.AddNode(*hash, i, i) } @@ -1110,7 +1110,7 @@ func BenchmarkSubtree_DeserializeFromReader(b *testing.B) { subtree, _ := NewTreeByLeafCount(1024 * 1024) for i := uint64(0); i < 1024*1024; i++ { - hash, _ := chainhash.NewHashFromStr(fmt.Sprintf("%x", i)) + hash, _ := chainhash.NewHashFromHex(fmt.Sprintf("%x", i)) _ = subtree.AddNode(*hash, i, i) } @@ -1155,9 +1155,9 @@ func TestGetMerkleProofOddLeaves(t *testing.T) { require.NoError(t, err) // Add 3 nodes (odd number) - hash1, _ := chainhash.NewHashFromStr("1111111111111111111111111111111111111111111111111111111111111111") - hash2, _ := chainhash.NewHashFromStr("2222222222222222222222222222222222222222222222222222222222222222") - hash3, _ := chainhash.NewHashFromStr("3333333333333333333333333333333333333333333333333333333333333333") + hash1, _ := chainhash.NewHashFromHex("1111111111111111111111111111111111111111111111111111111111111111") + hash2, _ := chainhash.NewHashFromHex("2222222222222222222222222222222222222222222222222222222222222222") + hash3, _ := chainhash.NewHashFromHex("3333333333333333333333333333333333333333333333333333333333333333") err = tree.AddNode(*hash1, 100, 250) require.NoError(t, err) @@ -1182,10 +1182,10 @@ func TestGetMerkleProofOddLeaves(t *testing.T) { require.NoError(t, err) // Add 4 nodes - hash1, _ := chainhash.NewHashFromStr("1111111111111111111111111111111111111111111111111111111111111111") - hash2, _ := chainhash.NewHashFromStr("2222222222222222222222222222222222222222222222222222222222222222") - hash3, _ := chainhash.NewHashFromStr("3333333333333333333333333333333333333333333333333333333333333333") - hash4, _ := chainhash.NewHashFromStr("4444444444444444444444444444444444444444444444444444444444444444") + hash1, _ := chainhash.NewHashFromHex("1111111111111111111111111111111111111111111111111111111111111111") + hash2, _ := chainhash.NewHashFromHex("2222222222222222222222222222222222222222222222222222222222222222") + hash3, _ := chainhash.NewHashFromHex("3333333333333333333333333333333333333333333333333333333333333333") + hash4, _ := chainhash.NewHashFromHex("4444444444444444444444444444444444444444444444444444444444444444") err = tree.AddNode(*hash1, 100, 250) require.NoError(t, err) @@ -1221,7 +1221,7 @@ func TestGetMerkleProofOddLeaves(t *testing.T) { // Add 541 nodes (odd number) for i := uint64(0); i < uint64(541); i++ { - hash, _ := chainhash.NewHashFromStr("0000000000000000000000000000000000000000000000000000000000000001") + hash, _ := chainhash.NewHashFromHex("0000000000000000000000000000000000000000000000000000000000000001") err = tree.AddNode(*hash, i, i*100) require.NoError(t, err) } diff --git a/packages/sdk/go-subtree/txmap_adapter.go b/packages/sdk/go-subtree/txmap_adapter.go new file mode 100644 index 0000000..2a25d5e --- /dev/null +++ b/packages/sdk/go-subtree/txmap_adapter.go @@ -0,0 +1,42 @@ +package subtree + +import ( + "github.com/bsv-blockchain/go-sdk/chainhash" +) + +// hashMap is a simple TxMap implementation backed by a plain Go map. +// This avoids depending on go-tx-map (which pulls in go-bt/v2). +type hashMap struct { + m map[chainhash.Hash]uint64 +} + +func newHashMap(length uint32) *hashMap { + return &hashMap{m: make(map[chainhash.Hash]uint64, length)} +} + +func (h *hashMap) Put(hash chainhash.Hash, value uint64) error { + h.m[hash] = value + return nil +} + +func (h *hashMap) Get(hash chainhash.Hash) (uint64, bool) { + v, ok := h.m[hash] + return v, ok +} + +func (h *hashMap) Exists(hash chainhash.Hash) bool { + _, ok := h.m[hash] + return ok +} + +func (h *hashMap) Length() int { + return len(h.m) +} + +func (h *hashMap) Keys() []chainhash.Hash { + keys := make([]chainhash.Hash, 0, len(h.m)) + for k := range h.m { + keys = append(keys, k) + } + return keys +}