OSDN Git Service

add readme and doc for accounts api
authorYongfeng LI <wliyongfeng@gmail.com>
Fri, 11 May 2018 06:40:15 +0000 (14:40 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Fri, 11 May 2018 06:40:15 +0000 (14:40 +0800)
README.md
src/api/account.js [deleted file]
src/api/accountsApi.js [new file with mode: 0644]
src/client.js

index ccadd05..741a6dc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1 +1,21 @@
-# bytom-sdk
+# Bytom Node.js SDK
+
+## Usage
+
+### In your code
+
+```
+const bytom = require('bytom-sdk')
+
+const client = new bytom.Client()
+```
+
+## Interaction with bytom
+
+### Acount
+
+```javascript
+client.account.listAccounts().then(resp => {
+  console.log(resp.data)
+})
+```
diff --git a/src/api/account.js b/src/api/account.js
deleted file mode 100644 (file)
index 197aba7..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-import ApiBase from './base'
-
-class Account {
-  constructor(connection) {
-    this.connection = connection
-  }
-
-  create(xpubs, quorum, alias) {
-    this.connection.request('/create-account', {
-      root_xpubs: xpubs,
-      quorum,
-      alias
-    })
-  }
-
-  listAccounts(id) {
-    this.connection.request('/list-accounts', {id})
-  }
-
-  createReceiverById(accountId) {
-    this.connection.request('/create-account-receiver', {
-      account_id: accountId
-    })
-  }
-
-  listAddressesById(accountId) {
-    this.connection.request('/list-addresses', {
-      account_id: accountId
-    })
-  }
-
-  deleteById(id) {
-    this.connection.request('/delete-account', {
-      account_info: id
-    })
-  }
-}
-
-export default Account
diff --git a/src/api/accountsApi.js b/src/api/accountsApi.js
new file mode 100644 (file)
index 0000000..fe38db9
--- /dev/null
@@ -0,0 +1,66 @@
+import ApiBase from './base'
+
+/**
+ * An account is an object in Bytom that tracks ownership of assets on a
+ * blockchain.
+ *
+ * @typedef {Object} Account
+ * @global
+ *
+ * @property {String} id
+ * Unique account identifier in one Bytom node.
+ *
+ * @property {String} alias
+ * User specified, unique identifier in one Bytom node.
+ *
+ * @property {Key[]} keys
+ * 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} quorum
+ * The number of keys required to sign transactions for the account.
+ *
+ */
+
+/**
+ * API for interacting with {@link Account accounts}.
+ *
+ * @module AccountsApi
+ */
+class AccountsApi {
+  constructor(connection) {
+    this.connection = connection
+  }
+
+  create(xpubs, quorum, alias) {
+    this.connection.request('/create-account', {
+      root_xpubs: xpubs,
+      quorum,
+      alias
+    })
+  }
+
+  listAccounts(id) {
+    this.connection.request('/list-accounts', {id})
+  }
+
+  createReceiverById(accountId) {
+    this.connection.request('/create-account-receiver', {
+      account_id: accountId
+    })
+  }
+
+  listAddressesById(accountId) {
+    this.connection.request('/list-addresses', {
+      account_id: accountId
+    })
+  }
+
+  deleteById(id) {
+    this.connection.request('/delete-account', {
+      account_info: id
+    })
+  }
+}
+
+export default AccountsApi
index c747356..a303ac3 100644 (file)
@@ -1,11 +1,11 @@
 import Connection from 'connection'
-import Account from 'api/account'
+import AccountsApi from 'api/account'
 
 class Client {
   constructor(baseUrl, token) {
     this.connection = new Connection(baseUrl, token)
 
-    this.account = new Account(this.connection)
+    this.account = new AccountsApi(this.connection)
   }
 }