• R/O
  • HTTP
  • SSH
  • HTTPS

Bytom-JS-SDK: Commit

It is a project for Bytom Chrome extension JS SDK https://bytom.github.io/Bytom-JS-SDK


Commit MetaInfo

Revision1bd6b83f4e2ada5ba48a2efef8f77def8f3ada1b (tree)
Zeit2020-06-15 14:42:01
AutorZhiting Lin <zlin035@uott...>
CommiterZhiting Lin

Log Message

update to v3

Ändern Zusammenfassung

Diff

--- a/src/api/accounts.js
+++ b/src/api/accounts.js
@@ -17,7 +17,7 @@ function accountsApi(http) {
1717 * @returns {Promise} Guid, address, label
1818 */
1919 accountsApi.prototype.create = function(params) {
20- return this.http.request('account/create-account', params);
20+ return this.http.request('account/create', params);
2121 };
2222
2323 /**
--- a/src/http.js
+++ b/src/http.js
@@ -1,5 +1,6 @@
11 import axios from 'axios';
22 import {handleApiError, handleAxiosError} from './utils/http';
3+import { camelize } from "./utils/utils";
34
45 // const basePath = 'api/v1/btm';
56
@@ -22,7 +23,7 @@ export function serverHttp(host) {
2223 if (resp.status !== 200 || resp.data.code !== 200) {
2324 throw handleApiError(resp);
2425 } else if (resp.data.code === 200) {
25- return resp.data.result.data;
26+ return camelize(resp.data.data);
2627 }
2728 return resp.data;
2829 }).catch(error=>{
@@ -50,7 +51,7 @@ export function http(baseUrl) {
5051 if (resp.status !== 200 || resp.data.code !== 200) {
5152 throw handleApiError(resp);
5253 } else if (resp.data.code === 200) {
53- return resp.data.result.data;
54+ return camelize(resp.data.data);
5455 }
5556 return resp.data;
5657 }).catch(error=>{
--- a/src/sdk/accounts.js
+++ b/src/sdk/accounts.js
@@ -50,9 +50,9 @@ accountsSDK.prototype.listAccountUseServer = function() {
5050 * @param {String} guid
5151 * @returns {Promise} list of all addresses
5252 */
53-accountsSDK.prototype.listAddressUseServer = function(guid) {
53+accountsSDK.prototype.listAddressUseServer = function(address) {
5454 let net = this.bytom.net;
55- return this.http.request('account/list-addresses', {guid:guid}, net);
55+ return this.http.request(`account/address?address=${address}`, '', net, 'GET');
5656 };
5757 /**
5858 * Create a new address for a wallet.
@@ -220,7 +220,7 @@ accountsSDK.prototype.listVaporAccountUseServer = function(guid) {
220220 let net = this.bytom.net;
221221 let that = this;
222222 let retPromise = new Promise((resolve, reject) => {
223- that.http.request('account/list-addresses', {guid:guid}, net).then(resp => {
223+ that.http.request('account/addresses', {address:address}, net).then(resp => {
224224 getDB().then(db => {
225225 let objectStore = db.transaction(['accounts-server'], 'readwrite').objectStore('accounts-server');
226226 let index = objectStore.index('guid');
--- a/src/sdk/keys.js
+++ b/src/sdk/keys.js
@@ -198,7 +198,7 @@ keysSDK.prototype.signMessage = function(message, password, address) {
198198 .getAll()
199199
200200 getRequest.onsuccess = function (e) {
201- const result = getRequest.result.filter(obj => obj.address === address)
201+ const result = getRequest.result.filter(obj => (obj.address === address || obj.vpAddress === address))
202202 if (result.length === 0) {
203203 reject(new Error('not found address'));
204204 return;
--- a/src/sdk/query.js
+++ b/src/sdk/query.js
@@ -34,7 +34,7 @@ querySDK.prototype.listUtxo = function(object) {
3434 */
3535 querySDK.prototype.getVoteStatus = function() {
3636 let net = this.bytom.net;
37- return this.http.request('q/get-vote-status',null, net, 'GET');
37+ return this.http.request('q/vote-status',null, net, 'GET');
3838 };
3939
4040 export default querySDK;
\ No newline at end of file
--- a/src/sdk/transaction.js
+++ b/src/sdk/transaction.js
@@ -19,9 +19,9 @@ function transactionSDK(bytom) {
1919 * @param {Number} limit page limit
2020 * @returns {Promise}
2121 */
22-transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
22+transactionSDK.prototype.list = function(address, filter,sort, start, limit) {
2323 let net = this.bytom.net;
24- let pm = {guid: guid};
24+ let pm = {}
2525
2626 if (filter) {
2727 pm.filter = filter;
@@ -31,7 +31,7 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
3131 pm.sort = sort;
3232 }
3333
34- let url = 'merchant/list-transactions';
34+ let url = 'merchant/transactions';
3535 let args = new URLSearchParams();
3636 if (typeof start !== 'undefined') {
3737 args.append('start', start);
@@ -39,6 +39,9 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
3939 if (limit) {
4040 args.append('limit', limit);
4141 }
42+ if (address) {
43+ args.append('address', address);
44+ }
4245 url = url + '?' + args.toString();
4346 return this.http.request(url, pm, net);
4447 };
@@ -51,10 +54,10 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
5154 * @param {String} raw_transaction raw transaction bytes encoded to string
5255 * @param {Array} signatures signed data of each signing instruction
5356 */
54-transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatures) {
57+transactionSDK.prototype.submitPayment = function(address, raw_transaction, signatures) {
5558 let net = this.bytom.net;
56- let pm = {guid: guid, raw_transaction: raw_transaction, signatures: signatures};
57- return this.http.request('merchant/submit-payment', pm, net);
59+ let pm = {raw_transaction: raw_transaction, signatures: signatures};
60+ return this.http.request(`merchant/submit-payment?address=${address}`, pm, net);
5861 };
5962
6063 /**
@@ -70,10 +73,9 @@ transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatu
7073 * @param {Number} confirmations - transaction confirmations
7174 * @returns {Promise}
7275 */
73-transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, confirmations, memo, forbidChainTx) {
76+transactionSDK.prototype.buildPayment = function(address, to, asset, amount, fee, confirmations, memo, forbidChainTx) {
7477 let net = this.bytom.net;
7578 let pm = {
76- guid: guid,
7779 asset: asset,
7880 recipients: {},
7981 forbid_chain_tx: false
@@ -93,7 +95,7 @@ transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, c
9395 if (confirmations) {
9496 pm.confirmations = confirmations;
9597 }
96- return this.http.request('merchant/build-payment', pm, net);
98+ return this.http.request(`merchant/build-payment?address=${address}`, pm, net);
9799 };
98100
99101 /**
@@ -106,11 +108,10 @@ transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, c
106108 * @param {Number} confirmations - transaction confirmations
107109 * @returns {Promise}
108110 */
109-transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, confirmations, forbidChainTx) {
111+transactionSDK.prototype.buildCrossChain = function(address, to, asset, amount, confirmations, forbidChainTx) {
110112 let net = this.bytom.net;
111113
112114 let pm = {
113- guid: guid,
114115 asset: asset,
115116 recipients: {},
116117 forbid_chain_tx: false
@@ -122,7 +123,7 @@ transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, con
122123 pm.forbid_chain_tx = forbidChainTx;
123124 }
124125
125- return this.http.request('merchant/build-crosschain', pm, net);
126+ return this.http.request(`merchant/build-crosschain?address=${address}`, pm, net);
126127 };
127128
128129 /**
@@ -135,9 +136,9 @@ transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, con
135136 * @param {Number} confirmations - transaction confirmations
136137 * @returns {Promise}
137138 */
138-transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations, memo, forbidChainTx) {
139+transactionSDK.prototype.buildVote = function(address, vote, amount, confirmations, memo, forbidChainTx) {
139140 let net = this.bytom.net;
140- let pm = {guid, vote, amount: amount, forbid_chain_tx: false};
141+ let pm = {vote, amount: amount, forbid_chain_tx: false};
141142 if (confirmations) {
142143 pm.confirmations = confirmations;
143144 }
@@ -148,7 +149,7 @@ transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations,
148149 pm.forbid_chain_tx = forbidChainTx;
149150 }
150151
151- return this.http.request('merchant/build-vote', pm, net);
152+ return this.http.request(`merchant/build-vote?address=${address}`, pm, net);
152153 };
153154
154155 /**
@@ -161,9 +162,9 @@ transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations,
161162 * @param {Number} confirmations - transaction confirmations
162163 * @returns {Promise}
163164 */
164-transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations, memo, forbidChainTx) {
165+transactionSDK.prototype.buildVeto = function(address, vote, amount, confirmations, memo, forbidChainTx) {
165166 let net = this.bytom.net;
166- let pm = {guid, vote, amount: amount, forbid_chain_tx: false};
167+ let pm = { vote, amount: amount, forbid_chain_tx: false};
167168 if (confirmations) {
168169 pm.confirmations = confirmations;
169170 }
@@ -174,7 +175,7 @@ transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations,
174175 pm.forbid_chain_tx = forbidChainTx;
175176 }
176177
177- return this.http.request('merchant/build-veto', pm, net);
178+ return this.http.request(`merchant/build-veto?address=${address}`, pm, net);
178179 };
179180
180181 /**
@@ -185,12 +186,12 @@ transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations,
185186 * @param {Number} fee transaction fee amount
186187 * @returns {Promise}
187188 */
188-transactionSDK.prototype.buildTransaction = function(guid, inputs, outputs, fee, confirmations ) {
189+transactionSDK.prototype.buildTransaction = function(address, inputs, outputs, fee, confirmations, forbid_chain_tx = true) {
189190 let net = this.bytom.net;
190191 let pm = {
191- guid,
192192 inputs,
193193 outputs,
194+ forbid_chain_tx
194195 };
195196 if (fee) {
196197 pm.fee = fee;
@@ -198,7 +199,7 @@ transactionSDK.prototype.buildTransaction = function(guid, inputs, outputs, fee,
198199 if (confirmations) {
199200 pm.confirmations = confirmations;
200201 }
201- return this.http.request('merchant/build-transaction', pm, net);
202+ return this.http.request(`merchant/build-advanced-tx?address=${address}`, pm, net);
202203 };
203204
204205 /**
--- /dev/null
+++ b/src/utils/utils.js
@@ -0,0 +1,19 @@
1+export const camelize = (object) => {
2+ for (let key in object) {
3+ let value = object[key];
4+ let newKey = key;
5+
6+ if (/_/.test(key)) {
7+ newKey = key.replace(/([_][a-z])/g, v => v[1].toUpperCase());
8+ delete object[key];
9+ }
10+
11+ if (typeof value == 'object') {
12+ value = camelize(value);
13+ }
14+
15+ object[newKey] = value;
16+ }
17+
18+ return object;
19+};
\ No newline at end of file
Show on old repository browser