mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
commit
0fa8f05646
@ -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
|
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/daglabs/btcd/chaincfg/chainhash"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// These variables are the chain proof-of-work limit parameters for each default
|
||||
@ -103,6 +104,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.
|
||||
@ -201,13 +253,14 @@ type Params struct {
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs bool
|
||||
|
||||
// Human-readable prefix for Bech32 encoded addresses
|
||||
Prefix Bech32Prefix
|
||||
|
||||
// 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
|
||||
@ -301,13 +354,14 @@ var MainNetParams = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: false,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagCoin,
|
||||
|
||||
// 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
|
||||
@ -377,14 +431,15 @@ var RegressionNetParams = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagReg,
|
||||
|
||||
// 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
|
||||
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
|
||||
@ -468,13 +523,14 @@ var TestNet3Params = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagTest,
|
||||
|
||||
// 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)
|
||||
@ -548,13 +604,14 @@ var SimNetParams = Params{
|
||||
// Mempool parameters
|
||||
RelayNonStdTxs: true,
|
||||
|
||||
// Human-readable part for Bech32 encoded addresses
|
||||
Prefix: DagSim,
|
||||
|
||||
// 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 ?
|
||||
@ -582,8 +639,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)
|
||||
)
|
||||
@ -607,8 +662,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
|
||||
@ -625,28 +678,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 {
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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