|
16 | 16 | from .script import CScript |
17 | 17 |
|
18 | 18 | from .serialize import * |
19 | | -from .coredefs import * |
| 19 | + |
| 20 | +# Core definitions |
| 21 | +COIN = 100000000 |
| 22 | +MAX_MONEY = 21000000 * COIN |
| 23 | +MAX_BLOCK_SIZE = 1000000 |
| 24 | +MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50 |
| 25 | + |
| 26 | +def MoneyRange(nValue): |
| 27 | + return 0<= nValue <= MAX_MONEY |
20 | 28 |
|
21 | 29 | def x(h): |
22 | 30 | """Convert a hex string to bytes""" |
@@ -313,6 +321,49 @@ def calc_merkle_root(self): |
313 | 321 | return CBlock.calc_merkle_root_from_hashes(hashes) |
314 | 322 |
|
315 | 323 |
|
| 324 | +class CoreChainParams(object): |
| 325 | + """Define consensus-critical parameters of a given instance of the Bitcoin system""" |
| 326 | + GENESIS_BLOCK = None |
| 327 | + PROOF_OF_WORK_LIMIT = None |
| 328 | + SUBSIDY_HALVING_INTERVAL = None |
| 329 | + NAME = None |
| 330 | + |
| 331 | +class CoreMainParams(CoreChainParams): |
| 332 | + NAME = 'mainnet' |
| 333 | + GENESIS_BLOCK = CBlock.deserialize(x('0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000')) |
| 334 | + SUBSIDY_HALVING_INTERVAL = 210000 |
| 335 | + PROOF_OF_WORK_LIMIT = 2**256-1 >> 32 |
| 336 | + |
| 337 | +class CoreTestNetParams(CoreMainParams): |
| 338 | + NAME = 'testnet' |
| 339 | + GENESIS_BLOCK = CBlock.deserialize(x('0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff001d1aa4ae180101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000')) |
| 340 | + |
| 341 | +class CoreRegTestParams(CoreTestNetParams): |
| 342 | + NAME = 'regtest' |
| 343 | + GENESIS_BLOCK = CBlock.deserialize(x('0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f20020000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000')) |
| 344 | + SUBSIDY_HALVING_INTERVAL = 150 |
| 345 | + PROOF_OF_WORK_LIMIT = 2**256-1 >> 1 |
| 346 | + |
| 347 | +"""Master global setting for what core chain params we're using""" |
| 348 | +coreparams = CoreMainParams() |
| 349 | + |
| 350 | +def _SelectCoreParams(name): |
| 351 | + """Select the core chain parameters to use |
| 352 | +
|
| 353 | + Don't use this directly, use bitcoin.SelectParams() instead so both |
| 354 | + consensus-critical and general parameters are set properly. |
| 355 | + """ |
| 356 | + global coreparams |
| 357 | + if name == 'mainnet': |
| 358 | + coreparams = CoreMainParams() |
| 359 | + elif name == 'testnet': |
| 360 | + coreparams = CoreTestNetParams() |
| 361 | + elif name == 'regtest': |
| 362 | + coreparams = CoreRegTestParams() |
| 363 | + else: |
| 364 | + raise ValueError('Unknown chain %r' % name) |
| 365 | + |
| 366 | + |
316 | 367 | class CheckTransactionError(ValidationError): |
317 | 368 | pass |
318 | 369 |
|
@@ -376,7 +427,7 @@ def CheckProofOfWork(hash, nBits): |
376 | 427 | target = uint256_from_compact(nBits) |
377 | 428 |
|
378 | 429 | # Check range |
379 | | - if not (0 < target <= PROOF_OF_WORK_LIMIT): |
| 430 | + if not (0 < target <= coreparams.PROOF_OF_WORK_LIMIT): |
380 | 431 | raise CheckProofOfWorkError("CheckProofOfWork() : nBits below minimum work") |
381 | 432 |
|
382 | 433 | # Check proof of work matches claimed amount |
|
0 commit comments