diff --git a/chaincfg/params.go b/chaincfg/params.go index b48d44484..c5f839efe 100644 --- a/chaincfg/params.go +++ b/chaincfg/params.go @@ -8,7 +8,6 @@ import ( "errors" "math" "math/big" - "strings" "time" "github.com/daglabs/btcd/chaincfg/chainhash" @@ -91,11 +90,6 @@ const ( // 68, 112, and 113. 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 // determine how many defined deployments there currently are. @@ -201,16 +195,10 @@ type Params struct { // Mempool parameters RelayNonStdTxs bool - // Human-readable part for Bech32 encoded segwit addresses, as defined - // in BIP 173. - Bech32HRPSegwit string - // Address encoding magics - PubKeyHashAddrID byte // First byte of a P2PKH address - ScriptHashAddrID byte // First byte of a P2SH address - 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 + PubKeyHashAddrID byte // First byte of a P2PKH address + ScriptHashAddrID byte // First byte of a P2SH address + PrivateKeyID byte // First byte of a WIF private key // BIP32 hierarchical deterministic extended key magics HDPrivateKeyID [4]byte @@ -291,26 +279,15 @@ var MainNetParams = Params{ StartTime: 1462060800, // May 1st, 2016 ExpireTime: 1493596800, // May 1st, 2017 }, - DeploymentSegwit: { - BitNumber: 1, - StartTime: 1479168000, // November 15, 2016 UTC - ExpireTime: 1510704000, // November 15, 2017 UTC. - }, }, // Mempool parameters 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 - PubKeyHashAddrID: 0x00, // starts with 1 - ScriptHashAddrID: 0x05, // starts with 3 - PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed) - WitnessPubKeyHashAddrID: 0x06, // starts with p2 - WitnessScriptHashAddrID: 0x0A, // starts with 7Xh + PubKeyHashAddrID: 0x00, // starts with 1 + ScriptHashAddrID: 0x05, // starts with 3 + PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed) // BIP32 hierarchical deterministic extended key magics HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv @@ -367,20 +344,11 @@ var RegressionNetParams = Params{ StartTime: 0, // Always available for vote ExpireTime: math.MaxInt64, // Never expires }, - DeploymentSegwit: { - BitNumber: 1, - StartTime: 0, // Always available for vote - ExpireTime: math.MaxInt64, // Never expires. - }, }, // Mempool parameters 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 PubKeyHashAddrID: 0x6f, // starts with m or n ScriptHashAddrID: 0xc4, // starts with 2 @@ -458,26 +426,15 @@ var TestNet3Params = Params{ StartTime: 1456790400, // March 1st, 2016 ExpireTime: 1493596800, // May 1st, 2017 }, - DeploymentSegwit: { - BitNumber: 1, - StartTime: 1462060800, // May 1, 2016 UTC - ExpireTime: 1493596800, // May 1, 2017 UTC. - }, }, // Mempool parameters 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 - PubKeyHashAddrID: 0x6f, // starts with m or n - ScriptHashAddrID: 0xc4, // starts with 2 - WitnessPubKeyHashAddrID: 0x03, // starts with QW - WitnessScriptHashAddrID: 0x28, // starts with T7n - PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed) + PubKeyHashAddrID: 0x6f, // starts with m or n + ScriptHashAddrID: 0xc4, // starts with 2 + PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed) // BIP32 hierarchical deterministic extended key magics HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv @@ -538,26 +495,15 @@ var SimNetParams = Params{ StartTime: 0, // Always available for vote ExpireTime: math.MaxInt64, // Never expires }, - DeploymentSegwit: { - BitNumber: 1, - StartTime: 0, // Always available for vote - ExpireTime: math.MaxInt64, // Never expires. - }, }, // Mempool parameters 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 - PubKeyHashAddrID: 0x3f, // starts with S - ScriptHashAddrID: 0x7b, // starts with s - PrivateKeyID: 0x64, // starts with 4 (uncompressed) or F (compressed) - WitnessPubKeyHashAddrID: 0x19, // starts with Gg - WitnessScriptHashAddrID: 0x28, // starts with ? + PubKeyHashAddrID: 0x3f, // starts with S + ScriptHashAddrID: 0x7b, // starts with s + PrivateKeyID: 0x64, // starts with 4 (uncompressed) or F (compressed) // BIP32 hierarchical deterministic extended key magics HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00}, // starts with sprv @@ -581,11 +527,10 @@ var ( ) var ( - registeredNets = make(map[wire.BitcoinNet]struct{}) - pubKeyHashAddrIDs = make(map[byte]struct{}) - scriptHashAddrIDs = make(map[byte]struct{}) - bech32SegwitPrefixes = make(map[string]struct{}) - hdPrivToPubKeyIDs = make(map[[4]byte][]byte) + registeredNets = make(map[wire.BitcoinNet]struct{}) + pubKeyHashAddrIDs = make(map[byte]struct{}) + scriptHashAddrIDs = make(map[byte]struct{}) + hdPrivToPubKeyIDs = make(map[[4]byte][]byte) ) // 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{}{} 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 } @@ -647,15 +589,6 @@ func IsScriptHashAddrID(id byte) bool { 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 // extended key id and returns the associated public key id. When the provided // id is not registered, the ErrUnknownHDKeyID error will be returned. diff --git a/chaincfg/register_test.go b/chaincfg/register_test.go index 1cb04dd6b..0a63af367 100644 --- a/chaincfg/register_test.go +++ b/chaincfg/register_test.go @@ -3,7 +3,6 @@ package chaincfg_test import ( "bytes" "reflect" - "strings" "testing" . "github.com/daglabs/btcd/chaincfg" @@ -17,7 +16,6 @@ var mockNetParams = Params{ Net: 1<<32 - 1, PubKeyHashAddrID: 0x9f, ScriptHashAddrID: 0xf9, - Bech32HRPSegwit: "tc", HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04}, HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08}, } @@ -43,12 +41,11 @@ func TestRegister(t *testing.T) { } tests := []struct { - name string - register []registerTest - p2pkhMagics []magicTest - p2shMagics []magicTest - segwitPrefixes []prefixTest - hdMagics []hdTest + name string + register []registerTest + p2pkhMagics []magicTest + p2shMagics []magicTest + hdMagics []hdTest }{ { name: "default networks", @@ -126,44 +123,6 @@ func TestRegister(t *testing.T) { 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{ { priv: MainNetParams.HDPrivateKeyID[:], @@ -260,44 +219,6 @@ func TestRegister(t *testing.T) { 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{ { priv: mockNetParams.HDPrivateKeyID[:], @@ -387,44 +308,6 @@ func TestRegister(t *testing.T) { 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{ { priv: MainNetParams.HDPrivateKeyID[:], @@ -485,13 +368,6 @@ func TestRegister(t *testing.T) { 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 { pubKey, err := HDPrivateKeyToPublicKeyID(magTest.priv[:]) if !reflect.DeepEqual(err, magTest.err) {