OSDN Git Service

add readme and doc for accounts api
[bytom/bytom-node-sdk.git] / src / api / accountsApi.js
1 import ApiBase from './base'
2
3 /**
4  * An account is an object in Bytom that tracks ownership of assets on a
5  * blockchain.
6  *
7  * @typedef {Object} Account
8  * @global
9  *
10  * @property {String} id
11  * Unique account identifier in one Bytom node.
12  *
13  * @property {String} alias
14  * User specified, unique identifier in one Bytom node.
15  *
16  * @property {Key[]} keys
17  * The list of keys used to create control programs under the account.
18  * Signatures from these keys are required for spending funds held in the account.
19  *
20  * @property {Number} quorum
21  * The number of keys required to sign transactions for the account.
22  *
23  */
24
25 /**
26  * API for interacting with {@link Account accounts}.
27  *
28  * @module AccountsApi
29  */
30 class AccountsApi {
31   constructor(connection) {
32     this.connection = connection
33   }
34
35   create(xpubs, quorum, alias) {
36     this.connection.request('/create-account', {
37       root_xpubs: xpubs,
38       quorum,
39       alias
40     })
41   }
42
43   listAccounts(id) {
44     this.connection.request('/list-accounts', {id})
45   }
46
47   createReceiverById(accountId) {
48     this.connection.request('/create-account-receiver', {
49       account_id: accountId
50     })
51   }
52
53   listAddressesById(accountId) {
54     this.connection.request('/list-addresses', {
55       account_id: accountId
56     })
57   }
58
59   deleteById(id) {
60     this.connection.request('/delete-account', {
61       account_info: id
62     })
63   }
64 }
65
66 export default AccountsApi