forked from bcoin-org/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen.js
134 lines (118 loc) · 2.97 KB
/
gen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
const consensus = require('../lib/protocol/consensus');
const TX = require('../lib/primitives/tx');
const Block = require('../lib/primitives/block');
const Script = require('../lib/script/script');
function createGenesisBlock(options) {
let flags = options.flags;
let key = options.key;
let reward = options.reward;
if (!flags) {
flags = Buffer.from(
'The Times 03/Jan/2009 Chancellor on brink of second bailout for banks',
'ascii');
}
if (!key) {
key = Buffer.from(''
+ '04678afdb0fe5548271967f1a67130b7105cd6a828e039'
+ '09a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c3'
+ '84df7ba0b8d578a4c702b6bf11d5f', 'hex');
}
if (!reward)
reward = 50 * consensus.COIN;
const tx = new TX({
version: 1,
inputs: [{
prevout: {
hash: consensus.ZERO_HASH,
index: 0xffffffff
},
script: Script()
.pushInt(486604799)
.pushPush(Buffer.from([4]))
.pushData(flags)
.compile(),
sequence: 0xffffffff
}],
outputs: [{
value: reward,
script: Script.fromPubkey(key)
}],
locktime: 0
});
const block = new Block({
version: options.version,
prevBlock: consensus.ZERO_HASH,
merkleRoot: tx.hash(),
time: options.time,
bits: options.bits,
nonce: options.nonce,
height: 0
});
block.txs.push(tx);
return block;
}
const main = createGenesisBlock({
version: 1,
time: 1231006505,
bits: 486604799,
nonce: 2083236893
});
const testnet = createGenesisBlock({
version: 1,
time: 1296688602,
bits: 486604799,
nonce: 414098458
});
const regtest = createGenesisBlock({
version: 1,
time: 1296688602,
bits: 545259519,
nonce: 2
});
const segnet3 = createGenesisBlock({
version: 1,
time: 1452831101,
bits: 486604799,
nonce: 0
});
const segnet4 = createGenesisBlock({
version: 1,
time: 1452831101,
bits: 503447551,
nonce: 0
});
const btcd = createGenesisBlock({
version: 1,
time: 1401292357,
bits: 545259519,
nonce: 2
});
console.log(main);
console.log('');
console.log(testnet);
console.log('');
console.log(regtest);
console.log('');
console.log(segnet3);
console.log('');
console.log(segnet4);
console.log('');
console.log('');
console.log('main hash: %s', main.rhash());
console.log('main raw: %s', main.toRaw().toString('hex'));
console.log('');
console.log('testnet hash: %s', testnet.rhash());
console.log('testnet raw: %s', testnet.toRaw().toString('hex'));
console.log('');
console.log('regtest hash: %s', regtest.rhash());
console.log('regtest raw: %s', regtest.toRaw().toString('hex'));
console.log('');
console.log('segnet3 hash: %s', segnet3.rhash());
console.log('segnet3 raw: %s', segnet3.toRaw().toString('hex'));
console.log('');
console.log('segnet4 hash: %s', segnet4.rhash());
console.log('segnet4 raw: %s', segnet4.toRaw().toString('hex'));
console.log('');
console.log('btcd simnet hash: %s', btcd.rhash());
console.log('btcd simnet raw: %s', btcd.toRaw().toString('hex'));