OSDN Git Service

update to v3
authorZhiting Lin <zlin035@uottawa.ca>
Mon, 15 Jun 2020 05:42:01 +0000 (13:42 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Mon, 15 Jun 2020 05:42:01 +0000 (13:42 +0800)
src/api/accounts.js
src/http.js
src/sdk/accounts.js
src/sdk/keys.js
src/sdk/query.js
src/sdk/transaction.js
src/utils/utils.js [new file with mode: 0644]

index 4bf61c2..580a5cf 100644 (file)
@@ -17,7 +17,7 @@ function accountsApi(http) {
  * @returns {Promise} Guid, address, label
  */
 accountsApi.prototype.create = function(params) {
-    return this.http.request('account/create-account', params);
+    return this.http.request('account/create', params);
 };
 
 /**
index 6cf7d09..a505842 100644 (file)
@@ -1,5 +1,6 @@
 import axios from 'axios';
 import {handleApiError, handleAxiosError} from './utils/http';
+import { camelize } from "./utils/utils";
 
 // const basePath = 'api/v1/btm';
 
@@ -22,7 +23,7 @@ export function serverHttp(host) {
                 if (resp.status !== 200 || resp.data.code !== 200) {
                     throw handleApiError(resp);
                 } else if (resp.data.code === 200) {
-                    return resp.data.result.data;
+                    return camelize(resp.data.data);
                 }
                 return resp.data;
             }).catch(error=>{
@@ -50,7 +51,7 @@ export function http(baseUrl) {
                 if (resp.status !== 200 || resp.data.code !== 200) {
                     throw handleApiError(resp);
                 } else if (resp.data.code === 200) {
-                    return resp.data.result.data;
+                    return camelize(resp.data.data);
                 }
                 return resp.data;
             }).catch(error=>{
index cc40873..febeb6d 100644 (file)
@@ -50,9 +50,9 @@ accountsSDK.prototype.listAccountUseServer = function() {
  * @param {String} guid
  * @returns {Promise} list of all addresses
  */
-accountsSDK.prototype.listAddressUseServer = function(guid) {
+accountsSDK.prototype.listAddressUseServer = function(address) {
     let net = this.bytom.net;
-    return this.http.request('account/list-addresses', {guid:guid}, net);
+    return this.http.request(`account/address?address=${address}`, '', net, 'GET');
 };
 /**
  * Create a new address for a wallet.
@@ -220,7 +220,7 @@ accountsSDK.prototype.listVaporAccountUseServer = function(guid) {
     let net = this.bytom.net;
     let that = this;
     let retPromise = new Promise((resolve, reject) => {
-        that.http.request('account/list-addresses', {guid:guid}, net).then(resp => {
+        that.http.request('account/addresses', {address:address}, net).then(resp => {
             getDB().then(db => {
                 let objectStore = db.transaction(['accounts-server'], 'readwrite').objectStore('accounts-server');
                 let index = objectStore.index('guid');
index e5ec7ee..cef6546 100644 (file)
@@ -198,7 +198,7 @@ keysSDK.prototype.signMessage = function(message, password, address) {
                 .getAll()
 
             getRequest.onsuccess = function (e) {
-                const result = getRequest.result.filter(obj => obj.address === address)
+                const result = getRequest.result.filter(obj => (obj.address === address || obj.vpAddress === address))
                 if (result.length === 0) {
                     reject(new Error('not found address'));
                     return;
index a4e0292..a726ad2 100644 (file)
@@ -34,7 +34,7 @@ querySDK.prototype.listUtxo = function(object) {
  */
 querySDK.prototype.getVoteStatus = function() {
     let net = this.bytom.net;
-    return this.http.request('q/get-vote-status',null, net,  'GET');
+    return this.http.request('q/vote-status',null, net,  'GET');
 };
 
 export default querySDK;
\ No newline at end of file
index 12aa42e..b2bccaa 100644 (file)
@@ -19,9 +19,9 @@ function transactionSDK(bytom) {
  * @param {Number} limit page limit
  * @returns {Promise}
  */
-transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
+transactionSDK.prototype.list = function(address, filter,sort, start, limit) {
     let net = this.bytom.net;
-    let pm = {guid: guid};
+    let pm = {}
 
     if (filter) {
         pm.filter = filter;
@@ -31,7 +31,7 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
         pm.sort = sort;
     }
 
-    let url = 'merchant/list-transactions';
+    let url = 'merchant/transactions';
     let args = new URLSearchParams();
     if (typeof start !== 'undefined') {
         args.append('start', start);
@@ -39,6 +39,9 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
     if (limit) {
         args.append('limit', limit);
     }
+    if (address) {
+        args.append('address', address);
+    }
     url = url + '?' + args.toString();
     return this.http.request(url, pm, net);
 };
@@ -51,10 +54,10 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
  * @param {String} raw_transaction raw transaction bytes encoded to string
  * @param {Array} signatures signed data of each signing instruction
  */
-transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatures) {
+transactionSDK.prototype.submitPayment = function(address, raw_transaction, signatures) {
     let net = this.bytom.net;
-    let pm = {guid: guid, raw_transaction: raw_transaction, signatures: signatures};
-    return this.http.request('merchant/submit-payment', pm, net);
+    let pm = {raw_transaction: raw_transaction, signatures: signatures};
+    return this.http.request(`merchant/submit-payment?address=${address}`, pm, net);
 };
 
 /**
@@ -70,10 +73,9 @@ transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatu
  * @param {Number} confirmations - transaction confirmations
  * @returns {Promise}
  */
-transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, confirmations, memo, forbidChainTx) {
+transactionSDK.prototype.buildPayment = function(address, to, asset, amount, fee, confirmations, memo, forbidChainTx) {
     let net = this.bytom.net;
     let pm = {
-        guid: guid,
         asset: asset,
         recipients: {},
         forbid_chain_tx: false
@@ -93,7 +95,7 @@ transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, c
     if (confirmations) {
         pm.confirmations = confirmations;
     }
-    return this.http.request('merchant/build-payment', pm, net);
+    return this.http.request(`merchant/build-payment?address=${address}`, pm, net);
 };
 
 /**
@@ -106,11 +108,10 @@ transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, c
  * @param {Number} confirmations - transaction confirmations
  * @returns {Promise}
  */
-transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, confirmations, forbidChainTx) {
+transactionSDK.prototype.buildCrossChain = function(address, to, asset, amount, confirmations, forbidChainTx) {
     let net = this.bytom.net;
 
     let pm = {
-        guid: guid,
         asset: asset,
         recipients: {},
         forbid_chain_tx: false
@@ -122,7 +123,7 @@ transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, con
         pm.forbid_chain_tx = forbidChainTx;
     }
 
-    return this.http.request('merchant/build-crosschain', pm, net);
+    return this.http.request(`merchant/build-crosschain?address=${address}`, pm, net);
 };
 
 /**
@@ -135,9 +136,9 @@ transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, con
  * @param {Number} confirmations - transaction confirmations
  * @returns {Promise}
  */
-transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations, memo, forbidChainTx) {
+transactionSDK.prototype.buildVote = function(address, vote, amount, confirmations, memo, forbidChainTx) {
     let net = this.bytom.net;
-    let pm = {guid, vote, amount: amount, forbid_chain_tx: false};
+    let pm = {vote, amount: amount, forbid_chain_tx: false};
     if (confirmations) {
         pm.confirmations = confirmations;
     }
@@ -148,7 +149,7 @@ transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations,
       pm.forbid_chain_tx = forbidChainTx;
     }
 
-    return this.http.request('merchant/build-vote', pm, net);
+    return this.http.request(`merchant/build-vote?address=${address}`, pm, net);
 };
 
 /**
@@ -161,9 +162,9 @@ transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations,
  * @param {Number} confirmations - transaction confirmations
  * @returns {Promise}
  */
-transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations, memo,  forbidChainTx) {
+transactionSDK.prototype.buildVeto = function(address, vote, amount, confirmations, memo,  forbidChainTx) {
     let net = this.bytom.net;
-    let pm = {guid, vote, amount: amount, forbid_chain_tx: false};
+    let pm = { vote, amount: amount, forbid_chain_tx: false};
     if (confirmations) {
         pm.confirmations = confirmations;
     }
@@ -174,7 +175,7 @@ transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations,
         pm.forbid_chain_tx = forbidChainTx;
       }
 
-    return this.http.request('merchant/build-veto', pm, net);
+    return this.http.request(`merchant/build-veto?address=${address}`, pm, net);
 };
 
 /**
@@ -185,12 +186,12 @@ transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations,
  * @param {Number} fee transaction fee amount
  * @returns {Promise}
  */
-transactionSDK.prototype.buildTransaction = function(guid, inputs, outputs, fee, confirmations ) {
+transactionSDK.prototype.buildTransaction = function(address, inputs, outputs, fee, confirmations, forbid_chain_tx = true) {
     let net = this.bytom.net;
     let pm = {
-        guid,
         inputs,
         outputs,
+        forbid_chain_tx
     };
     if (fee) {
         pm.fee = fee;
@@ -198,7 +199,7 @@ transactionSDK.prototype.buildTransaction = function(guid, inputs, outputs, fee,
     if (confirmations) {
         pm.confirmations = confirmations;
     }
-    return this.http.request('merchant/build-transaction', pm, net);
+    return this.http.request(`merchant/build-advanced-tx?address=${address}`, pm, net);
 };
 
 /**
diff --git a/src/utils/utils.js b/src/utils/utils.js
new file mode 100644 (file)
index 0000000..bc28bf8
--- /dev/null
@@ -0,0 +1,19 @@
+export const camelize = (object) => {
+    for (let key in object) {
+        let value = object[key];
+        let newKey = key;
+
+        if (/_/.test(key)) {
+            newKey = key.replace(/([_][a-z])/g, v => v[1].toUpperCase());
+            delete object[key];
+        }
+
+        if (typeof value == 'object') {
+            value = camelize(value);
+        }
+
+        object[newKey] = value;
+    }
+
+    return object;
+};
\ No newline at end of file