mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[DEV-13] Removed netID magic numbers.
This commit is contained in:
parent
d1bec5ced5
commit
6924403653
@ -121,8 +121,6 @@ var regressionNetParams = &chaincfg.Params{
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Address encoding magics
|
||||
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
|
||||
|
@ -209,8 +209,6 @@ type Params struct {
|
||||
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
|
||||
@ -312,8 +310,6 @@ var MainNetParams = Params{
|
||||
Bech32HRPSegwit: "bc", // always bc for main net
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x00, // starts with 0
|
||||
ScriptHashAddrID: 0x08, // starts with 8
|
||||
PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed)
|
||||
WitnessPubKeyHashAddrID: 0x06, // starts with p2
|
||||
WitnessScriptHashAddrID: 0x0A, // starts with 7Xh
|
||||
@ -391,9 +387,7 @@ var RegressionNetParams = Params{
|
||||
Bech32HRPSegwit: "bcrt", // always bcrt for reg test net
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x00, // starts with 0
|
||||
ScriptHashAddrID: 0x08, // starts with 8
|
||||
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
|
||||
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
|
||||
@ -485,8 +479,6 @@ var TestNet3Params = Params{
|
||||
Bech32HRPSegwit: "tb", // always tb for test net
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x00, // starts with 0
|
||||
ScriptHashAddrID: 0x08, // starts with 8
|
||||
WitnessPubKeyHashAddrID: 0x03, // starts with QW
|
||||
WitnessScriptHashAddrID: 0x28, // starts with T7n
|
||||
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
|
||||
@ -568,8 +560,6 @@ var SimNetParams = Params{
|
||||
Bech32HRPSegwit: "sb", // always sb for sim net
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x00, // starts with 0
|
||||
ScriptHashAddrID: 0x08, // starts with 8
|
||||
PrivateKeyID: 0x64, // starts with 4 (uncompressed) or F (compressed)
|
||||
WitnessPubKeyHashAddrID: 0x19, // starts with Gg
|
||||
WitnessScriptHashAddrID: 0x28, // starts with ?
|
||||
@ -597,8 +587,6 @@ 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)
|
||||
)
|
||||
@ -622,8 +610,6 @@ func Register(params *Params) error {
|
||||
return ErrDuplicateNet
|
||||
}
|
||||
registeredNets[params.Net] = struct{}{}
|
||||
pubKeyHashAddrIDs[params.PubKeyHashAddrID] = struct{}{}
|
||||
scriptHashAddrIDs[params.ScriptHashAddrID] = struct{}{}
|
||||
hdPrivToPubKeyIDs[params.HDPrivateKeyID] = params.HDPublicKeyID[:]
|
||||
|
||||
// A valid Bech32 encoded segwit address always has as prefix the
|
||||
@ -640,28 +626,6 @@ func mustRegister(params *Params) {
|
||||
}
|
||||
}
|
||||
|
||||
// IsPubKeyHashAddrID returns whether the id is an identifier known to prefix a
|
||||
// pay-to-pubkey-hash address on any default or registered network. This is
|
||||
// used when decoding an address string into a specific address type. It is up
|
||||
// to the caller to check both this and IsScriptHashAddrID and decide whether an
|
||||
// address is a pubkey hash address, script hash address, neither, or
|
||||
// undeterminable (if both return true).
|
||||
func IsPubKeyHashAddrID(id byte) bool {
|
||||
_, ok := pubKeyHashAddrIDs[id]
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsScriptHashAddrID returns whether the id is an identifier known to prefix a
|
||||
// pay-to-script-hash address on any default or registered network. This is
|
||||
// used when decoding an address string into a specific address type. It is up
|
||||
// to the caller to check both this and IsPubKeyHashAddrID and decide whether an
|
||||
// address is a pubkey hash address, script hash address, neither, or
|
||||
// undeterminable (if both return true).
|
||||
func IsScriptHashAddrID(id byte) bool {
|
||||
_, ok := scriptHashAddrIDs[id]
|
||||
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.
|
||||
|
@ -13,13 +13,11 @@ import (
|
||||
// network. This is necessary to test the registration of and
|
||||
// lookup of encoding magics from the network.
|
||||
var mockNetParams = Params{
|
||||
Name: "mocknet",
|
||||
Net: 1<<32 - 1,
|
||||
PubKeyHashAddrID: 0x9f,
|
||||
ScriptHashAddrID: 0xf9,
|
||||
Bech32HRPSegwit: "tc",
|
||||
HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04},
|
||||
HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08},
|
||||
Name: "mocknet",
|
||||
Net: 1<<32 - 1,
|
||||
Bech32HRPSegwit: "tc",
|
||||
HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04},
|
||||
HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08},
|
||||
}
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
@ -28,10 +26,6 @@ func TestRegister(t *testing.T) {
|
||||
params *Params
|
||||
err error
|
||||
}
|
||||
type magicTest struct {
|
||||
magic byte
|
||||
valid bool
|
||||
}
|
||||
type prefixTest struct {
|
||||
prefix string
|
||||
valid bool
|
||||
@ -45,8 +39,6 @@ func TestRegister(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
register []registerTest
|
||||
p2pkhMagics []magicTest
|
||||
p2shMagics []magicTest
|
||||
segwitPrefixes []prefixTest
|
||||
hdMagics []hdTest
|
||||
}{
|
||||
@ -74,58 +66,6 @@ func TestRegister(t *testing.T) {
|
||||
err: ErrDuplicateNet,
|
||||
},
|
||||
},
|
||||
p2pkhMagics: []magicTest{
|
||||
{
|
||||
magic: MainNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: TestNet3Params.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: RegressionNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: SimNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: mockNetParams.PubKeyHashAddrID,
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
magic: 0xFF,
|
||||
valid: false,
|
||||
},
|
||||
},
|
||||
p2shMagics: []magicTest{
|
||||
{
|
||||
magic: MainNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: TestNet3Params.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: RegressionNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: SimNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: mockNetParams.ScriptHashAddrID,
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
magic: 0xFF,
|
||||
valid: false,
|
||||
},
|
||||
},
|
||||
segwitPrefixes: []prefixTest{
|
||||
{
|
||||
prefix: MainNetParams.Bech32HRPSegwit + "1",
|
||||
@ -208,58 +148,6 @@ func TestRegister(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
p2pkhMagics: []magicTest{
|
||||
{
|
||||
magic: MainNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: TestNet3Params.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: RegressionNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: SimNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: mockNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: 0xFF,
|
||||
valid: false,
|
||||
},
|
||||
},
|
||||
p2shMagics: []magicTest{
|
||||
{
|
||||
magic: MainNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: TestNet3Params.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: RegressionNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: SimNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: mockNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: 0xFF,
|
||||
valid: false,
|
||||
},
|
||||
},
|
||||
segwitPrefixes: []prefixTest{
|
||||
{
|
||||
prefix: MainNetParams.Bech32HRPSegwit + "1",
|
||||
@ -335,58 +223,6 @@ func TestRegister(t *testing.T) {
|
||||
err: ErrDuplicateNet,
|
||||
},
|
||||
},
|
||||
p2pkhMagics: []magicTest{
|
||||
{
|
||||
magic: MainNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: TestNet3Params.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: RegressionNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: SimNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: mockNetParams.PubKeyHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: 0xFF,
|
||||
valid: false,
|
||||
},
|
||||
},
|
||||
p2shMagics: []magicTest{
|
||||
{
|
||||
magic: MainNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: TestNet3Params.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: RegressionNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: SimNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: mockNetParams.ScriptHashAddrID,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
magic: 0xFF,
|
||||
valid: false,
|
||||
},
|
||||
},
|
||||
segwitPrefixes: []prefixTest{
|
||||
{
|
||||
prefix: MainNetParams.Bech32HRPSegwit + "1",
|
||||
@ -471,20 +307,6 @@ func TestRegister(t *testing.T) {
|
||||
test.name, regTest.name, err, regTest.err)
|
||||
}
|
||||
}
|
||||
for i, magTest := range test.p2pkhMagics {
|
||||
valid := IsPubKeyHashAddrID(magTest.magic)
|
||||
if valid != magTest.valid {
|
||||
t.Errorf("%s: P2PKH magic %d valid mismatch: got %v expected %v",
|
||||
test.name, i, valid, magTest.valid)
|
||||
}
|
||||
}
|
||||
for i, magTest := range test.p2shMagics {
|
||||
valid := IsScriptHashAddrID(magTest.magic)
|
||||
if valid != magTest.valid {
|
||||
t.Errorf("%s: P2SH magic %d valid mismatch: got %v expected %v",
|
||||
test.name, i, valid, magTest.valid)
|
||||
}
|
||||
}
|
||||
for i, prxTest := range test.segwitPrefixes {
|
||||
valid := IsBech32SegwitPrefix(prxTest.prefix)
|
||||
if valid != prxTest.valid {
|
||||
|
@ -133,7 +133,7 @@ func newMemWallet(net *chaincfg.Params, harnessID uint32) (*memWallet, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
coinbaseAddr, err := keyToAddr(coinbaseKey, net)
|
||||
coinbaseAddr, err := keyToAddr(coinbaseKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -346,7 +346,7 @@ func (m *memWallet) newAddress() (btcutil.Address, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
addr, err := keyToAddr(privKey, m.net)
|
||||
addr, err := keyToAddr(privKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -560,9 +560,9 @@ func (m *memWallet) ConfirmedBalance() btcutil.Amount {
|
||||
}
|
||||
|
||||
// keyToAddr maps the passed private to corresponding p2pkh address.
|
||||
func keyToAddr(key *btcec.PrivateKey, net *chaincfg.Params) (btcutil.Address, error) {
|
||||
func keyToAddr(key *btcec.PrivateKey) (btcutil.Address, error) {
|
||||
serializedKey := key.PubKey().SerializeCompressed()
|
||||
pubKeyAddr, err := btcutil.NewAddressPubKey(serializedKey, net)
|
||||
pubKeyAddr, err := btcutil.NewAddressPubKey(serializedKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp
|
||||
// Generate associated pay-to-script-hash address and resulting payment
|
||||
// script.
|
||||
pubKeyBytes := signPub.SerializeCompressed()
|
||||
payPubKeyAddr, err := btcutil.NewAddressPubKey(pubKeyBytes, chainParams)
|
||||
payPubKeyAddr, err := btcutil.NewAddressPubKey(pubKeyBytes)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
18
rpcserver.go
18
rpcserver.go
@ -333,15 +333,15 @@ type gbtWorkState struct {
|
||||
prevHash *chainhash.Hash
|
||||
minTimestamp time.Time
|
||||
template *mining.BlockTemplate
|
||||
notifyMap map[chainhash.Hash]map[int64]chan struct{}
|
||||
timeSource blockchain.MedianTimeSource
|
||||
notifyMap map[chainhash.Hash]map[int64]chan struct{}
|
||||
timeSource blockchain.MedianTimeSource
|
||||
}
|
||||
|
||||
// newGbtWorkState returns a new instance of a gbtWorkState with all internal
|
||||
// fields initialized and ready to use.
|
||||
func newGbtWorkState(timeSource blockchain.MedianTimeSource) *gbtWorkState {
|
||||
return &gbtWorkState{
|
||||
notifyMap: make(map[chainhash.Hash]map[int64]chan struct{}),
|
||||
notifyMap: make(map[chainhash.Hash]map[int64]chan struct{}),
|
||||
timeSource: timeSource,
|
||||
}
|
||||
}
|
||||
@ -1549,7 +1549,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
|
||||
if template == nil || state.prevHash == nil ||
|
||||
!state.prevHash.IsEqual(latestHash) ||
|
||||
(state.lastTxUpdate != lastTxUpdate &&
|
||||
time.Now().After(state.lastGenerated.Add(time.Second*
|
||||
time.Now().After(state.lastGenerated.Add(time.Second *
|
||||
gbtRegenerateSeconds))) {
|
||||
|
||||
// Reset the previous best hash the block template was generated
|
||||
@ -1573,7 +1573,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
|
||||
blkTemplate, err := generator.NewBlockTemplate(payAddr)
|
||||
if err != nil {
|
||||
return internalRPCError("Failed to create new block "+
|
||||
"template: "+err.Error(), "")
|
||||
"template: "+ err.Error(), "")
|
||||
}
|
||||
template = blkTemplate
|
||||
msgBlock = template.Block
|
||||
@ -1870,7 +1870,7 @@ func handleGetBlockTemplateLongPoll(s *rpcServer, longPollID string, useCoinbase
|
||||
case <-closeChan:
|
||||
return nil, ErrClientQuit
|
||||
|
||||
// Wait until signal received to send the reply.
|
||||
// Wait until signal received to send the reply.
|
||||
case <-longPollChan:
|
||||
// Fallthrough
|
||||
}
|
||||
@ -2804,7 +2804,7 @@ func handlePing(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (inter
|
||||
nonce, err := wire.RandomUint64()
|
||||
if err != nil {
|
||||
return nil, internalRPCError("Not sending ping - failed to "+
|
||||
"generate nonce: "+err.Error(), "")
|
||||
"generate nonce: "+ err.Error(), "")
|
||||
}
|
||||
s.cfg.ConnMgr.BroadcastMessage(wire.NewMsgPing(nonce))
|
||||
|
||||
@ -3576,7 +3576,7 @@ func handleVerifyMessage(s *rpcServer, cmd interface{}, closeChan <-chan struct{
|
||||
} else {
|
||||
serializedPK = pk.SerializeUncompressed()
|
||||
}
|
||||
address, err := btcutil.NewAddressPubKey(serializedPK, params)
|
||||
address, err := btcutil.NewAddressPubKey(serializedPK)
|
||||
if err != nil {
|
||||
// Again mirror Bitcoin Core behavior, which treats error in public key
|
||||
// reconstruction as invalid signature.
|
||||
@ -4281,7 +4281,7 @@ func newRPCServer(config *rpcserverConfig) (*rpcServer, error) {
|
||||
gbtWorkState: newGbtWorkState(config.TimeSource),
|
||||
helpCacher: newHelpCacher(),
|
||||
requestProcessShutdown: make(chan struct{}),
|
||||
quit: make(chan int),
|
||||
quit: make(chan int),
|
||||
}
|
||||
if cfg.RPCUser != "" && cfg.RPCPass != "" {
|
||||
login := cfg.RPCUser + ":" + cfg.RPCPass
|
||||
|
@ -351,8 +351,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -390,8 +389,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -451,8 +449,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -490,8 +487,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -831,8 +827,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -888,8 +883,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeUncompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -969,8 +963,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -1025,8 +1018,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk := (*btcec.PublicKey)(&key.PublicKey).
|
||||
SerializeCompressed()
|
||||
address, err := btcutil.NewAddressPubKey(pk,
|
||||
&chaincfg.TestNet3Params)
|
||||
address, err := btcutil.NewAddressPubKey(pk)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -1106,8 +1098,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk1 := (*btcec.PublicKey)(&key1.PublicKey).
|
||||
SerializeCompressed()
|
||||
address1, err := btcutil.NewAddressPubKey(pk1,
|
||||
&chaincfg.TestNet3Params)
|
||||
address1, err := btcutil.NewAddressPubKey(pk1)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -1123,8 +1114,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk2 := (*btcec.PublicKey)(&key2.PublicKey).
|
||||
SerializeCompressed()
|
||||
address2, err := btcutil.NewAddressPubKey(pk2,
|
||||
&chaincfg.TestNet3Params)
|
||||
address2, err := btcutil.NewAddressPubKey(pk2)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address 2 for %s: %v",
|
||||
msg, err)
|
||||
@ -1182,8 +1172,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk1 := (*btcec.PublicKey)(&key1.PublicKey).
|
||||
SerializeCompressed()
|
||||
address1, err := btcutil.NewAddressPubKey(pk1,
|
||||
&chaincfg.TestNet3Params)
|
||||
address1, err := btcutil.NewAddressPubKey(pk1)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -1199,8 +1188,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk2 := (*btcec.PublicKey)(&key2.PublicKey).
|
||||
SerializeCompressed()
|
||||
address2, err := btcutil.NewAddressPubKey(pk2,
|
||||
&chaincfg.TestNet3Params)
|
||||
address2, err := btcutil.NewAddressPubKey(pk2)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address 2 for %s: %v",
|
||||
msg, err)
|
||||
@ -1288,8 +1276,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk1 := (*btcec.PublicKey)(&key1.PublicKey).
|
||||
SerializeCompressed()
|
||||
address1, err := btcutil.NewAddressPubKey(pk1,
|
||||
&chaincfg.TestNet3Params)
|
||||
address1, err := btcutil.NewAddressPubKey(pk1)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address for %s: %v",
|
||||
msg, err)
|
||||
@ -1305,8 +1292,7 @@ func TestSignTxOutput(t *testing.T) {
|
||||
|
||||
pk2 := (*btcec.PublicKey)(&key2.PublicKey).
|
||||
SerializeCompressed()
|
||||
address2, err := btcutil.NewAddressPubKey(pk2,
|
||||
&chaincfg.TestNet3Params)
|
||||
address2, err := btcutil.NewAddressPubKey(pk2)
|
||||
if err != nil {
|
||||
t.Errorf("failed to make address 2 for %s: %v",
|
||||
msg, err)
|
||||
|
@ -300,15 +300,15 @@ func CalcScriptInfo(sigScript, pkScript []byte, witness wire.TxWitness,
|
||||
// will fail).
|
||||
si.NumInputs = len(sigPops)
|
||||
|
||||
// If segwit is active, and this is a regular p2wkh output, then we'll
|
||||
// treat the script as a p2pkh output in essence.
|
||||
// If segwit is active, and this is a regular p2wkh output, then we'll
|
||||
// treat the script as a p2pkh output in essence.
|
||||
case si.PkScriptClass == WitnessV0PubKeyHashTy && segwit:
|
||||
|
||||
si.SigOps = GetWitnessSigOpCount(sigScript, pkScript, witness)
|
||||
si.NumInputs = len(witness)
|
||||
|
||||
// We'll attempt to detect the nested p2sh case so we can accurately
|
||||
// count the signature operations involved.
|
||||
// We'll attempt to detect the nested p2sh case so we can accurately
|
||||
// count the signature operations involved.
|
||||
case si.PkScriptClass == ScriptHashTy &&
|
||||
IsWitnessProgram(sigScript[1:]) && bip16 && segwit:
|
||||
|
||||
@ -327,8 +327,8 @@ func CalcScriptInfo(sigScript, pkScript []byte, witness wire.TxWitness,
|
||||
si.NumInputs = len(witness)
|
||||
si.NumInputs += len(sigPops)
|
||||
|
||||
// If segwit is active, and this is a p2wsh output, then we'll need to
|
||||
// examine the witness script to generate accurate script info.
|
||||
// If segwit is active, and this is a p2wsh output, then we'll need to
|
||||
// examine the witness script to generate accurate script info.
|
||||
case si.PkScriptClass == WitnessV0ScriptHashTy && segwit:
|
||||
// The witness script is the final element of the witness
|
||||
// stack.
|
||||
@ -564,7 +564,7 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
|
||||
// Therefore the pubkey is the first item on the stack.
|
||||
// Skip the pubkey if it's invalid for some reason.
|
||||
requiredSigs = 1
|
||||
addr, err := btcutil.NewAddressPubKey(pops[0].data, chainParams)
|
||||
addr, err := btcutil.NewAddressPubKey(pops[0].data)
|
||||
if err == nil {
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
@ -605,8 +605,7 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
|
||||
// Extract the public keys while skipping any that are invalid.
|
||||
addrs = make([]btcutil.Address, 0, numPubKeys)
|
||||
for i := 0; i < numPubKeys; i++ {
|
||||
addr, err := btcutil.NewAddressPubKey(pops[i+1].data,
|
||||
chainParams)
|
||||
addr, err := btcutil.NewAddressPubKey(pops[i+1].data)
|
||||
if err == nil {
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
|
@ -34,8 +34,7 @@ func mustParseShortForm(script string) []byte {
|
||||
// the tests as a helper since the only way it can fail is if there is an error
|
||||
// in the test source code.
|
||||
func newAddressPubKey(serializedPubKey []byte) btcutil.Address {
|
||||
addr, err := btcutil.NewAddressPubKey(serializedPubKey,
|
||||
&chaincfg.MainNetParams)
|
||||
addr, err := btcutil.NewAddressPubKey(serializedPubKey)
|
||||
if err != nil {
|
||||
panic("invalid public key in test source")
|
||||
}
|
||||
@ -613,15 +612,13 @@ func TestPayToAddrScript(t *testing.T) {
|
||||
|
||||
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg
|
||||
p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d"+
|
||||
"74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"),
|
||||
&chaincfg.MainNetParams)
|
||||
"74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed): %v",
|
||||
err)
|
||||
}
|
||||
p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b"+
|
||||
"d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"),
|
||||
&chaincfg.MainNetParams)
|
||||
"d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed 2): %v",
|
||||
err)
|
||||
@ -630,7 +627,7 @@ func TestPayToAddrScript(t *testing.T) {
|
||||
p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411"+
|
||||
"db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5"+
|
||||
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4"+
|
||||
"12a3"), &chaincfg.MainNetParams)
|
||||
"12a3"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (uncompressed): %v",
|
||||
err)
|
||||
@ -717,15 +714,13 @@ func TestMultiSigScript(t *testing.T) {
|
||||
|
||||
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg
|
||||
p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d"+
|
||||
"74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"),
|
||||
&chaincfg.MainNetParams)
|
||||
"74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed): %v",
|
||||
err)
|
||||
}
|
||||
p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b"+
|
||||
"d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"),
|
||||
&chaincfg.MainNetParams)
|
||||
"d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed 2): %v",
|
||||
err)
|
||||
@ -734,7 +729,7 @@ func TestMultiSigScript(t *testing.T) {
|
||||
p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411"+
|
||||
"db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5"+
|
||||
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4"+
|
||||
"12a3"), &chaincfg.MainNetParams)
|
||||
"12a3"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (uncompressed): %v",
|
||||
err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user