-
Notifications
You must be signed in to change notification settings - Fork 1
3.4 header
gettocat edited this page Aug 25, 2017
·
2 revisions
Blockheader is Block info type object. This type contain next fields (81 byte):
{
version: 'uint32',
prev_block: 'hash',
merkle_root: 'hash',
timestamp: 'uint32',
bits: 'uint32',
nonce: 'uint32',
txn_count: 'var_int',//for header is every time 0
hash: 'hash'//read only
}
if you need 80 bytes only use type: header80 (for stack and stream)
read from Buffer (or hex string) into object with fields above.
Buffer bitPony.header.write(int version, string prev_block, string merkle_root, int timestamp, int bits, int nonce)
write into Buffer object. Throw error if:
- version prev_block merkle_root timestamp bits or nonce is empty
- version,timestamp,bits,nonce is not numeric
- prev_block is invalid hash (not 32 byte str)
- merkle_root is invalid hash (not 32 byte str)
read from stack header value
var script = {
'keyname': ['header'] //or header80 if need only 80 bytes
}
var stack = new bitPony.stackReader(buffer, script)write into stack header value
var script = [
['header', version, prev_block, merkle_root, timestamp, bits, nonce, txn_count],//or header80 if need only 80 bytes or txn_count = null
];
var stack = new bitPony.stackWriter(buffer, script);read from stream tx
var stream = new bitPony.reader(b);
var res = stream.header(offset);
//res.resultwrite to stream header value
var stream = new bitPony.writer(b);
stream.header(version, prev_block, merkle_root, timestamp, bits, nonce, txn_count, true);
//or
var res = stream.tx_in(version, prev_block, merkle_root, timestamp, bits, nonce, txn_count);
//res.resultcan be vector as vector.header only for read