OSDN Git Service

0a266e6f57544bd26b99741d10f5475ddb9960ca
[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) => connection.request('/create-account', {
58       root_xpubs: xpubs,
59       quorum,
60       alias
61     }),
62
63     /**
64      * List accounts whose id starts with the given id.
65      *
66      * @param {module:AccountsApi~id} id - Account id prefix.
67      * @return {Promise<Response>} target accounts response.
68      */
69     listAccounts: (id) => connection.request('/list-accounts', {id}),
70
71     /**
72      * Create account receiver.
73      *
74      * @param {module:AccountsApi~id} accountId - Id for the target account.
75      * @return {Promise<Response>} target receiver response.
76      */
77     createReceiverById: (accountId) => connection.request('/create-account-receiver', {account_id: accountId}),
78
79     /**
80      * List all addresses for one account.
81      * @param {module:AccountsApi~id} accountId - Id for the target account.
82      * @return {Promise<Response>} target addresses response.
83      */
84     listAddressesById: (accountId) => connection.request('/list-addresses', {account_id: accountId}),
85
86     /**
87      * Delete account.
88      * @param {module:AccountsApi~id} id - Target account id.
89      */
90     deleteById: (id) => connection.request('/delete-account', {account_info: id})
91   }
92 }
93
94 export default Accounts