mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Merge remote-tracking branch 'origin/master' into remove-segwit
This commit is contained in:
commit
e14712c99e
28
Gopkg.lock
generated
28
Gopkg.lock
generated
@ -1,12 +1,6 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/aead/siphash"
|
||||
packages = ["."]
|
||||
revision = "e404fcfc888570cadd1610538e2dbc89f66af814"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/btcsuite/btclog"
|
||||
@ -62,20 +56,6 @@
|
||||
revision = "f8fb11f83f7e860e3769a08e6811d1b399a43722"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/daglabs/btcutil"
|
||||
packages = [
|
||||
".",
|
||||
"base58",
|
||||
"bech32",
|
||||
"bloom",
|
||||
"gcs",
|
||||
"gcs/builder",
|
||||
"hdkeychain"
|
||||
]
|
||||
revision = "b4e6eb624c3db8fb260f6ce2200a4a135c466652"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
@ -94,12 +74,6 @@
|
||||
revision = "a93b200c26cbae3bb09dd0dc2c7c7fe1468a034a"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kkdai/bstream"
|
||||
packages = ["."]
|
||||
revision = "f71540b9dfdcfe64dbf2818e9b66423c6aafcacd"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
@ -109,6 +83,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "939184fbaca652ccb2ada55cbf06b46a2e8aae3bc73d59206748889013761f19"
|
||||
inputs-digest = "f6928f9045d39e392385664563e9e2ebad733056d5a2d28747dfbfbe19aa6ad2"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
@ -4,7 +4,6 @@
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
@ -24,6 +23,7 @@
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
ignored = ["github.com/daglabs/btcutil*"]
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
@ -45,10 +45,6 @@
|
||||
name = "github.com/btcsuite/winsvc"
|
||||
version = "1.0.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/daglabs/btcutil"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
version = "1.1.0"
|
||||
|
@ -35,4 +35,4 @@ periodically purge peers which no longer appear to be good peers as well as
|
||||
bias the selection toward known good peers. The general idea is to make a best
|
||||
effort at only providing usable addresses.
|
||||
*/
|
||||
package addrmgr
|
||||
package addrmgr
|
@ -78,4 +78,4 @@ This package includes spec changes outlined by the following BIPs:
|
||||
BIP0030 (https://en.bitcoin.it/wiki/BIP_0030)
|
||||
BIP0034 (https://en.bitcoin.it/wiki/BIP_0034)
|
||||
*/
|
||||
package blockchain
|
||||
package blockchain
|
@ -17,4 +17,4 @@ This package has intentionally been designed so it can be used as a standalone
|
||||
package for any projects needing to test their implementation against a full set
|
||||
of blocks that exercise the consensus validation rules.
|
||||
*/
|
||||
package fullblocktests
|
||||
package fullblocktests
|
@ -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
|
||||
|
@ -18,4 +18,4 @@ standard formats. It was designed for use with btcd, but should be
|
||||
general enough for other uses of elliptic curve crypto. It was originally based
|
||||
on some initial work by ThePiachu, but has significantly diverged since then.
|
||||
*/
|
||||
package btcec
|
||||
package btcec
|
@ -143,4 +143,4 @@ The second category of errors (type RPCError), on the other hand, are useful for
|
||||
returning errors to RPC clients. Consequently, they are used in the previously
|
||||
described Response type.
|
||||
*/
|
||||
package btcjson
|
||||
package btcjson
|
@ -58,4 +58,4 @@
|
||||
// non-standard network. As a general rule of thumb, all network parameters
|
||||
// should be unique to the network, but parameter collisions can still occur
|
||||
// (unfortunately, this is the case with regtest and testnet3 sharing magics).
|
||||
package chaincfg
|
||||
package chaincfg
|
@ -10,6 +10,8 @@ import (
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/daglabs/btcd/chaincfg/chainhash"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
)
|
||||
@ -97,6 +99,57 @@ const (
|
||||
DefinedDeployments
|
||||
)
|
||||
|
||||
// Bech32Prefix is the human-readable prefix for a Bech32 address.
|
||||
type Bech32Prefix int
|
||||
|
||||
// Constants that define Bech32 address prefixes. Every network is assigned
|
||||
// a unique prefix.
|
||||
const (
|
||||
// Unknown/Erroneous prefix
|
||||
Unknown Bech32Prefix = iota
|
||||
|
||||
// Prefix for the main network.
|
||||
DagCoin
|
||||
|
||||
// Prefix for the regression test network.
|
||||
DagReg
|
||||
|
||||
// Prefix for the test network.
|
||||
DagTest
|
||||
|
||||
// Prefix for the simulation network.
|
||||
DagSim
|
||||
)
|
||||
|
||||
// Map from strings to Bech32 address prefix constants for parsing purposes.
|
||||
var stringsToBech32Prefixes = map[string]Bech32Prefix{
|
||||
"dagcoin": DagCoin,
|
||||
"dagreg": DagReg,
|
||||
"dagtest": DagTest,
|
||||
"dagsim": DagSim,
|
||||
}
|
||||
|
||||
// ParsePrefix attempts to parse a Bech32 address prefix.
|
||||
func ParsePrefix(prefixString string) (Bech32Prefix, error) {
|
||||
prefix, ok := stringsToBech32Prefixes[prefixString]
|
||||
if !ok {
|
||||
return Unknown, fmt.Errorf("could not parse prefix %v", prefixString)
|
||||
}
|
||||
|
||||
return prefix, nil
|
||||
}
|
||||
|
||||
// Converts from Bech32 address prefixes to their string values
|
||||
func (prefix Bech32Prefix) String() string {
|
||||
for key, value := range stringsToBech32Prefixes {
|
||||
if prefix == value {
|
||||
return key
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Params defines a Bitcoin network by its parameters. These parameters may be
|
||||
// used by Bitcoin applications to differentiate networks as well as addresses
|
||||
// and keys for one network from those intended for use on another network.
|
||||
@ -195,10 +248,11 @@ type Params struct {
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs bool
|
||||
|
||||
// Human-readable prefix for Bech32 encoded addresses
|
||||
Prefix Bech32Prefix
|
||||
|
||||
// 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
|
||||
PrivateKeyID byte // First byte of a WIF private key
|
||||
|
||||
// BIP32 hierarchical deterministic extended key magics
|
||||
HDPrivateKeyID [4]byte
|
||||
@ -284,10 +338,11 @@ var MainNetParams = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: false,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagCoin,
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x00, // starts with 1
|
||||
ScriptHashAddrID: 0x05, // starts with 3
|
||||
PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed)
|
||||
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
|
||||
@ -349,10 +404,11 @@ var RegressionNetParams = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagReg,
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x6f, // starts with m or n
|
||||
ScriptHashAddrID: 0xc4, // starts with 2
|
||||
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
|
||||
@ -431,10 +487,11 @@ var TestNet3Params = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagTest,
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x6f, // starts with m or n
|
||||
ScriptHashAddrID: 0xc4, // starts with 2
|
||||
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
|
||||
@ -500,10 +557,9 @@ var SimNetParams = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Address encoding magics
|
||||
PubKeyHashAddrID: 0x3f, // 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)
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagSim,
|
||||
|
||||
// BIP32 hierarchical deterministic extended key magics
|
||||
HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00}, // starts with sprv
|
||||
@ -528,8 +584,6 @@ var (
|
||||
|
||||
var (
|
||||
registeredNets = make(map[wire.BitcoinNet]struct{})
|
||||
pubKeyHashAddrIDs = make(map[byte]struct{})
|
||||
scriptHashAddrIDs = make(map[byte]struct{})
|
||||
hdPrivToPubKeyIDs = make(map[[4]byte][]byte)
|
||||
)
|
||||
|
||||
@ -552,8 +606,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[:]
|
||||
|
||||
return nil
|
||||
@ -567,28 +619,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
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
@ -12,12 +12,10 @@ 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,
|
||||
HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04},
|
||||
HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08},
|
||||
Name: "mocknet",
|
||||
Net: 1<<32 - 1,
|
||||
HDPrivateKeyID: [4]byte{0x01, 0x02, 0x03, 0x04},
|
||||
HDPublicKeyID: [4]byte{0x05, 0x06, 0x07, 0x08},
|
||||
}
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
@ -26,10 +24,6 @@ func TestRegister(t *testing.T) {
|
||||
params *Params
|
||||
err error
|
||||
}
|
||||
type magicTest struct {
|
||||
magic byte
|
||||
valid bool
|
||||
}
|
||||
type prefixTest struct {
|
||||
prefix string
|
||||
valid bool
|
||||
@ -41,11 +35,9 @@ func TestRegister(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
register []registerTest
|
||||
p2pkhMagics []magicTest
|
||||
p2shMagics []magicTest
|
||||
hdMagics []hdTest
|
||||
name string
|
||||
register []registerTest
|
||||
hdMagics []hdTest
|
||||
}{
|
||||
{
|
||||
name: "default networks",
|
||||
@ -71,58 +63,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,
|
||||
},
|
||||
},
|
||||
hdMagics: []hdTest{
|
||||
{
|
||||
priv: MainNetParams.HDPrivateKeyID[:],
|
||||
@ -167,58 +107,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,
|
||||
},
|
||||
},
|
||||
hdMagics: []hdTest{
|
||||
{
|
||||
priv: mockNetParams.HDPrivateKeyID[:],
|
||||
@ -256,58 +144,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,
|
||||
},
|
||||
},
|
||||
hdMagics: []hdTest{
|
||||
{
|
||||
priv: MainNetParams.HDPrivateKeyID[:],
|
||||
@ -354,20 +190,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, magTest := range test.hdMagics {
|
||||
pubKey, err := HDPrivateKeyToPublicKeyID(magTest.priv[:])
|
||||
if !reflect.DeepEqual(err, magTest.err) {
|
||||
|
@ -11,4 +11,4 @@ Connection Manager handles all the general connection concerns such as
|
||||
maintaining a set number of outbound connections, sourcing peers, banning,
|
||||
limiting max connections, tor lookup, etc.
|
||||
*/
|
||||
package connmgr
|
||||
package connmgr
|
@ -88,4 +88,4 @@ provide the ability to create an arbitrary number of nested buckets. It is
|
||||
a good idea to avoid a lot of buckets with little data in them as it could lead
|
||||
to poor page utilization depending on the specific driver in use.
|
||||
*/
|
||||
package database
|
||||
package database
|
@ -26,4 +26,4 @@ database path as a string and the block network:
|
||||
// Handle error
|
||||
}
|
||||
*/
|
||||
package ffldb
|
||||
package ffldb
|
@ -24,4 +24,4 @@ since the treap it points to is immutable. This effectively provides O(1)
|
||||
snapshot capability with efficient memory usage characteristics since the old
|
||||
nodes only remain allocated until there are no longer any references to them.
|
||||
*/
|
||||
package treap
|
||||
package treap
|
@ -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
|
||||
}
|
||||
|
@ -78,4 +78,4 @@ violations through type assertions. In addition, callers can programmatically
|
||||
determine the specific rule violation by type asserting the Err field to one of
|
||||
the aforementioned types and examining their underlying ErrorCode field.
|
||||
*/
|
||||
package mempool
|
||||
package mempool
|
@ -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
|
||||
}
|
||||
|
@ -10,4 +10,4 @@ new blocks connected to the chain. Currently the sync manager selects a single
|
||||
sync peer that it downloads all blocks from until it is up to date with the
|
||||
longest chain the sync peer is aware of.
|
||||
*/
|
||||
package netsync
|
||||
package netsync
|
@ -147,4 +147,4 @@ Bitcoin Improvement Proposals
|
||||
This package supports all BIPS supported by the wire package.
|
||||
(https://godoc.org/github.com/daglabs/btcd/wire#hdr-Bitcoin_Improvement_Proposals)
|
||||
*/
|
||||
package peer
|
||||
package peer
|
@ -175,4 +175,4 @@ The following full-blown client examples are in the examples directory:
|
||||
for notifications about changes to account balances, and gets a list of
|
||||
unspent transaction outputs (utxos) the wallet can sign
|
||||
*/
|
||||
package rpcclient
|
||||
package rpcclient
|
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,
|
||||
}
|
||||
}
|
||||
@ -1521,7 +1521,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
|
||||
@ -1545,7 +1545,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
|
||||
@ -1834,7 +1834,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
|
||||
}
|
||||
@ -2759,7 +2759,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))
|
||||
|
||||
@ -3527,7 +3527,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.
|
||||
@ -4232,7 +4232,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
|
||||
|
@ -39,4 +39,4 @@ error messages with contextual information. A convenience function named
|
||||
IsErrorCode is also provided to allow callers to easily check for a specific
|
||||
error code. See ErrorCode in the package documentation for a full list.
|
||||
*/
|
||||
package txscript
|
||||
package txscript
|
@ -24,7 +24,7 @@ func ExamplePayToAddrScript() {
|
||||
// which is useful to ensure the accuracy of the address and determine
|
||||
// the address type. It is also required for the upcoming call to
|
||||
// PayToAddrScript.
|
||||
addressStr := "12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV"
|
||||
addressStr := "dagcoin:qqfgqp8l9l90zwetj84k2jcac2m8falvvy9uastr55"
|
||||
address, err := btcutil.DecodeAddress(addressStr, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@ -75,7 +75,7 @@ func ExampleExtractPkScriptAddrs() {
|
||||
|
||||
// Output:
|
||||
// Script Class: pubkeyhash
|
||||
// Addresses: [12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV]
|
||||
// Addresses: [dagcoin:qqfgqp8l9l90zwetj84k2jcac2m8falvvy9uastr55]
|
||||
// Required Signatures: 1
|
||||
}
|
||||
|
||||
|
@ -348,8 +348,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)
|
||||
@ -386,8 +385,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)
|
||||
@ -447,8 +445,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)
|
||||
@ -485,8 +482,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)
|
||||
@ -821,8 +817,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)
|
||||
@ -877,8 +872,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)
|
||||
@ -957,8 +951,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)
|
||||
@ -1012,8 +1005,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)
|
||||
@ -1092,8 +1084,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)
|
||||
@ -1109,8 +1100,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)
|
||||
@ -1167,8 +1157,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)
|
||||
@ -1184,8 +1173,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)
|
||||
@ -1271,8 +1259,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)
|
||||
@ -1288,8 +1275,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)
|
||||
|
@ -452,7 +452,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)
|
||||
}
|
||||
@ -481,8 +481,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)
|
||||
}
|
||||
|
@ -32,8 +32,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")
|
||||
}
|
||||
@ -531,15 +530,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)
|
||||
@ -548,7 +545,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)
|
||||
@ -635,15 +632,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)
|
||||
@ -652,7 +647,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)
|
||||
|
@ -159,4 +159,4 @@ This package includes spec changes outlined by the following BIPs:
|
||||
BIP0130 (https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki)
|
||||
BIP0133 (https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki)
|
||||
*/
|
||||
package wire
|
||||
package wire
|
Loading…
x
Reference in New Issue
Block a user