OSDN Git Service

update node-sdk
authorZhiting Lin <zlin035@uottawa.ca>
Fri, 23 Nov 2018 08:35:36 +0000 (16:35 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Fri, 23 Nov 2018 08:35:36 +0000 (16:35 +0800)
src/api/accessTokens.js
src/api/accounts.js
src/api/assets.js
src/api/balances.js
src/api/block.js [new file with mode: 0644]
src/api/config.js [new file with mode: 0644]
src/api/keys.js
src/api/transactions.js
src/api/unspentOutputs.js
test/account.js [new file with mode: 0644]

index 4a3c819..b4ee47f 100644 (file)
@@ -24,10 +24,12 @@ const accessTokensApi = (connection) => {
     /**
      * Create a new access token.
      *
-     * @param {String} id - User specified, unique identifier.
+     * @param {Object} params - Access Token Object.
+     * @param {String} params.id - User specified, unique identifier.
+     * @param {String} params.type - type of token.
      * @returns {Promise<AccessToken>} Newly created access token.
      */
-    create: (id) => connection.request('/create-access-token', {id}),
+    create: (params) => connection.request('/create-access-token', params),
 
     /**
      * Get all access tokens.
@@ -39,9 +41,18 @@ const accessTokensApi = (connection) => {
     /**
      * Delete the target access token.
      *
-     * @param {String} id - The to be deleted token id.
+     * @param {String} id- The to be deleted token id.
      */
-    delete: (id) => connection.request('/delete-access-token', {id})
+    delete: (id) => connection.request('/delete-access-token', {id}),
+
+    /**
+     * Check the target access token.
+     *
+     * @param {Object} params - Parameters for access token check.
+     * @param {String} params.id - The to be deleted token id.
+     * @param {String} params.secret, secret of token, the second part of the colon division for token.
+     */
+    check: (params) => connection.request('/check-access-token', params),
   }
 }
 
index c057229..e89c605 100644 (file)
  */
 const accountsApi = (connection) => {
   /**
+   * @typedef {Object} createRequest
+   *
+   * @property {String} [alias]
+   * User specified, unique identifier.
+   *
+   * @property {String[]} root_xpubs
+   * The list of keys used to create control programs under the account.
+   *
+   * @property {Number} quorum
+   * The number of keys required to sign transactions for the account.
+   */
+
+
+  /**
+   * @typedef {Object} createReceiverRequest
+   *
+   * @property {String} [account_alias]
+   * The unique alias of the account. accountAlias or accountId must be
+   * provided.
+   *
+   * @property {String} [account_id]
+   * The unique ID of the account. accountAlias or accountId must be
+   * provided.
+   */
+
+
+  /**
    * @typedef {String[]} xpubs
    * The list of keys used to create control programs under the account.
    */
@@ -74,16 +101,10 @@ const accountsApi = (connection) => {
     /**
      * Create a new account.
      *
-     * @param {module:AccountsApi~xpubs} xpubs - Xpub of 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.
+     * @param {module:AccountsApi~createRequest} params - Parameters for account creation.
      * @returns {Promise<Account>} Newly created account response.
      */
-    create: (xpubs, quorum, alias) => connection.request('/create-account', {
-      root_xpubs: xpubs,
-      quorum,
-      alias
-    }),
+    create: (params) => connection.request('/create-account', params),
 
     /**
      * List all accounts in the target Bytom node.
@@ -95,31 +116,64 @@ const accountsApi = (connection) => {
     /**
      * List accounts whose id is the given one.
      *
-     * @param {module:AccountsApi~id} id - Account id.
+     * @param {Object} params={} - Filter and pagination information.
+     * @param {String} params.id - Account id.
+     * @param {String} params.alias - Account alias.
      * @return {Promise<Array<Account>>} Target accounts promise.
      */
-    listById: (id) => connection.request('/list-accounts', {id}),
+    list: (params) => connection.request('/list-accounts', params),
 
     /**
      * Create account receiver.
      *
-     * @param {module:AccountsApi~id} accountId - Id for the target account.
+     * @param {module:AccountsApi~createReceiverRequest} params - Parameters for receiver creation.
      * @return {Promise<Receiver>} Target receiver.
      */
-    createReceiverById: (accountId) => connection.request('/create-account-receiver', {account_id: accountId}),
+    createReceiver: (params) => connection.request('/create-account-receiver', params),
+
+    /**
+     * List all addresses for one account.
+     *
+     * @param {Object} params={} - Filter and pagination information.
+     * @param {String} params.account_alias, alias of account.
+     * @param {String} params.account_id, id of account.
+     * @param {Number} params.from, the start position of first address
+     * @param {Number} params.count, the number of returned.
+     * @return {Promise<module:AccountApi~AddressInfo>} target addresses response.
+     *
+     */
+    listAddresses: (params) => connection.request('/list-addresses', params),
 
     /**
      * List all addresses for one account.
-     * @param {module:AccountsApi~id} accountId - Id for the target account.
+     *
+     * @param {Object} params={} - Filter and pagination information.
+     * @param {String} params.account_alias, alias of account.
+     * @param {String} params.account_id, id of account.
+     * @param {Number} params.from, the start position of first address
+     * @param {Number} params.count, the number of returned.
      * @return {Promise<module:AccountApi~AddressInfo>} target addresses response.
+     *
      */
-    listAddressesById: (accountId) => connection.request('/list-addresses', {account_id: accountId}),
+    validateAddresses: (address) => connection.request('/validate-addresses', {address: address}),
 
     /**
      * Delete account.
-     * @param {module:AccountsApi~id} id - Target account id.
+     * @param {Object} params={} - Deletion information.
+     * @param {String} params.account_id - Account id.
+     * @param {String} params.account_alias - Account alias.
+     */
+    delete: (params) => connection.request('/delete-account', params),
+
+    /**
+     * Update account alias.
+     *
+     * @param {object} params - Parameters for account update.
+     * @param {String} params.account_id - id of account.
+     * @param {String} params.account_alias - alias of account.
+     * @param {String} params.new_alias - new alias of account.
      */
-    deleteById: (id) => connection.request('/delete-account', {account_info: id})
+    updateAlias: (params) => connection.request('/update-account-alias', params)
   }
 }
 
index e84f46e..33cd1a2 100644 (file)
  * @module AssetsApi
  */
 const assetsApi = (connection) => {
-  /**
-   * @typedef {String[]} xpubs
-   * The list of keys used to issue units of the asset.
-   */
 
   /**
-   * @typedef {String} [alias]
+   * @typedef {Object} createRequest
+   *
+   * @property {String} [alias]
    * User specified, unique identifier.
-   */
-
-  /**
-   * @typedef {Number} quorum
-   * The number of signatures required to issue new units of the asset.
-   */
-
-  /**
-   * @typedef {String} id
-   * Unique account identifier in one Bytom node.
-   */
-
-  /**
-   * @typedef {Object} definition
-   * User-specified, asset attributes accross Bytom blockchain network.
+   *
+   * @property {Object} [defintion]
+   * User-specified, arbitrary/unstructured data visible across blockchain networks.
+   *
+   * @property {String[]} root_xpubs
+   * Optional. The list of keys used to create the asset.
+   *
+   * @property {Number} quorum
+   * Optional. the default value is 1, threshold of keys that must sign a transaction to spend asset units controlled by the account.
+   *
+   * @property {String} [issuance_program]
+   * Optional. User-specified, contract program.
+   *
    */
 
   return {
     /**
      * Create a new asset.
      *
-     * @param {module:AssetsApi~xpubs} xpubs - Keys for asseet creation.
-     * @param {module:AssetsApi~quorum} quorum - The number of keys required to sign transactions for the account.
-     * @param {module:AssetsApi~alias} alias - Asset alias.
-     * @param {module:AssetsApi~definition} definition - Asset definition.
+     * @param {module:AssetsApi~createRequest} params - Parameters for asset creation.
      * @returns {Promise<Asset>} Newly created asset.
      */
-    create: (xpubs, quorum, alias, definition) => connection.request('/create-asset', {
-      alias,
-      quorum,
-      definition,
-      root_xpubs: xpubs
-    }),
+    create: (params) => connection.request('/create-asset', params),
 
     /**
      * List all assets in one Bytom node.
      *
      * @returns {Promise<Array<Asset>>} target assets.
      */
-    list: () => connection.request('/list-assets', {}),
+    listAll: () => connection.request('/list-assets', {}),
 
     /**
      * Get asset by the asset id.
@@ -91,15 +79,16 @@ const assetsApi = (connection) => {
      * @param {module:AssetsApi~id} id - Asset id.
      * @returns {Promise<Asset>} target asset.
      */
-    getById: (id) => connection.request('/get-asset', {id}),
+    list: (id) => connection.request('/get-asset', {id}),
 
     /**
      * Update asset alias.
      *
-     * @param {module:AssetsApi~id} id - Asset id.
-     * @param {String} newAlias - new alias.
+     * @param {object} params - Parameters for asset update.
+     * @param {String} params.id - id of asset.
+     * @param {String} params.alias - new alias of asset.
      */
-    updateAlias: (id, newAlias) => connection.request('/update-asset-alias', {id, alias: newAlias})
+    updateAlias: (params) => connection.request('/update-asset-alias', params)
   }
 }
 
index e7a776a..e225a6b 100644 (file)
 const balancesApi = (connection) => {
   return {
     /**
-     * Get all asset balances of all accounts.
+     * Get asset balances by account.
      *
+     * @param {Object} params={} - Filter and pagination information.
+     * @param {String} params.account_id, account id.
+     * @param {String} params.account_alias, name of account.
      * @returns {Promise<Array<Balance>>} The result balances.
      */
-    list: () => connection.request('/list-balances', {})
+    list: (params) => connection.request('/list-balances', params),
+
+    /**
+     * List all assets Balances in one Bytom node.
+     *
+     * @returns {Promise<Array<Balance>>} The result balances.
+     */
+    listAll: () => connection.request('/list-balances', {})
   }
 }
 
diff --git a/src/api/block.js b/src/api/block.js
new file mode 100644 (file)
index 0000000..8b986a8
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * @typedef {Object} BlockInfo
+ *
+ * @property {String} - hash, hash of block.
+ * @property {Integer} - size, size of block.
+ * @property {Integer} - version, version of block.
+ * @property {Integer} - height, height of block.
+ * @property {String} - previous_block_hash, previous block hash.
+ * @property {Integer} - timestamp, timestamp of block.
+ * @property {Integer} - nonce, nonce value.
+ * @property {Integer} - bits, bits of difficulty.
+ * @property {String} - difficulty, difficulty value(String type).
+ * @property {String} - transaction_merkle_root, merkle root of transaction.
+ * @property {String} - transaction_status_hash, merkle root of transaction status.
+ * @property {Object[]} - transactions, transaction object:
+ *                     {String} - id, transaction id, hash of the transaction.
+ *                     {Integer} - version, version of transaction.
+ *                     {Integer} - size, size of transaction.
+ *                     {Integer} - time_range, the unix timestamp for when the requst was responsed.
+ *                     {Boolean} - status_fail, whether the state of the request has failed.
+ *                     {String} - mux_id, the previous transaction mux id(source id of utxo).
+ * @property {Object[]} - inputs, object of inputs for the transaction.
+ *                     {String} - type, the type of input action, available option include: 'spend', 'issue', 'coinbase'.
+ *                     {String} - asset_id, asset id.
+ *                     {String} - asset_alias, name of asset.
+ *                     {Object} - asset_definition, definition of asset(json object).
+ *                     {Integer} - amount, amount of asset.
+ *                     {Object} - issuance_program, issuance program, it only exist when type is 'issue'.
+ *                     {Object} - control_program, control program of account, it only exist when type is 'spend'.
+ *                     {String} - address, address of account, it only exist when type is 'spend'.
+ *                     {String} - spent_output_id, the front of outputID to be spent in this input, it only exist when type is 'spend'.
+ *                     {String} - account_id, account id.
+ *                     {String} - account_alias, name of account.
+ *                     {Object} - arbitrary, arbitrary infomation can be set by miner, it only exist when type is 'coinbase'.
+ *                     {String} - input_id, hash of input action.
+ *                     {String[]} - witness_arguments, witness arguments.
+ * @property {Object[]} - outputs, object of outputs for the transaction.
+ *                     {String} - type, the type of output action, available option include: 'retire', 'control'.
+ *                     {String} - id, outputid related to utxo.
+ *                     {Integer} - position, position of outputs.
+ *                     {String} - asset_id, asset id.
+ *                     {String} - asset_alias, name of asset.
+ *                     {Object} - asset_definition, definition of asset(json object).
+ *                     {Integer} - amount, amount of asset.
+ *                     {String} - account_id, account id.
+ *                     {String} - account_alias, name of account.
+ *                     {Object} - control_program, control program of account.
+ *                     {String} - address, address of account.
+
+ */
+
+
+
+const blockAPI = (connection) => {
+  return {
+    /**
+     * Returns the current block height for blockchain.
+     *
+     * @returns {Promise} Promise resolved on success with block_count returned.
+     */
+    getBlockCount: () => connection.request('/get-block-count', {}),
+
+
+    /**
+     * Returns the current block hash for blockchain.
+     *
+     * @returns {Promise} Requested info of specified Chain Core with block_hash returned.
+     */
+    getBlockHash: () => connection.request('/get-block-hash', {} ),
+
+    /**
+     * Returns the detail block by block height or block hash.
+     *
+     * @param params
+     * @param {String} params.block_hash, hash of block.
+     * @param {Integer} params.block_height, height of block.
+     * @returns {Promise<BlockInfo>}
+     */
+    getBlock: (params) => connection.request('/get-block', params),
+
+    /**
+     * Returns the detail block header by block height or block hash.
+     *
+     * @param params
+     * @param {String} params.block_hash, hash of block.
+     * @param {Integer} params.block_height, height of block.
+     * @returns {Promise}
+     */
+    getBlockHeader: (params) => connection.request('/get-block-header', params),
+
+    /**
+     * Returns the block difficulty by block height or block hash.
+     *
+     * @param params
+     * @param {String} params.block_hash, hash of block.
+     * @param {Integer} params.block_height, height of block.
+     * @returns {Promise}
+     */
+    getDifficulty: (params) => connection.request('/get-difficulty', params),
+
+    /**
+     * Returns the block hash rate by block height or block hash,
+     * it returns the current block hash rate when request is empty.
+     *
+     * @param params
+     * @param {String} params.block_hash, hash of block.
+     * @param {Integer} params.block_height, height of block.
+     * @returns {Promise}
+     */
+    getHashRate: (params) => connection.request('/get-hash-rate', params)
+  }
+}
+
+module.exports = blockAPI
\ No newline at end of file
diff --git a/src/api/config.js b/src/api/config.js
new file mode 100644 (file)
index 0000000..f05b612
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * Basic information about the configuration of Bytom Core, as well as any
+ * errors encountered when updating the local state of the blockchain
+ *
+ * More info: {}
+ * @typedef {Object} CoreInfo
+ *
+ * @property {Boolean} listening, whether the node is listening.
+ * @property {Boolean} syncing, whether the node is syncing.
+ * @property {Boolean} mining, whether the node is mining.
+ * @property {Integer} peer_count, current count of connected peers.
+ * @property {Integer} current_block, current block height in the node's blockchain.
+ * @property {Integer} highest_block, current highest block of the connected peers.
+ * @property {String} network_id, network id.
+ * @property {Object} version_info, bytomd version information:
+ * @property {String} version, current version of the running bytomd.
+ * @property {uint16} update, whether there exists an update.
+ *                      0: no update;
+ *                      1: small update;
+ *                      2: significant update.
+ * @property {String} new_version, the newest version of bytomd if there is one.
+ */
+
+/**
+ * Bytom Core can be configured as a new blockchain network, or as a node in an
+ * existing blockchain network.
+ *
+ * More info: {}
+ * @module ConfigApi
+ */
+const configAPI = (connection) => {
+  return {
+    /**
+     * get gas rate
+     * @returns {Promise} Promise resolved with gas rate on success.
+     */
+    gasRate: () => connection.request('/gas-rate', {}),
+
+
+    /**
+     * Get info on specified Bytom Core.
+     *
+     * @param {objectCallback} [callback] - Optional callback. Use instead of Promise return value as desired.
+     * @returns {Promise<CoreInfo>} Requested info of specified Bytom Core.
+     */
+    netInfo: () => connection.request('/net-info',{}),
+
+    /**
+     *
+     * @param params
+     * @param {String} params.address, address for account.
+     * @param {String} params.derived_xpub, derived xpub.
+     * @param {String} params.message, message for signature by derived_xpub.
+     * @param {String} params.signature, signature for message.
+     * @returns {*|AxiosPromise<any>}
+     */
+    verifyMessage: (params) => connection.request('verify-message', params)
+  }
+}
+
+module.exports = configAPI
\ No newline at end of file
index 638b2ed..ad9ed8d 100644 (file)
  * @module KeysApi
  */
 const keysApi = connection => {
+  /**
+   * @typedef {Object} createRequest
+   *
+   * @property {String} [alias]
+   * User specified, unique identifier.
+   *
+   * @property {String} [password]
+   * password of the key.
+   *
+   * @property {String} [language]
+   * mnemonic language of the key.
+   *
+   * @option params [String] mnemonic
+   * mnemonic of the key, create key by specified mnemonic.
+   */
+
   return {
     /**
      * Create a new key.
      *
-     * @param {String} alias - User specified, unique identifier.
-     * @param {String} password - User specified, key password.
+     * @param {module:KeysApi~createRequest} params - Parameters for asset creation.
      * @returns {Promise<Key>} Newly created key.
      */
-    create: (alias, password) => connection.request('/create-key', {alias, password}),
+    create: (params) => connection.request('/create-key', params),
 
     /**
      * Got all the keys in one Bytom node.
      * @returns {Promise<Array<Key>>} All keys.
      */
-    list: () => connection.request('/list-keys'),
+    listAll: () => connection.request('/list-keys'),
 
     /**
+     * @param {Object} params={} - Deletion information.
+     * @param {String} params.xpub - Hex-encoded string representation of the key.
+     * @param {String} params.password - Key password.
+     */
+    delete: (params) => connection.request('/delete-key', params),
+
+    /**
+     * Reset key password.
      *
-     * @param {String} xpub - Hex-encoded string representation of the key.
-     * @param {String} password - Key password.
+     * @param {Object} params={} - Password checking information.
+     * @param {String} params.xpub - Hex-encoded string representation of the key.
+     * @param {String} params.password - password.
      */
-    delete: (xpub, password) => connection.request('/delete-key', {xpub, password}),
+    checkPassword: (params) => connection.request('/check-key-password', params),
 
     /**
      * Reset key password.
      *
-     * @param {String} xpub - Hex-encoded string representation of the key.
-     * @param {String} oldPassword - Old password.
-     * @param {String} newPassword - New password.
+     * @param {Object} params={} - Key password reset information.
+     * @param {String} params.xpub - Hex-encoded string representation of the key.
+     * @param {String} params.oldPassword - Old password.
+     * @param {String} params.newPassword - New password.
      */
-    resetPassword: (xpub, oldPassword, newPassword) => connection.request('/reset-key-password', {
-      xpub,
-      old_password: oldPassword,
-      new_password: newPassword
-    })
+    resetPassword: (params) => connection.request('/reset-key-password', params)
   }
 }
 
index 9171c04..613a20f 100644 (file)
  */
 
 /**
+ * @class
+ * A convenience class for building transaction template objects.
+ */
+class TransactionBuilder {
+  /**
+   * constructor - return a new object used for constructing a transaction.
+   */
+  constructor() {
+    this.actions = []
+
+
+    /**
+     * nteger of the time to live in milliseconds, it means utxo will be reserved(locked) for
+     * builded transaction in this time range, if the transaction will not to be submitted into block,
+     * it will be auto unlocked for build transaction again after this ttl time. it will be set to
+     * 5 minutes(300 seconds) defaultly when ttl is 0.
+     * @type {Integer}
+     */
+    // this.ttl = 0
+    this.ttl = 1
+
+    /**
+     * Base transaction provided by a third party.
+     * @type {Object}
+     */
+    this.baseTransaction = null
+  }
+
+  /**
+   * Add an action that issues assets.
+   *
+   * @param {Object} params - Action parameters.
+   * @param {String} params.assetId - Asset ID specifying the asset to be issued.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.assetAlias - Asset alias specifying the asset to be issued.
+   *                                      You must specify either an ID or an alias.
+   * @param {String} params.amount - Amount of the asset to be issued.
+   */
+  issue(params) {
+    this.actions.push(Object.assign({}, params, {type: 'issue'}))
+  }
+
+  /**
+   * Add an action that controls assets with an account specified by identifier.
+   *
+   * @param {Object} params - Action parameters.
+   *
+   * @param {String} params.asset_alias - Asset alias specifying the asset to be controlled.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.asset_id - Asset ID specifying the account controlling the asset.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.address - Account address specifying the account controlling the asset.
+   *                                   You must specify either an ID or an alias.
+   * @param {Number} params.amount - Amount of the asset to be controlled.
+   */
+  controlWithAddress(params) {
+    this.actions.push(Object.assign({}, params, {type: 'control_address'}))
+  }
+
+  /**
+   * Add an action that controls assets with a receiver.
+   *
+   * @param {Object} params - Action parameters.
+   *
+   * @param {Object} params.control_program - The receiver object in which assets will be controlled.
+   *
+   * @param {String} params.asset_id - Asset ID specifying the asset to be controlled.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.asset_alias - Asset alias specifying the asset to be controlled.
+   *                                   You must specify either an ID or an alias.
+   * @param {Number} params.amount - Amount of the asset to be controlled.
+   */
+  controlWithControlProgram(params) {
+    this.actions.push(Object.assign({}, params, {type: 'control_program"'}))
+  }
+
+  /**
+   * Add an action that spends assets from an account specified by identifier.
+   *
+   * @param {Object} params - Action parameters.
+   * @param {String} params.asset_id - Asset ID specifying the asset to be spent.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.asset_alias - Asset alias specifying the asset to be spent.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.account_id - Account ID specifying the account spending the asset.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.account_alias - Account alias specifying the account spending the asset.
+   *                                   You must specify either an ID or an alias.
+   * @param {Number} params.amount - Amount of the asset to be spent.
+   */
+  spendFromAccount(params) {
+    this.actions.push(Object.assign({}, params, {type: 'spend_account'}))
+  }
+
+  /**
+   * Add an action that spends an unspent output.
+   *
+   * @param {Object} params - Action parameters.
+   * @param {String} params.output_id - ID of the transaction output to be spent.
+   */
+  spendUnspentOutput(params) {
+    this.actions.push(Object.assign({}, params, {type: 'spend_account_unspent_output'}))
+  }
+
+  /**
+   * Add an action that retires units of an asset.
+   *
+   * @param {Object} params - Action parameters.
+   * @param {String} params.asset_id - Asset ID specifying the asset to be retired.
+   *                                   You must specify either an ID or an alias.
+   * @param {String} params.asset_alias - Asset alias specifying the asset to be retired.
+   *                                   You must specify either an ID or an alias.
+   * @param {Number} params.amount - Amount of the asset to be retired.
+   *
+   * @option params [String] - arbitrary Any message string, can be empty.
+   */
+  retire(params) {
+    this.actions.push(Object.assign({}, params, {type: 'retire'}))
+  }
+}
+
+/**
  * API for interacting with {@link Transaction transactions}.
  *
  * @module TransactionsApi
@@ -148,31 +270,37 @@ const transactionsApi = connection => {
    * Whether all input actions are signed. It means this transaction can be submit if true, else not.
    */
 
-  const ONE_MINUTE = 1000 * 60
-
   return {
     /**
-     * Build an unsigned transaction from a set of actions and base transction(possibly null).
+     * Build an unsigned transaction from a set of actions.
      *
-     * @param {String} baseTransaction - Encoded base raw transaction.
-     * @param {module:TransactionsApi~Action[]} actions - Set of actions to compose the transaction.
-     * @param {Number} ttl - Time duration to spent UTXOs will be reserverd(can't be spent during this time duration).
-     * @returns {Promise<Object>} - Unsigned transaction template.
+     * @param {module:TransactionsApi~builderCallback} builderBlock - Function that adds desired actions
+     *                                         to a given builder object.
+     * @param {objectCallback} [callback] - Optional callback. Use instead of Promise return value as desired.
+     * @returns {Promise<Object>} Unsigned transaction template, or error.
      */
-    build: (baseTransaction = null, actions, ttl = ONE_MINUTE * 2) => connection.request('/build-transaction', {
-      base_transaction: baseTransaction,
-      actions,
-      ttl
-    }),
+    build: (builderBlock) => {
+      const builder = new TransactionBuilder()
+
+      try {
+        builderBlock(builder)
+      } catch (err) {
+        return Promise.reject(err)
+      }
+
+      return connection.request('/build-transaction', builder)
+    },
+
 
     /**
      * Sign transaction.
      *
-     * @param {Object} transaction - The built transaction template.
-     * @param {Object} password - Password of the key which will sign the transaction template.
+     * @param {Object} params - The built transaction template.
+     * @param {String} params.password, signature of the password.
+     * @param {Object} params.transaction, builded transaction.
      * @returns {Promise<module:TransactionsApi~SignResult>} - Sign result.
      */
-    sign: (transaction, password) => connection.request('/sign-transaction', {transaction, password}),
+    sign: (params) => connection.request('/sign-transaction', params),
 
     /**
      * Submit a signed transaction to the blockchain.
@@ -196,23 +324,22 @@ const transactionsApi = connection => {
      *
      * @returns {Promise<Transaction[]>} All local transactions.
      */
-    listAll: () => connection.request('/list-transactions', {}),
+    listAll: () => connection.request('/list-transactions', {unconfirmed: true}),
 
     /**
      * List local transactions by id.
      *
-     * @param {String} id - The transaction id.
-     * @returns {Promise<Transaction[]>} The result transactions.
-     */
-    listById: (id) => connection.request('/list-transactions', {id}),
-
-    /**
-     * List all local transactions by account id.
-     *
-     * @param {String} accountId - Account id.
+     * @param {Object} params - Transaction filter params.
+     * @param {String} params.id - transaction id, hash of transaction.
+     * @param {String} params.account_id - id of account.
+     * @param {Boolean} params.detail -  flag of detail transactions, default false (only return transaction summary).
+     * @param {Boolean} params.unconfirmed -  flag of unconfirmed transactions(query result include all confirmed
+     *                  and unconfirmed transactions), default false.
+     * @param {Integer} params.from - The start position of first transaction.
+     * @param {Integer} params.count - The number of returned.
      * @returns {Promise<Transaction[]>} The result transactions.
      */
-    listByAccountId: (accountId) => connection.request('list-transactions', {account_id: accountId})
+    list: (params) => connection.request('/list-transactions', params),
   }
 }
 
index 2afa264..2376688 100644 (file)
@@ -58,14 +58,22 @@ const unspentOutputsAPI = (connection) => {
      * Get all unspent outputs.
      * @returns {Promise<Array<UnspentOutput>>} Target unspent outputs.
      */
-    list: () => connection.request('/list-unspent-outputs', {}),
+    listAll: () => connection.request('/list-unspent-outputs', {}),
 
     /**
-     * Get target unspent outputs by id.
-     * @param {String} id - Unspent output id.
+     * Get target unspent outputs.
+     *
+     * @param {Object} params={} - Filter and pagination information.
+     * @param {String} params.id - Unspent output id.
+     * @param {Boolean} params.unconfirmed, is include unconfirmed utxo
+     * @param {Boolean} params.smart_contract, is contract utxo
+     * @param {Integer} params.from, the start position of first utxo
+     * @param {Integer} params.count, the number of returned
+     * @param {String} params.account_id, account id.
+     * @param {String} params.account_alias, name of account.
      * @returns {Promise<Array<UnspentOutput>>} Target unspent outputs.
      */
-    listById: (id) => connection.request('list-unspent-outputs', {id})
+    list: (params) => connection.request('list-unspent-outputs', params)
   }
 }
 
diff --git a/test/account.js b/test/account.js
new file mode 100644 (file)
index 0000000..e69de29