-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblockHeader.js
27 lines (24 loc) · 1.03 KB
/
blockHeader.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
const {merkleRootTxid} = require('./create_merkle_txid.js')
const { decimalToLittleEndian8, bigToLittleEndian } = require('./utils.js');
const currentTimeInSeconds = Math.floor(Date.now() / 1000);
const hexTime = currentTimeInSeconds.toString(16);
const hexTime_reverse = bigToLittleEndian(hexTime)
const block = {
version: 20000000,//VERSION
previousBlockHash: "0000000000000000000000000000000000000000000000000000000000000000",
merkleRootHash: "c3cde35006601b0b08cf9d4b6e2dd551ceba49e67497e48032bcdafb86191a83",
timeStamp: hexTime_reverse,
difficultyTarget: "0000ffff00000000000000000000000000000000000000000000000000000000",
nonce: 0
}
function createBlockHeader(x){
let blockheader = ""
blockheader += "00000020";
blockheader += (x.previousBlockHash);
blockheader += (x.merkleRootHash);
blockheader += x.timeStamp;
blockheader += bigToLittleEndian("1f00ffff")
return blockheader;
}
const blockHeaderwithoutnounce = createBlockHeader(block)
module.exports = {blockHeaderwithoutnounce, block}