github.com/palcoin-project/palcd@v1.0.0/chaincfg/params.go (about) 1 // Copyright (c) 2014-2016 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package chaincfg 6 7 import ( 8 "encoding/binary" 9 "encoding/hex" 10 "errors" 11 "math" 12 "math/big" 13 "strings" 14 "time" 15 16 "github.com/palcoin-project/palcd/chaincfg/chainhash" 17 "github.com/palcoin-project/palcd/wire" 18 ) 19 20 // These variables are the chain proof-of-work limit parameters for each default 21 // network. 22 var ( 23 // bigOne is 1 represented as a big.Int. It is defined here to avoid 24 // the overhead of creating it multiple times. 25 bigOne = big.NewInt(1) 26 27 // mainPowLimit is the highest proof of work value a Bitcoin block can 28 // have for the main network. It is the value 2^224 - 1. 29 mainPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 245), bigOne) 30 31 // regressionPowLimit is the highest proof of work value a Bitcoin block 32 // can have for the regression test network. It is the value 2^255 - 1. 33 regressionPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne) 34 35 // testNet3PowLimit is the highest proof of work value a Bitcoin block 36 // can have for the test network (version 3). It is the value 37 // 2^224 - 1. 38 testNet3PowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 224), bigOne) 39 40 // simNetPowLimit is the highest proof of work value a Bitcoin block 41 // can have for the simulation test network. It is the value 2^255 - 1. 42 simNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne) 43 44 // sigNetPowLimit is the highest proof of work value a bitcoin block can 45 // have for the signet test network. It is the value 0x0377ae << 216. 46 sigNetPowLimit = new(big.Int).Lsh(new(big.Int).SetInt64(0x0377ae), 216) 47 48 // DefaultSignetChallenge is the byte representation of the signet 49 // challenge for the default (public, Taproot enabled) signet network. 50 // This is the binary equivalent of the bitcoin script 51 // 1 03ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430 52 // 0359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c4 2 53 // OP_CHECKMULTISIG 54 DefaultSignetChallenge, _ = hex.DecodeString( 55 "512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d" + 56 "1e086be430210359ef5021964fe22d6f8e05b2463c9540ce9688" + 57 "3fe3b278760f048f5189f2e6c452ae", 58 ) 59 60 // DefaultSignetDNSSeeds is the list of seed nodes for the default 61 // (public, Taproot enabled) signet network. 62 DefaultSignetDNSSeeds = []DNSSeed{ 63 {"178.128.221.177", false}, 64 } 65 ) 66 67 // Checkpoint identifies a known good point in the block chain. Using 68 // checkpoints allows a few optimizations for old blocks during initial download 69 // and also prevents forks from old blocks. 70 // 71 // Each checkpoint is selected based upon several factors. See the 72 // documentation for blockchain.IsCheckpointCandidate for details on the 73 // selection criteria. 74 type Checkpoint struct { 75 Height int32 76 Hash *chainhash.Hash 77 } 78 79 // DNSSeed identifies a DNS seed. 80 type DNSSeed struct { 81 // Host defines the hostname of the seed. 82 Host string 83 84 // HasFiltering defines whether the seed supports filtering 85 // by service flags (wire.ServiceFlag). 86 HasFiltering bool 87 } 88 89 // ConsensusDeployment defines details related to a specific consensus rule 90 // change that is voted in. This is part of BIP0009. 91 type ConsensusDeployment struct { 92 // BitNumber defines the specific bit number within the block version 93 // this particular soft-fork deployment refers to. 94 BitNumber uint8 95 96 // StartTime is the median block time after which voting on the 97 // deployment starts. 98 StartTime uint64 99 100 // ExpireTime is the median block time after which the attempted 101 // deployment expires. 102 ExpireTime uint64 103 } 104 105 // Constants that define the deployment offset in the deployments field of the 106 // parameters for each deployment. This is useful to be able to get the details 107 // of a specific deployment by name. 108 const ( 109 // DeploymentTestDummy defines the rule change deployment ID for testing 110 // purposes. 111 DeploymentTestDummy = iota 112 113 // DeploymentCSV defines the rule change deployment ID for the CSV 114 // soft-fork package. The CSV package includes the deployment of BIPS 115 // 68, 112, and 113. 116 DeploymentCSV 117 118 // DeploymentSegwit defines the rule change deployment ID for the 119 // Segregated Witness (segwit) soft-fork package. The segwit package 120 // includes the deployment of BIPS 141, 142, 144, 145, 147 and 173. 121 DeploymentSegwit 122 123 // DeploymentTaproot defines the rule change deployment ID for the 124 // Taproot (+Schnorr) soft-fork package. The taproot package includes 125 // the deployment of BIPS 340, 341 and 342. 126 DeploymentTaproot 127 128 // NOTE: DefinedDeployments must always come last since it is used to 129 // determine how many defined deployments there currently are. 130 131 // DefinedDeployments is the number of currently defined deployments. 132 DefinedDeployments 133 ) 134 135 // Params defines a Bitcoin network by its parameters. These parameters may be 136 // used by Bitcoin applications to differentiate networks as well as addresses 137 // and keys for one network from those intended for use on another network. 138 type Params struct { 139 // Name defines a human-readable identifier for the network. 140 Name string 141 142 // Net defines the magic bytes used to identify the network. 143 Net wire.BitcoinNet 144 145 // DefaultPort defines the default peer-to-peer port for the network. 146 DefaultPort string 147 148 // DNSSeeds defines a list of DNS seeds for the network that are used 149 // as one method to discover peers. 150 DNSSeeds []DNSSeed 151 152 // GenesisBlock defines the first block of the chain. 153 GenesisBlock *wire.MsgBlock 154 155 // GenesisHash is the starting block hash. 156 GenesisHash *chainhash.Hash 157 158 // PowLimit defines the highest allowed proof of work value for a block 159 // as a uint256. 160 PowLimit *big.Int 161 162 // PowLimitBits defines the highest allowed proof of work value for a 163 // block in compact form. 164 PowLimitBits uint32 165 166 // These fields define the block heights at which the specified softfork 167 // BIP became active. 168 BIP0034Height int32 169 BIP0065Height int32 170 BIP0066Height int32 171 172 // CoinbaseMaturity is the number of blocks required before newly mined 173 // coins (coinbase transactions) can be spent. 174 CoinbaseMaturity uint16 175 176 // SubsidyReductionInterval is the interval of blocks before the subsidy 177 // is reduced. 178 SubsidyReductionInterval int32 179 180 // TargetTimespan is the desired amount of time that should elapse 181 // before the block difficulty requirement is examined to determine how 182 // it should be changed in order to maintain the desired block 183 // generation rate. 184 TargetTimespan time.Duration 185 186 // TargetTimePerBlock is the desired amount of time to generate each 187 // block. 188 TargetTimePerBlock time.Duration 189 190 // RetargetAdjustmentFactor is the adjustment factor used to limit 191 // the minimum and maximum amount of adjustment that can occur between 192 // difficulty retargets. 193 RetargetAdjustmentFactor int64 194 195 // ReduceMinDifficulty defines whether the network should reduce the 196 // minimum required difficulty after a long enough period of time has 197 // passed without finding a block. This is really only useful for test 198 // networks and should not be set on a main network. 199 ReduceMinDifficulty bool 200 201 // MinDiffReductionTime is the amount of time after which the minimum 202 // required difficulty should be reduced when a block hasn't been found. 203 // 204 // NOTE: This only applies if ReduceMinDifficulty is true. 205 MinDiffReductionTime time.Duration 206 207 // GenerateSupported specifies whether or not CPU mining is allowed. 208 GenerateSupported bool 209 210 // Checkpoints ordered from oldest to newest. 211 Checkpoints []Checkpoint 212 213 // These fields are related to voting on consensus rule changes as 214 // defined by BIP0009. 215 // 216 // RuleChangeActivationThreshold is the number of blocks in a threshold 217 // state retarget window for which a positive vote for a rule change 218 // must be cast in order to lock in a rule change. It should typically 219 // be 95% for the main network and 75% for test networks. 220 // 221 // MinerConfirmationWindow is the number of blocks in each threshold 222 // state retarget window. 223 // 224 // Deployments define the specific consensus rule changes to be voted 225 // on. 226 RuleChangeActivationThreshold uint32 227 MinerConfirmationWindow uint32 228 Deployments [DefinedDeployments]ConsensusDeployment 229 230 // Mempool parameters 231 RelayNonStdTxs bool 232 233 // Human-readable part for Bech32 encoded segwit addresses, as defined 234 // in BIP 173. 235 Bech32HRPSegwit string 236 237 // Address encoding magics 238 PubKeyHashAddrID byte // First byte of a P2PKH address 239 ScriptHashAddrID byte // First byte of a P2SH address 240 PrivateKeyID byte // First byte of a WIF private key 241 WitnessPubKeyHashAddrID byte // First byte of a P2WPKH address 242 WitnessScriptHashAddrID byte // First byte of a P2WSH address 243 244 // BIP32 hierarchical deterministic extended key magics 245 HDPrivateKeyID [4]byte 246 HDPublicKeyID [4]byte 247 248 // BIP44 coin type used in the hierarchical deterministic path for 249 // address generation. 250 HDCoinType uint32 251 } 252 253 // MainNetParams defines the network parameters for the main Bitcoin network. 254 var MainNetParams = Params{ 255 Name: "mainnet", 256 Net: wire.MainNet, 257 DefaultPort: "1948", //8333 258 DNSSeeds: []DNSSeed{ 259 {"seed1.palcoin.net", true}, 260 }, 261 262 // Chain parameters 263 GenesisBlock: &genesisBlock, 264 GenesisHash: &genesisHash, 265 PowLimit: mainPowLimit, 266 PowLimitBits: 0x2000001f, 267 BIP0034Height: 1, // always available 268 BIP0065Height: 1, // always available 269 BIP0066Height: 1, // always available 270 CoinbaseMaturity: 100, 271 SubsidyReductionInterval: 600000, // halve every 272 TargetTimespan: time.Hour * 24 * 2, // recalculate difficulty every 273 TargetTimePerBlock: time.Minute * 4, 274 RetargetAdjustmentFactor: 4, // 25% less, 400% more 275 ReduceMinDifficulty: false, 276 MinDiffReductionTime: 0, 277 GenerateSupported: true, 278 279 // Checkpoints ordered from oldest to newest. 280 Checkpoints: []Checkpoint{}, 281 282 // Consensus rule change deployments. 283 // 284 // The miner confirmation window is defined as: 285 // target proof of work timespan / target proof of work spacing 286 RuleChangeActivationThreshold: 1916, // 95% of MinerConfirmationWindow 287 MinerConfirmationWindow: 2016, // 288 Deployments: [DefinedDeployments]ConsensusDeployment{ 289 DeploymentTestDummy: { 290 BitNumber: 28, 291 StartTime: 1199145601, // January 1, 2008 UTC 292 ExpireTime: 1230767999, // December 31, 2008 UTC 293 }, 294 DeploymentCSV: { 295 BitNumber: 0, 296 StartTime: 1462060800, // May 1st, 2016 297 ExpireTime: 1493596800, // May 1st, 2017 298 }, 299 DeploymentSegwit: { 300 BitNumber: 1, 301 StartTime: 1479168000, // November 15, 2016 UTC 302 ExpireTime: 1510704000, // November 15, 2017 UTC. 303 }, 304 }, 305 306 // Mempool parameters 307 RelayNonStdTxs: false, 308 309 // Human-readable part for Bech32 encoded segwit addresses, as defined in 310 // BIP 173. 311 Bech32HRPSegwit: "bc", // always bc for main net 312 313 // Address encoding magics 314 PubKeyHashAddrID: 0x00, // starts with 1 315 ScriptHashAddrID: 0x05, // starts with 3 316 PrivateKeyID: 0x80, // starts with 5 (uncompressed) or K (compressed) 317 WitnessPubKeyHashAddrID: 0x06, // starts with p2 318 WitnessScriptHashAddrID: 0x0A, // starts with 7Xh 319 320 // BIP32 hierarchical deterministic extended key magics 321 HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv 322 HDPublicKeyID: [4]byte{0x04, 0x88, 0xb2, 0x1e}, // starts with xpub 323 324 // BIP44 coin type used in the hierarchical deterministic path for 325 // address generation. 326 HDCoinType: 1948, 327 } 328 329 // RegressionNetParams defines the network parameters for the regression test 330 // Bitcoin network. Not to be confused with the test Bitcoin network (version 331 // 3), this network is sometimes simply called "testnet". 332 var RegressionNetParams = Params{ 333 Name: "regtest", 334 Net: wire.TestNet, 335 DefaultPort: "12000", //18444 336 DNSSeeds: []DNSSeed{}, 337 338 // Chain parameters 339 GenesisBlock: ®TestGenesisBlock, 340 GenesisHash: ®TestGenesisHash, 341 PowLimit: regressionPowLimit, 342 PowLimitBits: 0x207fffff, 343 CoinbaseMaturity: 100, 344 BIP0034Height: 100000000, // Not active - Permit ver 1 blocks 345 BIP0065Height: 1351, // Used by regression tests 346 BIP0066Height: 1251, // Used by regression tests 347 SubsidyReductionInterval: 150, 348 TargetTimespan: time.Hour * 24 * 7, // 7 days 349 TargetTimePerBlock: time.Minute * 2, // 2 minutes 350 RetargetAdjustmentFactor: 4, // 25% less, 400% more 351 ReduceMinDifficulty: true, 352 MinDiffReductionTime: time.Minute * 4, // TargetTimePerBlock * 2 353 GenerateSupported: true, 354 355 // Checkpoints ordered from oldest to newest. 356 Checkpoints: nil, 357 358 // Consensus rule change deployments. 359 // 360 // The miner confirmation window is defined as: 361 // target proof of work timespan / target proof of work spacing 362 RuleChangeActivationThreshold: 108, // 75% of MinerConfirmationWindow 363 MinerConfirmationWindow: 144, 364 Deployments: [DefinedDeployments]ConsensusDeployment{ 365 DeploymentTestDummy: { 366 BitNumber: 28, 367 StartTime: 0, // Always available for vote 368 ExpireTime: math.MaxInt64, // Never expires 369 }, 370 DeploymentCSV: { 371 BitNumber: 0, 372 StartTime: 0, // Always available for vote 373 ExpireTime: math.MaxInt64, // Never expires 374 }, 375 DeploymentSegwit: { 376 BitNumber: 1, 377 StartTime: 0, // Always available for vote 378 ExpireTime: math.MaxInt64, // Never expires. 379 }, 380 }, 381 382 // Mempool parameters 383 RelayNonStdTxs: true, 384 385 // Human-readable part for Bech32 encoded segwit addresses, as defined in 386 // BIP 173. 387 Bech32HRPSegwit: "bcr", // always bcrt for reg test net 388 389 // Address encoding magics 390 PubKeyHashAddrID: 0x6f, // starts with m or n 391 ScriptHashAddrID: 0xc4, // starts with 2 392 PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed) 393 394 // BIP32 hierarchical deterministic extended key magics 395 HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv 396 HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub 397 398 // BIP44 coin type used in the hierarchical deterministic path for 399 // address generation. 400 HDCoinType: 1, 401 } 402 403 // TestNet3Params defines the network parameters for the test Bitcoin network 404 // (version 3). Not to be confused with the regression test network, this 405 // network is sometimes simply called "testnet". 406 var TestNet3Params = Params{ 407 Name: "testnet3", 408 Net: wire.TestNet3, 409 DefaultPort: "11948", //18333 410 DNSSeeds: []DNSSeed{ 411 {"seed-test1.palcoin.net", true}, 412 }, 413 414 // Chain parameters 415 GenesisBlock: &testNet3GenesisBlock, 416 GenesisHash: &testNet3GenesisHash, 417 PowLimit: testNet3PowLimit, 418 PowLimitBits: 0x1d00ffff, 419 BIP0034Height: 21111, // 0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8 420 BIP0065Height: 581885, // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6 421 BIP0066Height: 330776, // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182 422 CoinbaseMaturity: 100, 423 SubsidyReductionInterval: 210000, 424 TargetTimespan: time.Hour * 24 * 7, // 7 days 425 TargetTimePerBlock: time.Minute * 2, // 2 minutes 426 RetargetAdjustmentFactor: 4, // 25% less, 400% more 427 ReduceMinDifficulty: true, 428 MinDiffReductionTime: time.Minute * 4, // TargetTimePerBlock * 2 429 GenerateSupported: false, 430 431 // Checkpoints ordered from oldest to newest. 432 Checkpoints: []Checkpoint{}, 433 434 // Consensus rule change deployments. 435 // 436 // The miner confirmation window is defined as: 437 // target proof of work timespan / target proof of work spacing 438 RuleChangeActivationThreshold: 1512, // 75% of MinerConfirmationWindow 439 MinerConfirmationWindow: 2016, 440 Deployments: [DefinedDeployments]ConsensusDeployment{ 441 DeploymentTestDummy: { 442 BitNumber: 28, 443 StartTime: 1199145601, // January 1, 2008 UTC 444 ExpireTime: 1230767999, // December 31, 2008 UTC 445 }, 446 DeploymentCSV: { 447 BitNumber: 0, 448 StartTime: 1456790400, // March 1st, 2016 449 ExpireTime: 1493596800, // May 1st, 2017 450 }, 451 DeploymentSegwit: { 452 BitNumber: 1, 453 StartTime: 1462060800, // May 1, 2016 UTC 454 ExpireTime: 1493596800, // May 1, 2017 UTC. 455 }, 456 }, 457 458 // Mempool parameters 459 RelayNonStdTxs: true, 460 461 // Human-readable part for Bech32 encoded segwit addresses, as defined in 462 // BIP 173. 463 Bech32HRPSegwit: "tb", // always tb for test net 464 465 // Address encoding magics 466 PubKeyHashAddrID: 0x6f, // starts with m or n 467 ScriptHashAddrID: 0xc4, // starts with 2 468 WitnessPubKeyHashAddrID: 0x03, // starts with QW 469 WitnessScriptHashAddrID: 0x28, // starts with T7n 470 PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed) 471 472 // BIP32 hierarchical deterministic extended key magics 473 HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv 474 HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub 475 476 // BIP44 coin type used in the hierarchical deterministic path for 477 // address generation. 478 HDCoinType: 1, 479 } 480 481 // SimNetParams defines the network parameters for the simulation test Bitcoin 482 // network. This network is similar to the normal test network except it is 483 // intended for private use within a group of individuals doing simulation 484 // testing. The functionality is intended to differ in that the only nodes 485 // which are specifically specified are used to create the network rather than 486 // following normal discovery rules. This is important as otherwise it would 487 // just turn into another public testnet. 488 var SimNetParams = Params{ 489 Name: "simnet", 490 Net: wire.SimNet, 491 DefaultPort: "11917", //18555 492 DNSSeeds: []DNSSeed{}, // NOTE: There must NOT be any seeds. 493 494 // Chain parameters 495 GenesisBlock: &simNetGenesisBlock, 496 GenesisHash: &simNetGenesisHash, 497 PowLimit: simNetPowLimit, 498 PowLimitBits: 0x207fffff, 499 BIP0034Height: 0, // Always active on simnet 500 BIP0065Height: 0, // Always active on simnet 501 BIP0066Height: 0, // Always active on simnet 502 CoinbaseMaturity: 100, 503 SubsidyReductionInterval: 210000, 504 TargetTimespan: time.Hour * 24 * 7, // 7 days 505 TargetTimePerBlock: time.Minute * 2, // 2 minutes 506 RetargetAdjustmentFactor: 4, // 25% less, 400% more 507 ReduceMinDifficulty: true, 508 MinDiffReductionTime: time.Minute * 4, // TargetTimePerBlock * 2 509 GenerateSupported: true, 510 511 // Checkpoints ordered from oldest to newest. 512 Checkpoints: nil, 513 514 // Consensus rule change deployments. 515 // 516 // The miner confirmation window is defined as: 517 // target proof of work timespan / target proof of work spacing 518 RuleChangeActivationThreshold: 75, // 75% of MinerConfirmationWindow 519 MinerConfirmationWindow: 100, 520 Deployments: [DefinedDeployments]ConsensusDeployment{ 521 DeploymentTestDummy: { 522 BitNumber: 28, 523 StartTime: 0, // Always available for vote 524 ExpireTime: math.MaxInt64, // Never expires 525 }, 526 DeploymentCSV: { 527 BitNumber: 0, 528 StartTime: 0, // Always available for vote 529 ExpireTime: math.MaxInt64, // Never expires 530 }, 531 DeploymentSegwit: { 532 BitNumber: 1, 533 StartTime: 0, // Always available for vote 534 ExpireTime: math.MaxInt64, // Never expires. 535 }, 536 }, 537 538 // Mempool parameters 539 RelayNonStdTxs: true, 540 541 // Human-readable part for Bech32 encoded segwit addresses, as defined in 542 // BIP 173. 543 Bech32HRPSegwit: "sb", // always sb for sim net 544 545 // Address encoding magics 546 PubKeyHashAddrID: 0x3f, // starts with S 547 ScriptHashAddrID: 0x7b, // starts with s 548 PrivateKeyID: 0x64, // starts with 4 (uncompressed) or F (compressed) 549 WitnessPubKeyHashAddrID: 0x19, // starts with Gg 550 WitnessScriptHashAddrID: 0x28, // starts with ? 551 552 // BIP32 hierarchical deterministic extended key magics 553 HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00}, // starts with sprv 554 HDPublicKeyID: [4]byte{0x04, 0x20, 0xbd, 0x3a}, // starts with spub 555 556 // BIP44 coin type used in the hierarchical deterministic path for 557 // address generation. 558 HDCoinType: 115, // ASCII for s 559 } 560 561 // SigNetParams defines the network parameters for the default public signet 562 // Bitcoin network. Not to be confused with the regression test network, this 563 // network is sometimes simply called "signet" or "taproot signet". 564 var SigNetParams = CustomSignetParams( 565 DefaultSignetChallenge, DefaultSignetDNSSeeds, 566 ) 567 568 // CustomSignetParams creates network parameters for a custom signet network 569 // from a challenge. The challenge is the binary compiled version of the block 570 // challenge script. 571 func CustomSignetParams(challenge []byte, dnsSeeds []DNSSeed) Params { 572 // The message start is defined as the first four bytes of the sha256d 573 // of the challenge script, as a single push (i.e. prefixed with the 574 // challenge script length). 575 challengeLength := byte(len(challenge)) 576 hashDouble := chainhash.DoubleHashB( 577 append([]byte{challengeLength}, challenge...), 578 ) 579 580 // We use little endian encoding of the hash prefix to be in line with 581 // the other wire network identities. 582 net := binary.LittleEndian.Uint32(hashDouble[0:4]) 583 return Params{ 584 Name: "signet", 585 Net: wire.BitcoinNet(net), 586 DefaultPort: "31948", //38333 587 DNSSeeds: dnsSeeds, 588 589 // Chain parameters 590 GenesisBlock: &sigNetGenesisBlock, 591 GenesisHash: &sigNetGenesisHash, 592 PowLimit: sigNetPowLimit, 593 PowLimitBits: 0x1e0377ae, 594 BIP0034Height: 1, 595 BIP0065Height: 1, 596 BIP0066Height: 1, 597 CoinbaseMaturity: 100, 598 SubsidyReductionInterval: 210000, 599 TargetTimespan: time.Hour * 24 * 7, // 7 days 600 TargetTimePerBlock: time.Minute * 2, // 2 minutes 601 RetargetAdjustmentFactor: 4, // 25% less, 400% more 602 ReduceMinDifficulty: false, 603 MinDiffReductionTime: time.Minute * 4, // TargetTimePerBlock * 2 604 GenerateSupported: false, 605 606 // Checkpoints ordered from oldest to newest. 607 Checkpoints: nil, 608 609 // Consensus rule change deployments. 610 // 611 // The miner confirmation window is defined as: 612 // target proof of work timespan / target proof of work spacing 613 RuleChangeActivationThreshold: 1916, // 95% of 2016 614 MinerConfirmationWindow: 2016, 615 Deployments: [DefinedDeployments]ConsensusDeployment{ 616 DeploymentTestDummy: { 617 BitNumber: 28, 618 StartTime: 1199145601, // January 1, 2008 UTC 619 ExpireTime: 1230767999, // December 31, 2008 UTC 620 }, 621 DeploymentCSV: { 622 BitNumber: 29, 623 StartTime: 0, // Always available for vote 624 ExpireTime: math.MaxInt64, // Never expires 625 }, 626 DeploymentSegwit: { 627 BitNumber: 29, 628 StartTime: 0, // Always available for vote 629 ExpireTime: math.MaxInt64, // Never expires. 630 }, 631 DeploymentTaproot: { 632 BitNumber: 29, 633 StartTime: 0, // Always available for vote 634 ExpireTime: math.MaxInt64, // Never expires. 635 }, 636 }, 637 638 // Mempool parameters 639 RelayNonStdTxs: false, 640 641 // Human-readable part for Bech32 encoded segwit addresses, as defined in 642 // BIP 173. 643 Bech32HRPSegwit: "tb", // always tb for test net 644 645 // Address encoding magics 646 PubKeyHashAddrID: 0x6f, // starts with m or n 647 ScriptHashAddrID: 0xc4, // starts with 2 648 WitnessPubKeyHashAddrID: 0x03, // starts with QW 649 WitnessScriptHashAddrID: 0x28, // starts with T7n 650 PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed) 651 652 // BIP32 hierarchical deterministic extended key magics 653 HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv 654 HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub 655 656 // BIP44 coin type used in the hierarchical deterministic path for 657 // address generation. 658 HDCoinType: 1, 659 } 660 } 661 662 var ( 663 // ErrDuplicateNet describes an error where the parameters for a Bitcoin 664 // network could not be set due to the network already being a standard 665 // network or previously-registered into this package. 666 ErrDuplicateNet = errors.New("duplicate Bitcoin network") 667 668 // ErrUnknownHDKeyID describes an error where the provided id which 669 // is intended to identify the network for a hierarchical deterministic 670 // private extended key is not registered. 671 ErrUnknownHDKeyID = errors.New("unknown hd private extended key bytes") 672 673 // ErrInvalidHDKeyID describes an error where the provided hierarchical 674 // deterministic version bytes, or hd key id, is malformed. 675 ErrInvalidHDKeyID = errors.New("invalid hd extended key version bytes") 676 ) 677 678 var ( 679 registeredNets = make(map[wire.BitcoinNet]struct{}) 680 pubKeyHashAddrIDs = make(map[byte]struct{}) 681 scriptHashAddrIDs = make(map[byte]struct{}) 682 bech32SegwitPrefixes = make(map[string]struct{}) 683 hdPrivToPubKeyIDs = make(map[[4]byte][]byte) 684 ) 685 686 // String returns the hostname of the DNS seed in human-readable form. 687 func (d DNSSeed) String() string { 688 return d.Host 689 } 690 691 // Register registers the network parameters for a Bitcoin network. This may 692 // error with ErrDuplicateNet if the network is already registered (either 693 // due to a previous Register call, or the network being one of the default 694 // networks). 695 // 696 // Network parameters should be registered into this package by a main package 697 // as early as possible. Then, library packages may lookup networks or network 698 // parameters based on inputs and work regardless of the network being standard 699 // or not. 700 func Register(params *Params) error { 701 if _, ok := registeredNets[params.Net]; ok { 702 return ErrDuplicateNet 703 } 704 registeredNets[params.Net] = struct{}{} 705 pubKeyHashAddrIDs[params.PubKeyHashAddrID] = struct{}{} 706 scriptHashAddrIDs[params.ScriptHashAddrID] = struct{}{} 707 708 err := RegisterHDKeyID(params.HDPublicKeyID[:], params.HDPrivateKeyID[:]) 709 if err != nil { 710 return err 711 } 712 713 // A valid Bech32 encoded segwit address always has as prefix the 714 // human-readable part for the given net followed by '1'. 715 bech32SegwitPrefixes[params.Bech32HRPSegwit+"1"] = struct{}{} 716 return nil 717 } 718 719 // mustRegister performs the same function as Register except it panics if there 720 // is an error. This should only be called from package init functions. 721 func mustRegister(params *Params) { 722 if err := Register(params); err != nil { 723 panic("failed to register network: " + err.Error()) 724 } 725 } 726 727 // IsPubKeyHashAddrID returns whether the id is an identifier known to prefix a 728 // pay-to-pubkey-hash address on any default or registered network. This is 729 // used when decoding an address string into a specific address type. It is up 730 // to the caller to check both this and IsScriptHashAddrID and decide whether an 731 // address is a pubkey hash address, script hash address, neither, or 732 // undeterminable (if both return true). 733 func IsPubKeyHashAddrID(id byte) bool { 734 _, ok := pubKeyHashAddrIDs[id] 735 return ok 736 } 737 738 // IsScriptHashAddrID returns whether the id is an identifier known to prefix a 739 // pay-to-script-hash address on any default or registered network. This is 740 // used when decoding an address string into a specific address type. It is up 741 // to the caller to check both this and IsPubKeyHashAddrID and decide whether an 742 // address is a pubkey hash address, script hash address, neither, or 743 // undeterminable (if both return true). 744 func IsScriptHashAddrID(id byte) bool { 745 _, ok := scriptHashAddrIDs[id] 746 return ok 747 } 748 749 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit 750 // addresses on any default or registered network. This is used when decoding 751 // an address string into a specific address type. 752 func IsBech32SegwitPrefix(prefix string) bool { 753 prefix = strings.ToLower(prefix) 754 _, ok := bech32SegwitPrefixes[prefix] 755 return ok 756 } 757 758 // RegisterHDKeyID registers a public and private hierarchical deterministic 759 // extended key ID pair. 760 // 761 // Non-standard HD version bytes, such as the ones documented in SLIP-0132, 762 // should be registered using this method for library packages to lookup key 763 // IDs (aka HD version bytes). When the provided key IDs are invalid, the 764 // ErrInvalidHDKeyID error will be returned. 765 // 766 // Reference: 767 // SLIP-0132 : Registered HD version bytes for BIP-0032 768 // https://github.com/satoshilabs/slips/blob/master/slip-0132.md 769 func RegisterHDKeyID(hdPublicKeyID []byte, hdPrivateKeyID []byte) error { 770 if len(hdPublicKeyID) != 4 || len(hdPrivateKeyID) != 4 { 771 return ErrInvalidHDKeyID 772 } 773 774 var keyID [4]byte 775 copy(keyID[:], hdPrivateKeyID) 776 hdPrivToPubKeyIDs[keyID] = hdPublicKeyID 777 778 return nil 779 } 780 781 // HDPrivateKeyToPublicKeyID accepts a private hierarchical deterministic 782 // extended key id and returns the associated public key id. When the provided 783 // id is not registered, the ErrUnknownHDKeyID error will be returned. 784 func HDPrivateKeyToPublicKeyID(id []byte) ([]byte, error) { 785 if len(id) != 4 { 786 return nil, ErrUnknownHDKeyID 787 } 788 789 var key [4]byte 790 copy(key[:], id) 791 pubBytes, ok := hdPrivToPubKeyIDs[key] 792 if !ok { 793 return nil, ErrUnknownHDKeyID 794 } 795 796 return pubBytes, nil 797 } 798 799 // newHashFromStr converts the passed big-endian hex string into a 800 // chainhash.Hash. It only differs from the one available in chainhash in that 801 // it panics on an error since it will only (and must only) be called with 802 // hard-coded, and therefore known good, hashes. 803 func newHashFromStr(hexStr string) *chainhash.Hash { 804 hash, err := chainhash.NewHashFromStr(hexStr) 805 if err != nil { 806 // Ordinarily I don't like panics in library code since it 807 // can take applications down without them having a chance to 808 // recover which is extremely annoying, however an exception is 809 // being made in this case because the only way this can panic 810 // is if there is an error in the hard-coded hashes. Thus it 811 // will only ever potentially panic on init and therefore is 812 // 100% predictable. 813 panic(err) 814 } 815 return hash 816 } 817 818 func init() { 819 // Register all default networks when the package is initialized. 820 mustRegister(&MainNetParams) 821 mustRegister(&TestNet3Params) 822 mustRegister(&RegressionNetParams) 823 mustRegister(&SimNetParams) 824 }