OSDN Git Service

update the document
[bytom/bytom-node-sdk.git] / src / api / unspentOutputs.js
1 /**
2  * Each new transaction in the blockchain consumes some unspent outputs and
3  * creates others. An output is considered unspent when it has not yet been used
4  * as an input to a new transaction. All asset units on a blockchain exist in
5  * the unspent output set.
6  *
7  * @typedef {Object} UnspentOutput
8  * @global
9  *
10  * @property {String} account_alias
11  * The alias of the account transferring the asset (possibly null).
12  *
13  * @property {String} account_id
14  * The id of the account transferring the asset (possibly null).
15  *
16  * @property {String} address
17  * The output address.
18  *
19  * @property {String} id
20  * Unique transaction identifier.
21  *
22  * @property {Number} amount
23  * The number of units of the asset being issued or spent.
24  *
25  * @property {String} asset_alias
26  * The alias of the asset being issued or spent (possibly null).
27  *
28  * @property {String} asset_id
29  * The id of the asset being issued or spent.
30  *
31  * @property {Number} source_pos
32  * The output's position in a transaction's list of outputs.
33  *
34  * @property {Boolean} change
35  * Whether this output is asset change of one spend.
36  *
37  * @property {Number} control_program_index
38  * Control program index.
39  *
40  * @property {String} program
41  * The control program which must be satisfied to transfer this output.
42  *
43  * @property {String} source_id
44  * The source unspent output id.
45  *
46  * @property {Number} valid_height
47  * It means coinbase utxo if valid_height > 0.
48  */
49
50 /**
51  * API for interacting with {@link UnspentOutput unspent outputs}.
52  *
53  * @module UnspentOutputsApi
54  */
55 const unspentOutputsAPI = (connection) => {
56   return {
57     /**
58      * Get all unspent outputs.
59      * @returns {Promise<Array<UnspentOutput>>} Target unspent outputs.
60      */
61     listAll: () => connection.request('/list-unspent-outputs', {}),
62
63     /**
64      * Get target unspent outputs.
65      *
66      * @param {Object} params={} - Filter and pagination information.
67      * @param {String} params.id - Unspent output id.
68      * @param {Boolean} params.unconfirmed, is include unconfirmed utxo
69      * @param {Boolean} params.smart_contract, is contract utxo
70      * @param {Integer} params.from, the start position of first utxo
71      * @param {Integer} params.count, the number of returned
72      * @param {String} params.account_id, account id.
73      * @param {String} params.account_alias, name of account.
74      * @returns {Promise<Array<UnspentOutput>>} Target unspent outputs.
75      */
76     list: (params) => connection.request('list-unspent-outputs', params)
77   }
78 }
79
80 export default unspentOutputsAPI