OSDN Git Service

update node-sdk
[bytom/bytom-node-sdk.git] / src / api / assets.js
1 /**
2  * An asset is a type of value that can be issued on a blockchain. All units of
3  * a given asset are fungible. Units of an asset can be transacted directly
4  * between parties without the involvement of the issuer.
5  *
6  * @typedef {Object} Asset
7  * @global
8  *
9  * @property {String} id
10  * Globally unique identifier of the asset.
11  * Asset specifies the asset id as the hash of:
12  * - the asset's issuance program
13  * - the core's VM version
14  * - the hash of asset definition
15  *
16  * @property {String} alias
17  * User specified, unique identifier in one Bytom node.
18  *
19  * @property {String} issuanceProgram
20  *
21  * @property {Key[]} keys
22  * The list of keys used to issue units of the asset.
23  *
24  * @property {Number} quorum
25  * The number of signatures required to issue new units of the asset.
26  *
27  * @property {Object} defintion
28  * User-specified, arbitrary/unstructured data visible across Bytom
29  * blockchain networks. assets specify the definition in their
30  * issuance programs, rendering the definition immutable.
31  */
32
33 /**
34  * API for interacting with {@link Asset assets}.
35  *
36  * @module AssetsApi
37  */
38 const assetsApi = (connection) => {
39
40   /**
41    * @typedef {Object} createRequest
42    *
43    * @property {String} [alias]
44    * User specified, unique identifier.
45    *
46    * @property {Object} [defintion]
47    * User-specified, arbitrary/unstructured data visible across blockchain networks.
48    *
49    * @property {String[]} root_xpubs
50    * Optional. The list of keys used to create the asset.
51    *
52    * @property {Number} quorum
53    * Optional. the default value is 1, threshold of keys that must sign a transaction to spend asset units controlled by the account.
54    *
55    * @property {String} [issuance_program]
56    * Optional. User-specified, contract program.
57    *
58    */
59
60   return {
61     /**
62      * Create a new asset.
63      *
64      * @param {module:AssetsApi~createRequest} params - Parameters for asset creation.
65      * @returns {Promise<Asset>} Newly created asset.
66      */
67     create: (params) => connection.request('/create-asset', params),
68
69     /**
70      * List all assets in one Bytom node.
71      *
72      * @returns {Promise<Array<Asset>>} target assets.
73      */
74     listAll: () => connection.request('/list-assets', {}),
75
76     /**
77      * Get asset by the asset id.
78      *
79      * @param {module:AssetsApi~id} id - Asset id.
80      * @returns {Promise<Asset>} target asset.
81      */
82     list: (id) => connection.request('/get-asset', {id}),
83
84     /**
85      * Update asset alias.
86      *
87      * @param {object} params - Parameters for asset update.
88      * @param {String} params.id - id of asset.
89      * @param {String} params.alias - new alias of asset.
90      */
91     updateAlias: (params) => connection.request('/update-asset-alias', params)
92   }
93 }
94
95 export default assetsApi