Skip to content

Commit

Permalink
wire: add bitcoin network magic for default SigNet
Browse files Browse the repository at this point in the history
Added constant wire.SigNet, added it to stringer for BitcoinNet type.
Added a test in chaincfg to compare calculated magic value with the constant.
  • Loading branch information
starius committed Nov 25, 2024
1 parent e9d95ee commit 38af045
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions chaincfg/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"encoding/hex"
"math/big"
"testing"

"github.com/btcsuite/btcd/wire"
"github.com/stretchr/testify/require"
)

// TestInvalidHashStr ensures the newShaHashFromStr function panics when used to
Expand Down Expand Up @@ -104,6 +107,12 @@ func TestSigNetPowLimit(t *testing.T) {
}
}

// TestSigNetMagic makes sure that the default signet has the expected bitcoin
// network magic.
func TestSigNetMagic(t *testing.T) {
require.Equal(t, wire.SigNet, SigNetParams.Net)
}

// compactToBig is a copy of the blockchain.CompactToBig function. We copy it
// here so we don't run into a circular dependency just because of a test.
func compactToBig(compact uint32) *big.Int {
Expand Down
1 change: 1 addition & 0 deletions wire/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ the following constants:
wire.MainNet
wire.TestNet (Regression test network)
wire.TestNet3 (Test network version 3)
wire.SigNet (Signet, default)
wire.SimNet (Simulation test network)
# Determining Message Type
Expand Down
7 changes: 6 additions & 1 deletion wire/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (f ServiceFlag) String() string {
// BitcoinNet represents which bitcoin network a message belongs to.
type BitcoinNet uint32

// Constants used to indicate the message bitcoin network. They can also be
// Constants used to indicate the message bitcoin network. They can also be
// used to seek to the next message when a stream's state is unknown, but
// this package does not provide that functionality since it's generally a
// better idea to simply disconnect clients that are misbehaving over TCP.
Expand All @@ -183,6 +183,10 @@ const (
// TestNet3 represents the test network (version 3).
TestNet3 BitcoinNet = 0x0709110b

// SigNet represents the public default SigNet. For custom signets,
// see CustomSignetParams.
SigNet BitcoinNet = 0x40CF030A

// SimNet represents the simulation test network.
SimNet BitcoinNet = 0x12141c16
)
Expand All @@ -193,6 +197,7 @@ var bnStrings = map[BitcoinNet]string{
MainNet: "MainNet",
TestNet: "TestNet",
TestNet3: "TestNet3",
SigNet: "SigNet",
SimNet: "SimNet",
}

Expand Down
1 change: 1 addition & 0 deletions wire/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestBitcoinNetStringer(t *testing.T) {
{MainNet, "MainNet"},
{TestNet, "TestNet"},
{TestNet3, "TestNet3"},
{SigNet, "SigNet"},
{SimNet, "SimNet"},
{0xffffffff, "Unknown BitcoinNet (4294967295)"},
}
Expand Down

0 comments on commit 38af045

Please sign in to comment.