Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package assets

import (
"fmt"
"math"
"math/big"

"github.com/bisoncraft/utxowallet/netparams"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
)

func NetParams(chain, net string) (p *netparams.ChainParams, _ error) {
func NetParams(chain, net string) (p *netparams.ChainParams, err error) {
switch chain {
case "btc":
p = BTCParams[net]
Expand All @@ -18,6 +20,9 @@ func NetParams(chain, net string) (p *netparams.ChainParams, _ error) {
if p == nil {
return nil, fmt.Errorf("no net params for chain %s, network %s", chain, net)
}
registerParams := *p.BTCDParams() // populate the internal btcParams field
registerParams.Net = math.MaxUint32
err = chaincfg.Register(&registerParams)
return
}

Expand Down
23 changes: 23 additions & 0 deletions assets/assets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package assets

import "testing"

func TestParams(t *testing.T) {
for chain, nets := range map[string][]string{
"btc": {"mainnet", "testnet", "simnet"},
"ltc": {"mainnet", "testnet", "simnet"},
} {
for _, net := range nets {
t.Run(chain+"."+net, func(t *testing.T) {
chainParams, _ := NetParams(chain, net)
h := chainParams.GenesisBlock.BlockHash()
if h != *chainParams.GenesisHash {
t.Fatalf("Genesis hash mismatch")
}
if chainParams.Chain != chain {
t.Fatalf("Wrong chain. %s != %s", chainParams.Chain, chain)
}
})
}
}
}
32 changes: 25 additions & 7 deletions assets/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var genesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet

var BTCParams = map[string]*netparams.ChainParams{
"mainnet": {
Chain: "btc",
Name: "mainnet",
Net: wire.MainNet,
DefaultPort: "8333",
Expand Down Expand Up @@ -95,9 +96,12 @@ var BTCParams = map[string]*netparams.ChainParams{
0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
}),
PowLimit: new(big.Int).Sub(new(big.Int).Lsh(bigOne, 224), bigOne),
PowLimitBits: 0x1d00ffff,
TargetTimespan: time.Hour * 24 * 14, // 14 days
TargetTimePerBlock: time.Minute * 10, // 10 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: false,
MinDiffReductionTime: 0,

// Checkpoints ordered from oldest to newest.
Checkpoints: []chaincfg.Checkpoint{
Expand Down Expand Up @@ -144,14 +148,17 @@ var BTCParams = map[string]*netparams.ChainParams{
WitnessPubKeyHashAddrID: 0x06, // starts with p2
WitnessScriptHashAddrID: 0x0A, // starts with 7Xh
// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv
HDPublicKeyID: [4]byte{0x04, 0x88, 0xb2, 0x1e}, // starts with xpub
HDCoinType: 0,
BIP0034Height: 227931, // 000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8
BIP0065Height: 388381, // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
BIP0066Height: 363725, // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv
HDPublicKeyID: [4]byte{0x04, 0x88, 0xb2, 0x1e}, // starts with xpub
HDCoinType: 0,
BIP0034Height: 227931, // 000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8
BIP0065Height: 388381, // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
BIP0066Height: 363725, // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
CoinbaseMaturity: 100,
MaxSatoshi: btcutil.MaxSatoshi,
},
"testnet": {
Chain: "btc",
Name: "testnet3",
Net: wire.TestNet3,
DefaultPort: "18333",
Expand Down Expand Up @@ -219,9 +226,12 @@ var BTCParams = map[string]*netparams.ChainParams{
0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00,
}),
PowLimit: new(big.Int).Sub(new(big.Int).Lsh(bigOne, 224), bigOne),
PowLimitBits: 0x1d00ffff,
TargetTimespan: time.Hour * 24 * 14, // 14 days
TargetTimePerBlock: time.Minute * 10, // 10 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: true,
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2

// Checkpoints ordered from oldest to newest.
Checkpoints: []chaincfg.Checkpoint{
Expand Down Expand Up @@ -261,11 +271,14 @@ var BTCParams = map[string]*netparams.ChainParams{
BIP0034Height: 21111, // 0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8
BIP0065Height: 581885, // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
BIP0066Height: 330776, // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
CoinbaseMaturity: 100,
MaxSatoshi: btcutil.MaxSatoshi,
},
"simnet": {
Chain: "btc",
Name: "regtest",
Net: wire.TestNet,
DefaultPort: "18444",
DefaultPort: "20575", // 18444 // Changed to match dcrdex testing harness
DNSSeeds: []chaincfg.DNSSeed{},
GenesisBlock: &wire.MsgBlock{
Header: wire.BlockHeader{
Expand Down Expand Up @@ -325,9 +338,13 @@ var BTCParams = map[string]*netparams.ChainParams{
0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f,
}),
PowLimit: new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne),
PowLimitBits: 0x207fffff,
PoWNoRetargeting: true,
TargetTimespan: time.Hour * 24 * 14, // 14 days
TargetTimePerBlock: time.Minute * 10, // 10 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: true,
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
Checkpoints: nil,
Bech32HRPSegwit: "bcrt", // always bcrt for reg test net
PubKeyHashAddrID: 0x6f, // starts with m or n
Expand All @@ -339,6 +356,7 @@ var BTCParams = map[string]*netparams.ChainParams{
BIP0034Height: 100000000, // Not active - Permit ver 1 blocks
BIP0065Height: 1351, // Used by regression tests
BIP0066Height: 1251, // Used by regression tests
CoinbaseMaturity: 100,
MaxSatoshi: btcutil.MaxSatoshi,
},
}
Loading