mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 06:36:46 +00:00
[DEV-14] Removed segwit from chaincfg package
This commit is contained in:
parent
9d6ea58b4c
commit
ca5100b459
@ -8,7 +8,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/daglabs/btcd/chaincfg/chainhash"
|
"github.com/daglabs/btcd/chaincfg/chainhash"
|
||||||
@ -91,11 +90,6 @@ const (
|
|||||||
// 68, 112, and 113.
|
// 68, 112, and 113.
|
||||||
DeploymentCSV
|
DeploymentCSV
|
||||||
|
|
||||||
// DeploymentSegwit defines the rule change deployment ID for the
|
|
||||||
// Segregated Witness (segwit) soft-fork package. The segwit package
|
|
||||||
// includes the deployment of BIPS 141, 142, 144, 145, 147 and 173.
|
|
||||||
DeploymentSegwit
|
|
||||||
|
|
||||||
// NOTE: DefinedDeployments must always come last since it is used to
|
// NOTE: DefinedDeployments must always come last since it is used to
|
||||||
// determine how many defined deployments there currently are.
|
// determine how many defined deployments there currently are.
|
||||||
|
|
||||||
@ -201,16 +195,10 @@ type Params struct {
|
|||||||
// Mempool parameters
|
// Mempool parameters
|
||||||
RelayNonStdTxs bool
|
RelayNonStdTxs bool
|
||||||
|
|
||||||
// Human-readable part for Bech32 encoded segwit addresses, as defined
|
|
||||||
// in BIP 173.
|
|
||||||
Bech32HRPSegwit string
|
|
||||||
|
|
||||||
// Address encoding magics
|
// Address encoding magics
|
||||||
PubKeyHashAddrID byte // First byte of a P2PKH address
|
PubKeyHashAddrID byte // First byte of a P2PKH address
|
||||||
ScriptHashAddrID byte // First byte of a P2SH address
|
ScriptHashAddrID byte // First byte of a P2SH address
|
||||||
PrivateKeyID byte // First byte of a WIF private key
|
PrivateKeyID byte // First byte of a WIF private key
|
||||||
WitnessPubKeyHashAddrID byte // First byte of a P2WPKH address
|
|
||||||
WitnessScriptHashAddrID byte // First byte of a P2WSH address
|
|
||||||
|
|
||||||
// BIP32 hierarchical deterministic extended key magics
|
// BIP32 hierarchical deterministic extended key magics
|
||||||
HDPrivateKeyID [4]byte
|
HDPrivateKeyID [4]byte
|
||||||
@ -291,26 +279,15 @@ var MainNetParams = Params{
|
|||||||
StartTime: 1462060800, // May 1st, 2016
|
StartTime: 1462060800, // May 1st, 2016
|
||||||
ExpireTime: 1493596800, // May 1st, 2017
|
ExpireTime: 1493596800, // May 1st, 2017
|
||||||
},
|
},
|
||||||
DeploymentSegwit: {
|
|
||||||
BitNumber: 1,
|
|
||||||
StartTime: 1479168000, // November 15, 2016 UTC
|
|
||||||
ExpireTime: 1510704000, // November 15, 2017 UTC.
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mempool parameters
|
// Mempool parameters
|
||||||
RelayNonStdTxs: false,
|
RelayNonStdTxs: false,
|
||||||
|
|
||||||
// Human-readable part for Bech32 encoded segwit addresses, as defined in
|
|
||||||
// BIP 173.
|
|
||||||
Bech32HRPSegwit: "bc", // always bc for main net
|
|
||||||
|
|
||||||
// Address encoding magics
|
// Address encoding magics
|
||||||
PubKeyHashAddrID: 0x00, // starts with 1
|
PubKeyHashAddrID: 0x00, // starts with 1
|
||||||
ScriptHashAddrID: 0x05, // starts with 3
|
ScriptHashAddrID: 0x05, // starts with 3
|
||||||
PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed)
|
PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed)
|
||||||
WitnessPubKeyHashAddrID: 0x06, // starts with p2
|
|
||||||
WitnessScriptHashAddrID: 0x0A, // starts with 7Xh
|
|
||||||
|
|
||||||
// BIP32 hierarchical deterministic extended key magics
|
// BIP32 hierarchical deterministic extended key magics
|
||||||
HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv
|
HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv
|
||||||
@ -367,20 +344,11 @@ var RegressionNetParams = Params{
|
|||||||
StartTime: 0, // Always available for vote
|
StartTime: 0, // Always available for vote
|
||||||
ExpireTime: math.MaxInt64, // Never expires
|
ExpireTime: math.MaxInt64, // Never expires
|
||||||
},
|
},
|
||||||
DeploymentSegwit: {
|
|
||||||
BitNumber: 1,
|
|
||||||
StartTime: 0, // Always available for vote
|
|
||||||
ExpireTime: math.MaxInt64, // Never expires.
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mempool parameters
|
// Mempool parameters
|
||||||
RelayNonStdTxs: true,
|
RelayNonStdTxs: true,
|
||||||
|
|
||||||
// Human-readable part for Bech32 encoded segwit addresses, as defined in
|
|
||||||
// BIP 173.
|
|
||||||
Bech32HRPSegwit: "bcrt", // always bcrt for reg test net
|
|
||||||
|
|
||||||
// Address encoding magics
|
// Address encoding magics
|
||||||
PubKeyHashAddrID: 0x6f, // starts with m or n
|
PubKeyHashAddrID: 0x6f, // starts with m or n
|
||||||
ScriptHashAddrID: 0xc4, // starts with 2
|
ScriptHashAddrID: 0xc4, // starts with 2
|
||||||
@ -458,26 +426,15 @@ var TestNet3Params = Params{
|
|||||||
StartTime: 1456790400, // March 1st, 2016
|
StartTime: 1456790400, // March 1st, 2016
|
||||||
ExpireTime: 1493596800, // May 1st, 2017
|
ExpireTime: 1493596800, // May 1st, 2017
|
||||||
},
|
},
|
||||||
DeploymentSegwit: {
|
|
||||||
BitNumber: 1,
|
|
||||||
StartTime: 1462060800, // May 1, 2016 UTC
|
|
||||||
ExpireTime: 1493596800, // May 1, 2017 UTC.
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mempool parameters
|
// Mempool parameters
|
||||||
RelayNonStdTxs: true,
|
RelayNonStdTxs: true,
|
||||||
|
|
||||||
// Human-readable part for Bech32 encoded segwit addresses, as defined in
|
|
||||||
// BIP 173.
|
|
||||||
Bech32HRPSegwit: "tb", // always tb for test net
|
|
||||||
|
|
||||||
// Address encoding magics
|
// Address encoding magics
|
||||||
PubKeyHashAddrID: 0x6f, // starts with m or n
|
PubKeyHashAddrID: 0x6f, // starts with m or n
|
||||||
ScriptHashAddrID: 0xc4, // starts with 2
|
ScriptHashAddrID: 0xc4, // starts with 2
|
||||||
WitnessPubKeyHashAddrID: 0x03, // starts with QW
|
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
|
||||||
WitnessScriptHashAddrID: 0x28, // starts with T7n
|
|
||||||
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
|
|
||||||
|
|
||||||
// BIP32 hierarchical deterministic extended key magics
|
// BIP32 hierarchical deterministic extended key magics
|
||||||
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
|
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
|
||||||
@ -538,26 +495,15 @@ var SimNetParams = Params{
|
|||||||
StartTime: 0, // Always available for vote
|
StartTime: 0, // Always available for vote
|
||||||
ExpireTime: math.MaxInt64, // Never expires
|
ExpireTime: math.MaxInt64, // Never expires
|
||||||
},
|
},
|
||||||
DeploymentSegwit: {
|
|
||||||
BitNumber: 1,
|
|
||||||
StartTime: 0, // Always available for vote
|
|
||||||
ExpireTime: math.MaxInt64, // Never expires.
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mempool parameters
|
// Mempool parameters
|
||||||
RelayNonStdTxs: true,
|
RelayNonStdTxs: true,
|
||||||
|
|
||||||
// Human-readable part for Bech32 encoded segwit addresses, as defined in
|
|
||||||
// BIP 173.
|
|
||||||
Bech32HRPSegwit: "sb", // always sb for sim net
|
|
||||||
|
|
||||||
// Address encoding magics
|
// Address encoding magics
|
||||||
PubKeyHashAddrID: 0x3f, // starts with S
|
PubKeyHashAddrID: 0x3f, // starts with S
|
||||||
ScriptHashAddrID: 0x7b, // starts with s
|
ScriptHashAddrID: 0x7b, // starts with s
|
||||||
PrivateKeyID: 0x64, // starts with 4 (uncompressed) or F (compressed)
|
PrivateKeyID: 0x64, // starts with 4 (uncompressed) or F (compressed)
|
||||||
WitnessPubKeyHashAddrID: 0x19, // starts with Gg
|
|
||||||
WitnessScriptHashAddrID: 0x28, // starts with ?
|
|
||||||
|
|
||||||
// BIP32 hierarchical deterministic extended key magics
|
// BIP32 hierarchical deterministic extended key magics
|
||||||
HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00}, // starts with sprv
|
HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00}, // starts with sprv
|
||||||
@ -581,11 +527,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
registeredNets = make(map[wire.BitcoinNet]struct{})
|
registeredNets = make(map[wire.BitcoinNet]struct{})
|
||||||
pubKeyHashAddrIDs = make(map[byte]struct{})
|
pubKeyHashAddrIDs = make(map[byte]struct{})
|
||||||
scriptHashAddrIDs = make(map[byte]struct{})
|
scriptHashAddrIDs = make(map[byte]struct{})
|
||||||
bech32SegwitPrefixes = make(map[string]struct{})
|
hdPrivToPubKeyIDs = make(map[[4]byte][]byte)
|
||||||
hdPrivToPubKeyIDs = make(map[[4]byte][]byte)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns the hostname of the DNS seed in human-readable form.
|
// String returns the hostname of the DNS seed in human-readable form.
|
||||||
@ -611,9 +556,6 @@ func Register(params *Params) error {
|
|||||||
scriptHashAddrIDs[params.ScriptHashAddrID] = struct{}{}
|
scriptHashAddrIDs[params.ScriptHashAddrID] = struct{}{}
|
||||||
hdPrivToPubKeyIDs[params.HDPrivateKeyID] = params.HDPublicKeyID[:]
|
hdPrivToPubKeyIDs[params.HDPrivateKeyID] = params.HDPublicKeyID[:]
|
||||||
|
|
||||||
// A valid Bech32 encoded segwit address always has as prefix the
|
|
||||||
// human-readable part for the given net followed by '1'.
|
|
||||||
bech32SegwitPrefixes[params.Bech32HRPSegwit+"1"] = struct{}{}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,15 +589,6 @@ func IsScriptHashAddrID(id byte) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
|
|
||||||
// addresses on any default or registered network. This is used when decoding
|
|
||||||
// an address string into a specific address type.
|
|
||||||
func IsBech32SegwitPrefix(prefix string) bool {
|
|
||||||
prefix = strings.ToLower(prefix)
|
|
||||||
_, ok := bech32SegwitPrefixes[prefix]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// HDPrivateKeyToPublicKeyID accepts a private hierarchical deterministic
|
// HDPrivateKeyToPublicKeyID accepts a private hierarchical deterministic
|
||||||
// extended key id and returns the associated public key id. When the provided
|
// extended key id and returns the associated public key id. When the provided
|
||||||
// id is not registered, the ErrUnknownHDKeyID error will be returned.
|
// id is not registered, the ErrUnknownHDKeyID error will be returned.
|
||||||
|
@ -3,7 +3,6 @@ package chaincfg_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/daglabs/btcd/chaincfg"
|
. "github.com/daglabs/btcd/chaincfg"
|
||||||
@ -17,7 +16,6 @@ var mockNetParams = Params{
|
|||||||
Net: 1<<32 - 1,
|
Net: 1<<32 - 1,
|
||||||
PubKeyHashAddrID: 0x9f,
|
PubKeyHashAddrID: 0x9f,
|
||||||
ScriptHashAddrID: 0xf9,
|
ScriptHashAddrID: 0xf9,
|
||||||
Bech32HRPSegwit: "tc",
|
|
||||||
HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04},
|
HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04},
|
||||||
HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08},
|
HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08},
|
||||||
}
|
}
|
||||||
@ -43,12 +41,11 @@ func TestRegister(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
register []registerTest
|
register []registerTest
|
||||||
p2pkhMagics []magicTest
|
p2pkhMagics []magicTest
|
||||||
p2shMagics []magicTest
|
p2shMagics []magicTest
|
||||||
segwitPrefixes []prefixTest
|
hdMagics []hdTest
|
||||||
hdMagics []hdTest
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "default networks",
|
name: "default networks",
|
||||||
@ -126,44 +123,6 @@ func TestRegister(t *testing.T) {
|
|||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
segwitPrefixes: []prefixTest{
|
|
||||||
{
|
|
||||||
prefix: MainNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: TestNet3Params.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: RegressionNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: SimNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: strings.ToUpper(MainNetParams.Bech32HRPSegwit + "1"),
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: mockNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: "abc1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: "1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: MainNetParams.Bech32HRPSegwit,
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
hdMagics: []hdTest{
|
hdMagics: []hdTest{
|
||||||
{
|
{
|
||||||
priv: MainNetParams.HDPrivateKeyID[:],
|
priv: MainNetParams.HDPrivateKeyID[:],
|
||||||
@ -260,44 +219,6 @@ func TestRegister(t *testing.T) {
|
|||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
segwitPrefixes: []prefixTest{
|
|
||||||
{
|
|
||||||
prefix: MainNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: TestNet3Params.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: RegressionNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: SimNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: strings.ToUpper(MainNetParams.Bech32HRPSegwit + "1"),
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: mockNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: "abc1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: "1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: MainNetParams.Bech32HRPSegwit,
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
hdMagics: []hdTest{
|
hdMagics: []hdTest{
|
||||||
{
|
{
|
||||||
priv: mockNetParams.HDPrivateKeyID[:],
|
priv: mockNetParams.HDPrivateKeyID[:],
|
||||||
@ -387,44 +308,6 @@ func TestRegister(t *testing.T) {
|
|||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
segwitPrefixes: []prefixTest{
|
|
||||||
{
|
|
||||||
prefix: MainNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: TestNet3Params.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: RegressionNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: SimNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: strings.ToUpper(MainNetParams.Bech32HRPSegwit + "1"),
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: mockNetParams.Bech32HRPSegwit + "1",
|
|
||||||
valid: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: "abc1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: "1",
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prefix: MainNetParams.Bech32HRPSegwit,
|
|
||||||
valid: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
hdMagics: []hdTest{
|
hdMagics: []hdTest{
|
||||||
{
|
{
|
||||||
priv: MainNetParams.HDPrivateKeyID[:],
|
priv: MainNetParams.HDPrivateKeyID[:],
|
||||||
@ -485,13 +368,6 @@ func TestRegister(t *testing.T) {
|
|||||||
test.name, i, valid, magTest.valid)
|
test.name, i, valid, magTest.valid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, prxTest := range test.segwitPrefixes {
|
|
||||||
valid := IsBech32SegwitPrefix(prxTest.prefix)
|
|
||||||
if valid != prxTest.valid {
|
|
||||||
t.Errorf("%s: segwit prefix %s (%d) valid mismatch: got %v expected %v",
|
|
||||||
test.name, prxTest.prefix, i, valid, prxTest.valid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i, magTest := range test.hdMagics {
|
for i, magTest := range test.hdMagics {
|
||||||
pubKey, err := HDPrivateKeyToPublicKeyID(magTest.priv[:])
|
pubKey, err := HDPrivateKeyToPublicKeyID(magTest.priv[:])
|
||||||
if !reflect.DeepEqual(err, magTest.err) {
|
if !reflect.DeepEqual(err, magTest.err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user