2 * @typedef {Object} BlockInfo
4 * @property {String} - hash, hash of block.
5 * @property {Integer} - size, size of block.
6 * @property {Integer} - version, version of block.
7 * @property {Integer} - height, height of block.
8 * @property {String} - previous_block_hash, previous block hash.
9 * @property {Integer} - timestamp, timestamp of block.
10 * @property {Integer} - nonce, nonce value.
11 * @property {Integer} - bits, bits of difficulty.
12 * @property {String} - difficulty, difficulty value(String type).
13 * @property {String} - transaction_merkle_root, merkle root of transaction.
14 * @property {String} - transaction_status_hash, merkle root of transaction status.
15 * @property {Object[]} - transactions, transaction object:
16 * {String} - id, transaction id, hash of the transaction.
17 * {Integer} - version, version of transaction.
18 * {Integer} - size, size of transaction.
19 * {Integer} - time_range, the unix timestamp for when the requst was responsed.
20 * {Boolean} - status_fail, whether the state of the request has failed.
21 * {String} - mux_id, the previous transaction mux id(source id of utxo).
22 * @property {Object[]} - inputs, object of inputs for the transaction.
23 * {String} - type, the type of input action, available option include: 'spend', 'issue', 'coinbase'.
24 * {String} - asset_id, asset id.
25 * {String} - asset_alias, name of asset.
26 * {Object} - asset_definition, definition of asset(json object).
27 * {Integer} - amount, amount of asset.
28 * {Object} - issuance_program, issuance program, it only exist when type is 'issue'.
29 * {Object} - control_program, control program of account, it only exist when type is 'spend'.
30 * {String} - address, address of account, it only exist when type is 'spend'.
31 * {String} - spent_output_id, the front of outputID to be spent in this input, it only exist when type is 'spend'.
32 * {String} - account_id, account id.
33 * {String} - account_alias, name of account.
34 * {Object} - arbitrary, arbitrary infomation can be set by miner, it only exist when type is 'coinbase'.
35 * {String} - input_id, hash of input action.
36 * {String[]} - witness_arguments, witness arguments.
37 * @property {Object[]} - outputs, object of outputs for the transaction.
38 * {String} - type, the type of output action, available option include: 'retire', 'control'.
39 * {String} - id, outputid related to utxo.
40 * {Integer} - position, position of outputs.
41 * {String} - asset_id, asset id.
42 * {String} - asset_alias, name of asset.
43 * {Object} - asset_definition, definition of asset(json object).
44 * {Integer} - amount, amount of asset.
45 * {String} - account_id, account id.
46 * {String} - account_alias, name of account.
47 * {Object} - control_program, control program of account.
48 * {String} - address, address of account.
54 const blockAPI = (connection) => {
57 * Returns the current block height for blockchain.
59 * @returns {Promise} Promise resolved on success with block_count returned.
61 getBlockCount: () => connection.request('/get-block-count', {}),
65 * Returns the current block hash for blockchain.
67 * @returns {Promise} Requested info of specified Chain Core with block_hash returned.
69 getBlockHash: () => connection.request('/get-block-hash', {} ),
72 * Returns the detail block by block height or block hash.
75 * @param {String} params.block_hash, hash of block.
76 * @param {Integer} params.block_height, height of block.
77 * @returns {Promise<BlockInfo>}
79 getBlock: (params) => connection.request('/get-block', params),
82 * Returns the detail block header by block height or block hash.
85 * @param {String} params.block_hash, hash of block.
86 * @param {Integer} params.block_height, height of block.
89 getBlockHeader: (params) => connection.request('/get-block-header', params),
92 * Returns the block difficulty by block height or block hash.
95 * @param {String} params.block_hash, hash of block.
96 * @param {Integer} params.block_height, height of block.
99 getDifficulty: (params) => connection.request('/get-difficulty', params),
102 * Returns the block hash rate by block height or block hash,
103 * it returns the current block hash rate when request is empty.
106 * @param {String} params.block_hash, hash of block.
107 * @param {Integer} params.block_height, height of block.
110 getHashRate: (params) => connection.request('/get-hash-rate', params)
114 module.exports = blockAPI