Skip to content

Commit

Permalink
Merge pull request #2276 from starius/wire-signet
Browse files Browse the repository at this point in the history
wire: add bitcoin network magic for default SigNet
  • Loading branch information
Roasbeef authored Jan 14, 2025
2 parents 8211142 + 38af045 commit f3bd1f5
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 @@ -165,7 +165,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 @@ -179,6 +179,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 @@ -189,6 +193,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 f3bd1f5

Please sign in to comment.