| 6 | const Script = require('../lib/script/script'); |
| 7 | |
| 8 | function createGenesisBlock(options) { |
| 9 | let flags = options.flags; |
| 10 | let key = options.key; |
| 11 | let reward = options.reward; |
| 12 | |
| 13 | if (!flags) { |
| 14 | flags = Buffer.from( |
| 15 | 'The Times 03/Jan/2009 Chancellor on brink of second bailout for banks', |
| 16 | 'ascii'); |
| 17 | } |
| 18 | |
| 19 | if (!key) { |
| 20 | key = Buffer.from('' |
| 21 | + '04678afdb0fe5548271967f1a67130b7105cd6a828e039' |
| 22 | + '09a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c3' |
| 23 | + '84df7ba0b8d578a4c702b6bf11d5f', 'hex'); |
| 24 | } |
| 25 | |
| 26 | if (!reward) |
| 27 | reward = 50 * consensus.COIN; |
| 28 | |
| 29 | const tx = new TX({ |
| 30 | version: 1, |
| 31 | inputs: [{ |
| 32 | prevout: { |
| 33 | hash: consensus.ZERO_HASH, |
| 34 | index: 0xffffffff |
| 35 | }, |
| 36 | script: Script() |
| 37 | .pushInt(486604799) |
| 38 | .pushPush(Buffer.from([4])) |
| 39 | .pushData(flags) |
| 40 | .compile(), |
| 41 | sequence: 0xffffffff |
| 42 | }], |
| 43 | outputs: [{ |
| 44 | value: reward, |
| 45 | script: Script.fromPubkey(key) |
| 46 | }], |
| 47 | locktime: 0 |
| 48 | }); |
| 49 | |
| 50 | const block = new Block({ |
| 51 | version: options.version, |
| 52 | prevBlock: consensus.ZERO_HASH, |
| 53 | merkleRoot: tx.hash(), |
| 54 | time: options.time, |
| 55 | bits: options.bits, |
| 56 | nonce: options.nonce, |
| 57 | height: 0 |
| 58 | }); |
| 59 | |
| 60 | block.txs.push(tx); |
| 61 | |
| 62 | return block; |
| 63 | } |
| 64 | |
| 65 | const main = createGenesisBlock({ |