Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@
"disable": [
"gochecknoglobals",
"gocritic",
"godot"
"godot",
"godox",
"testifylint",
"revive",
"gochecknoinits",
"forbidigo",
"err113",
"errorlint",
"gosec",
"unused",
"gomoddirectives"
],
"enable": [
"asasalint",
Expand Down
46 changes: 46 additions & 0 deletions coinbase_placeholder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package subtree

import (
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/chainhash"
)

var (
// CoinbasePlaceholder hard code this value to avoid having to calculate it every time
// to help the compiler optimize the code.
CoinbasePlaceholder = [32]byte{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
}
CoinbasePlaceholderHashValue = chainhash.Hash(CoinbasePlaceholder)
CoinbasePlaceholderHash = &CoinbasePlaceholderHashValue

FrozenBytes = [36]byte{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
}
FrozenBytesTxBytes = FrozenBytes[0:32]
FrozenBytesTxHash = chainhash.Hash(FrozenBytesTxBytes)
)

var (
CoinbasePlaceholderTx *bt.Tx
coinbasePlaceholderTxHash *chainhash.Hash
)

func init() {
CoinbasePlaceholderTx = bt.NewTx()
CoinbasePlaceholderTx.Version = 0xFFFFFFFF
CoinbasePlaceholderTx.LockTime = 0xFFFFFFFF

coinbasePlaceholderTxHash = CoinbasePlaceholderTx.TxIDChainHash()
}

func IsCoinbasePlaceHolderTx(tx *bt.Tx) bool {
return tx.TxIDChainHash().IsEqual(coinbasePlaceholderTxHash)
}
17 changes: 17 additions & 0 deletions coinbase_placeholder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package subtree

import (
"testing"

"github.com/libsv/go-bt/v2"
"github.com/stretchr/testify/assert"
)

func TestCoinbasePlaceholderTx(t *testing.T) {
assert.True(t, IsCoinbasePlaceHolderTx(CoinbasePlaceholderTx))
assert.Equal(t, CoinbasePlaceholderTx.Version, uint32(0xFFFFFFFF))
assert.Equal(t, CoinbasePlaceholderTx.LockTime, uint32(0xFFFFFFFF))
assert.Equal(t, CoinbasePlaceholderTx.TxIDChainHash(), coinbasePlaceholderTxHash)
assert.False(t, IsCoinbasePlaceHolderTx(bt.NewTx()))
assert.Equal(t, "a8502e9c08b3c851201a71d25bf29fd38a664baedb777318b12d19242f0e46ab", CoinbasePlaceholderTx.TxIDChainHash().String())
}
19 changes: 19 additions & 0 deletions compare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package subtree

import "golang.org/x/exp/constraints"

func Min[T constraints.Ordered](a, b T) T {
if a < b {
return a
}

return b
}

func Max[T constraints.Ordered](a, b T) T {
if a > b {
return a
}

return b
}
43 changes: 43 additions & 0 deletions compare_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package subtree

import "testing"

func TestMin(t *testing.T) {
tests := []struct {
a, b, expected int
}{
{1, 2, 1},
{2, 1, 1},
{3, 3, 3},
{-1, 1, -1},
}

for _, tt := range tests {
t.Run("", func(t *testing.T) {
result := Min(tt.a, tt.b)
if result != tt.expected {
t.Errorf("Min(%d, %d) = %d; want %d", tt.a, tt.b, result, tt.expected)
}
})
}
}

func TestMax(t *testing.T) {
tests := []struct {
a, b, expected int
}{
{1, 2, 2},
{2, 1, 2},
{3, 3, 3},
{-1, 1, 1},
}

for _, tt := range tests {
t.Run("", func(t *testing.T) {
result := Max(tt.a, tt.b)
if result != tt.expected {
t.Errorf("Max(%d, %d) = %d; want %d", tt.a, tt.b, result, tt.expected)
}
})
}
}
15 changes: 0 additions & 15 deletions examples/example.go

This file was deleted.

16 changes: 15 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@ module github.com/bsv-blockchain/go-subtree

go 1.24

require github.com/stretchr/testify v1.10.0
require (
github.com/bsv-blockchain/go-safe-conversion v0.0.0-20250701040542-ca4e7b9ca0da
github.com/bsv-blockchain/go-tx-map v1.0.0
github.com/libsv/go-bt/v2 v2.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.10.0
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/dolthub/swiss v0.2.1 // indirect
github.com/libsv/go-bk v0.1.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/libsv/go-bt/v2 => github.com/ordishs/go-bt/v2 v2.2.22
31 changes: 30 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
github.com/bsv-blockchain/go-safe-conversion v0.0.0-20250701040542-ca4e7b9ca0da h1:WYjLgrUvgq1HjGcP1mU0aXPrqZ5l0UoDB/b9ssa/nxo=
github.com/bsv-blockchain/go-safe-conversion v0.0.0-20250701040542-ca4e7b9ca0da/go.mod h1:Fmat8fhPfMrdGCGv9PZ+QOkpQutD61hssbaLto4+3ks=
github.com/bsv-blockchain/go-tx-map v1.0.0 h1:oeGI6et039crvzuELKHojYdlZwDNf+UCv9r1+63sZHE=
github.com/bsv-blockchain/go-tx-map v1.0.0/go.mod h1:xCauj1rtF8dxuxP8WusegkFLzmcVCuLzcYZfjwXOi3Y=
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/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.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
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/ordishs/go-bt/v2 v2.2.22 h1:5WmTQoX74g9FADM9hpbXZOE34uep4EqeSwpIy4CbWYE=
github.com/ordishs/go-bt/v2 v2.2.22/go.mod h1:bOaZFOoazYognJH/nfcBjuDFud1XmIc05n7bp4Tvvfk=
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.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
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=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading