-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget_block_prefix.js
More file actions
31 lines (27 loc) · 919 Bytes
/
get_block_prefix.js
File metadata and controls
31 lines (27 loc) · 919 Bytes
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
const steem = require('@steemit/steem-js');
steem.api.setOptions({
url: "https://api.steemit.com",
retry: false,
useAppbaseApi: true,
});
function getProperties() {
return new Promise((resolve, reject) => {
steem.api.getDynamicGlobalProperties(function(err, result) {
if(!err) {
resolve(result);
}
else
console.log(err);
});
});
}
async function getBlockAndPrefix(properties) {
let refBlockNum = (properties.last_irreversible_block_num - 1) & 0xFFFF;
steem.api.getBlockHeaderAsync(properties.last_irreversible_block_num).then((block) => {
let headBlockId = block ? block.previous : '0000000000000000000000000000000000000000';
console.log('ref_block_num: ' + refBlockNum);
console.log('ref_block_prefix: ' + new Buffer(headBlockId, 'hex').readUInt32LE(4));
});
}
getProperties()
.then(getBlockAndPrefix);