-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitcoind-getblock.js
More file actions
28 lines (24 loc) · 1016 Bytes
/
bitcoind-getblock.js
File metadata and controls
28 lines (24 loc) · 1016 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
import {QUESTION_PASSWORD, postGot, getJsonRpcOptionsGot} from './util.js';
import {question} from 'readline-sync';
const main = async function () {
const block = process.argv[2];
if (isNaN(block)) {
console.error('Block missing!');
process.exit();
}
const password = question(QUESTION_PASSWORD, {hideEchoBack: true});
let options = getJsonRpcOptionsGot('getblockhash', [Number(block)], password);
let response = await postGot(options);
if (200 === response.statusCode) {
const blockhash = response.body.result;
options = getJsonRpcOptionsGot('getblock', [blockhash], password);
response = await postGot(options);
if (200 === response.statusCode) {
const blockdata = response.body.result;
const txArray = response.body.result.tx;
console.log('Tx', txArray.length, 'Tx0', txArray[0]);
console.log('Block', blockdata.height, '@', new Date(blockdata.time * 1000));
}
}
}
main();