itns-sidechain/scripts/gen.js

143 lines
3.3 KiB
JavaScript
Raw Normal View History

var bcoin = require('bcoin');
2016-02-23 20:38:25 -08:00
var constants = bcoin.protocol.constants;
2016-03-30 19:10:59 -07:00
var network = bcoin.protocol.network;
2016-02-23 20:38:25 -08:00
var utils = bcoin.utils;
2016-03-30 19:10:59 -07:00
var bn = require('bn.js');
2016-02-23 20:38:25 -08:00
function createGenesisBlock(options) {
var parser = bcoin.protocol.parser;
2016-03-30 19:10:59 -07:00
var tx, block, txRaw, blockRaw;
2016-02-23 20:38:25 -08:00
if (!options.flags) {
options.flags = new Buffer(
'The Times 03/Jan/2009 Chancellor on brink of second bailout for banks',
'ascii');
}
if (!options.script) {
2016-03-30 19:10:59 -07:00
options.script = {
code: [
new Buffer('04678afdb0fe5548271967f1a67130b7105cd6a828e039'
+ '09a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c3'
+ '84df7ba0b8d578a4c702b6bf11d5f', 'hex'),
constants.opcodes.OP_CHECKSIG
]
};
2016-02-23 20:38:25 -08:00
}
if (!options.reward)
2016-04-17 08:45:22 -07:00
options.reward = new bn(50).mul(constants.COIN);
2016-02-23 20:38:25 -08:00
tx = {
version: 1,
inputs: [{
prevout: {
2016-04-17 08:45:22 -07:00
hash: constants.NULL_HASH,
2016-02-23 20:38:25 -08:00
index: 0xffffffff
},
2016-03-30 19:10:59 -07:00
script: {
code: [
2016-04-09 03:23:55 -07:00
new bn(486604799).toBuffer('le'),
new bn(4).toBuffer('le'),
2016-03-30 19:10:59 -07:00
options.flags
]
},
2016-02-23 20:38:25 -08:00
sequence: 0xffffffff
}],
outputs: [{
value: options.reward,
script: options.script
}],
locktime: 0
};
2016-04-27 20:50:04 -07:00
tx.inputs[0].script.code[1].opcode = 1;
2016-03-30 19:10:59 -07:00
txRaw = bcoin.protocol.framer.tx(tx);
tx._raw = txRaw;
tx._size = txRaw.length;
tx._witnessSize = 0;
2016-02-23 20:38:25 -08:00
block = {
version: options.version,
2016-04-17 08:45:22 -07:00
prevBlock: constants.NULL_HASH,
2016-04-18 01:11:02 -07:00
merkleRoot: utils.dsha256(txRaw).toString('hex'),
2016-02-23 20:38:25 -08:00
ts: options.ts,
bits: options.bits,
nonce: options.nonce,
txs: [tx]
};
2016-03-30 19:10:59 -07:00
blockRaw = bcoin.protocol.framer.block(block);
2016-02-23 20:38:25 -08:00
2016-03-30 19:10:59 -07:00
block = parser.parseBlock(blockRaw);
2016-02-23 20:38:25 -08:00
2016-03-30 19:10:59 -07:00
block._hash = utils.dsha256(blockRaw.slice(0, 80));
2016-04-18 01:11:02 -07:00
block.hash = block._hash.toString('hex');
2016-03-30 19:10:59 -07:00
block._raw = blockRaw;
block._size = blockRaw.length;
block._witnessSize = 0;
2016-02-23 20:38:25 -08:00
block.height = 0;
tx = block.txs[0];
tx.height = 0;
tx.ts = block.ts;
tx._hash = block.merkleRoot;
2016-04-18 01:11:02 -07:00
tx.hash = tx._hash.toString('hex');
2016-02-23 20:38:25 -08:00
return block;
}
var main = createGenesisBlock({
version: 1,
ts: 1231006505,
bits: 486604799,
nonce: 2083236893
});
var testnet = createGenesisBlock({
version: 1,
ts: 1296688602,
bits: 486604799,
nonce: 414098458
});
var regtest = createGenesisBlock({
version: 1,
ts: 1296688602,
bits: 545259519,
nonce: 2
});
2016-03-30 19:10:59 -07:00
var segnet3 = createGenesisBlock({
version: 1,
2016-02-26 17:08:06 -08:00
ts: 1452831101,
bits: 0x1d00ffff,
nonce: 0
});
2016-03-30 19:10:59 -07:00
var segnet4 = createGenesisBlock({
version: 1,
ts: 1452831101,
2016-04-27 20:50:04 -07:00
bits: utils.toCompact(network.segnet4.pow.limit),
2016-03-30 19:10:59 -07:00
nonce: 0
});
2016-02-23 20:38:25 -08:00
utils.print(main);
utils.print(testnet);
utils.print(regtest);
2016-03-30 19:10:59 -07:00
utils.print(segnet3);
2016-02-26 17:08:06 -08:00
utils.print('main hash: %s', utils.revHex(main.hash));
2016-04-27 20:50:04 -07:00
utils.print('main raw: %s', main._raw.toString('hex'));
2016-02-23 20:38:25 -08:00
utils.print('');
2016-02-26 17:08:06 -08:00
utils.print('testnet hash: %s', utils.revHex(testnet.hash));
2016-04-27 20:50:04 -07:00
utils.print('testnet raw: %s', testnet._raw.toString('hex'));
2016-02-23 20:38:25 -08:00
utils.print('');
2016-02-26 17:08:06 -08:00
utils.print('regtest hash: %s', utils.revHex(regtest.hash));
2016-04-27 20:50:04 -07:00
utils.print('regtest raw: %s', regtest._raw.toString('hex'));
2016-03-30 19:10:59 -07:00
utils.print('segnet3 hash: %s', utils.revHex(segnet3.hash));
2016-04-27 20:50:04 -07:00
utils.print('segnet3 raw: %s', segnet3._raw.toString('hex'));
2016-03-30 19:10:59 -07:00
utils.print('segnet4 hash: %s', utils.revHex(segnet4.hash));
2016-04-27 20:50:04 -07:00
utils.print('segnet4 raw: %s', segnet4._raw.toString('hex'));
2016-03-30 19:10:59 -07:00
utils.print(segnet4);