OSDN Git Service

8b986a85f0d9ab1844952116bd7ba3a61e9bd6a3
[bytom/bytom-node-sdk.git] / src / api / block.js
1 /**
2  * @typedef {Object} BlockInfo
3  *
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.
49
50  */
51
52
53
54 const blockAPI = (connection) => {
55   return {
56     /**
57      * Returns the current block height for blockchain.
58      *
59      * @returns {Promise} Promise resolved on success with block_count returned.
60      */
61     getBlockCount: () => connection.request('/get-block-count', {}),
62
63
64     /**
65      * Returns the current block hash for blockchain.
66      *
67      * @returns {Promise} Requested info of specified Chain Core with block_hash returned.
68      */
69     getBlockHash: () => connection.request('/get-block-hash', {} ),
70
71     /**
72      * Returns the detail block by block height or block hash.
73      *
74      * @param params
75      * @param {String} params.block_hash, hash of block.
76      * @param {Integer} params.block_height, height of block.
77      * @returns {Promise<BlockInfo>}
78      */
79     getBlock: (params) => connection.request('/get-block', params),
80
81     /**
82      * Returns the detail block header by block height or block hash.
83      *
84      * @param params
85      * @param {String} params.block_hash, hash of block.
86      * @param {Integer} params.block_height, height of block.
87      * @returns {Promise}
88      */
89     getBlockHeader: (params) => connection.request('/get-block-header', params),
90
91     /**
92      * Returns the block difficulty by block height or block hash.
93      *
94      * @param params
95      * @param {String} params.block_hash, hash of block.
96      * @param {Integer} params.block_height, height of block.
97      * @returns {Promise}
98      */
99     getDifficulty: (params) => connection.request('/get-difficulty', params),
100
101     /**
102      * Returns the block hash rate by block height or block hash,
103      * it returns the current block hash rate when request is empty.
104      *
105      * @param params
106      * @param {String} params.block_hash, hash of block.
107      * @param {Integer} params.block_height, height of block.
108      * @returns {Promise}
109      */
110     getHashRate: (params) => connection.request('/get-hash-rate', params)
111   }
112 }
113
114 module.exports = blockAPI