OSDN Git Service

improve accounts api doc
authorYongfeng LI <wliyongfeng@gmail.com>
Tue, 15 May 2018 07:50:50 +0000 (15:50 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Tue, 15 May 2018 07:50:50 +0000 (15:50 +0800)
src/api/accounts.js

index 624fd7f..e002acc 100644 (file)
  * The list of keys used to create control programs under the account.
  * Signatures from these keys are required for spending funds held in the account.
  *
+ * @property {Number} key_index
+ * The index of keys.
+ *
  * @property {Number} quorum
  * The number of keys required to sign transactions for the account.
  */
 
 /**
+ * A receiver is an object that wraps an account control program with the corresponding address.
+ *
+ * @typedef {Object} Receiver
+ *
+ * @property {String} control_program
+ * The underlying control program that will be used in transactions paying to the address.
+ *
+ * @property {String} address
+ * The target address one transaction can pay UTXO to.
+ */
+
+/**
  * API for interacting with {@link Account accounts}.
  *
  * @module AccountsApi
@@ -45,6 +60,16 @@ const accountsApi = (connection) => {
    * Unique account identifier in one Bytom node.
    */
 
+  /**
+   * @typedef {Object} AddressInfo
+   *
+   * @property {String} account_alias
+   * @property {String} account_id
+   * @property {String} adddress
+   * @property {Boolean} change
+   * Indicate whether this address is for change UTXO.
+   */
+
   return {
     /**
      * Create a new account.
@@ -52,7 +77,7 @@ const accountsApi = (connection) => {
      * @param {module:AccountsApi~xpubs} xpubs - Keys for account creation.
      * @param {module:AccountsApi~quorum} quorum - The number of keys required to sign transactions for the account.
      * @param {module:AccountsApi~alias} alias - Account alias.
-     * @returns {Promise<Response>} Newly created account response.
+     * @returns {Promise<Account>} Newly created account response.
      */
     create: (xpubs, quorum, alias) => connection.request('/create-account', {
       root_xpubs: xpubs,
@@ -61,25 +86,32 @@ const accountsApi = (connection) => {
     }),
 
     /**
-     * List accounts whose id starts with the given id.
+     * List all accounts in the target Bytom node.
+     *
+     * @returns {Promise<Array<Account>>} All accounts promise.
+     */
+    listAll: () => connection.request('/list-accounts', {}),
+
+    /**
+     * List accounts whose id is the given one.
      *
-     * @param {module:AccountsApi~id} id - Account id prefix.
-     * @return {Promise<Response>} target accounts response.
+     * @param {module:AccountsApi~id} id - Account id.
+     * @return {Promise<Array<Account>>} Target accounts promise.
      */
-    listAccounts: (id) => connection.request('/list-accounts', {id}),
+    listById: (id) => connection.request('/list-accounts', {id}),
 
     /**
      * Create account receiver.
      *
      * @param {module:AccountsApi~id} accountId - Id for the target account.
-     * @return {Promise<Response>} target receiver response.
+     * @return {Promise<Receiver>} Target receiver.
      */
     createReceiverById: (accountId) => connection.request('/create-account-receiver', {account_id: accountId}),
 
     /**
      * List all addresses for one account.
      * @param {module:AccountsApi~id} accountId - Id for the target account.
-     * @return {Promise<Response>} target addresses response.
+     * @return {Promise<module:AccountApi~AddressInfo>} target addresses response.
      */
     listAddressesById: (accountId) => connection.request('/list-addresses', {account_id: accountId}),