OSDN Git Service

fix accountsApi doc
[bytom/bytom-node-sdk.git] / src / api / accounts.js
1 /**
2  * An account is an object in Bytom that tracks ownership of assets on a
3  * blockchain.
4  *
5  * @typedef {Object} Account
6  * @global
7  *
8  * @property {String} id
9  * Unique account identifier in one Bytom node.
10  *
11  * @property {String} alias
12  * User specified, unique identifier in one Bytom node.
13  *
14  * @property {Key[]} keys
15  * The list of keys used to create control programs under the account.
16  * Signatures from these keys are required for spending funds held in the account.
17  *
18  * @property {Number} quorum
19  * The number of keys required to sign transactions for the account.
20  */
21
22 /**
23  * API for interacting with {@link Account accounts}.
24  *
25  * @module AccountsApi
26  */
27 const Accounts = (connection) => {
28   /**
29    * @typedef {String[]} xpubs
30    * The list of keys used to create control programs under the account.
31    */
32
33   /**
34    * @typedef {String} [alias]
35    * User specified, unique identifier.
36    */
37
38   /**
39    * @typedef {Number} quorum
40    * The number of keys required to sign transactions for the account.
41    */
42
43   /**
44    * @typedef {String} id
45    * Unique account identifier in one Bytom node.
46    */
47
48   return {
49     /**
50      * Create a new account.
51      *
52      * @param {module:AccountsApi~xpubs} xpubs - Keys for account creation.
53      * @param {module:AccountsApi~quorum} quorum - The number of keys required to sign transactions for the account.
54      * @param {module:AccountsApi~alias} alias - Account alias.
55      * @returns {Promise<Response>} Newly created account response.
56      */
57     create(xpubs, quorum, alias) {
58       this.connection.request('/create-account', {
59         root_xpubs: xpubs,
60         quorum,
61         alias
62       })
63     },
64
65     /**
66      * List accounts whose id starts with the given id.
67      *
68      * @param {module:AccountsApi~id} id - Account id prefix.
69      * @return {Promise<Response>} target accounts response.
70      */
71     listAccounts(id) {
72       this.connection.request('/list-accounts', {id})
73     },
74
75     /**
76      * Create account receiver.
77      *
78      * @param {module:AccountsApi~id} accountId - Id for the target account.
79      * @return {Promise<Response>} target receiver response.
80      */
81     createReceiverById(accountId) {
82       this.connection.request('/create-account-receiver', {
83         account_id: accountId
84       })
85     },
86
87     /**
88      * List all addresses for one account.
89      * @param {module:AccountsApi~id} accountId - Id for the target account.
90      * @return {Promise<Response>} target addresses response.
91      */
92     listAddressesById(accountId) {
93       this.connection.request('/list-addresses', {
94         account_id: accountId
95       })
96     },
97
98     /**
99      * Delete account.
100      * @param {module:AccountsApi~id} id - Target account id.
101      */
102     deleteById(id) {
103       this.connection.request('/delete-account', {
104         account_info: id
105       })
106     }
107   }
108 }
109
110 export default Accounts