openchain-nodejs-ts-yxl 1.0.8 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +20 -0
- package/lib/common/util.js +693 -685
- package/lib/util/index.js +57 -119
- package/package.json +1 -1
package/lib/common/util.js
CHANGED
@@ -4,15 +4,18 @@ const axios = require('axios');
|
|
4
4
|
const is = require('is-type-of');
|
5
5
|
const long = require('long');
|
6
6
|
const JSONbig = require('json-bigint');
|
7
|
+
// const bigNumberToString = require('bignumber-to-string')
|
7
8
|
const BigNumber = require('bignumber.js');
|
8
9
|
const protobuf = require("protobufjs");
|
9
10
|
const tou8 = require('buffer-to-uint8array');
|
10
11
|
const humps = require('humps');
|
11
|
-
const {
|
12
|
+
const {keypair, signature} = require('phcer-encryption');
|
12
13
|
const errors = require('../exception');
|
13
14
|
|
15
|
+
|
14
16
|
const proto = exports;
|
15
17
|
|
18
|
+
|
16
19
|
/**
|
17
20
|
* GET/POST request
|
18
21
|
*
|
@@ -21,414 +24,402 @@ const proto = exports;
|
|
21
24
|
* @param {Object} data
|
22
25
|
* @return {Object}
|
23
26
|
*/
|
24
|
-
|
27
|
+
// 替换原有request实现
|
28
|
+
proto._request = async function(method, endpoint, data) {
|
25
29
|
try {
|
26
|
-
const
|
27
|
-
const uri = `${protocol}${this.options.host}/${path}`;
|
28
|
-
|
29
|
-
if (!is.string(method) || this._isEmptyString(method)) {
|
30
|
-
throw new Error('method must be a non-empty string');
|
31
|
-
}
|
32
|
-
|
33
|
-
if (!is.string(path) || this._isEmptyString(path)) {
|
34
|
-
throw new Error('path must be a non-empty string');
|
35
|
-
}
|
36
|
-
|
37
|
-
const methods = ['get', 'post'];
|
38
|
-
|
39
|
-
if (!methods.includes(method.toLowerCase())) {
|
40
|
-
throw new Error(`${method} http method is not supported`);
|
41
|
-
}
|
42
|
-
|
43
|
-
const options = {
|
30
|
+
const response = await axios({
|
44
31
|
method,
|
45
|
-
url:
|
46
|
-
|
47
|
-
};
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
if (method.toLowerCase() === 'post') {
|
54
|
-
options.data = data;
|
55
|
-
}
|
56
|
-
|
57
|
-
const response = await axios(options);
|
58
|
-
const result = response.data;
|
59
|
-
const obj = typeof result === 'string' ? JSONbig.parse(result) : result;
|
60
|
-
const error_code = obj.error_code;
|
61
|
-
const final = this._bigNumberToString(obj);
|
62
|
-
final.error_code = error_code;
|
63
|
-
return final;
|
64
|
-
} catch (err) {
|
65
|
-
throw err;
|
32
|
+
url: `${this.options.host}/${endpoint}`,
|
33
|
+
data
|
34
|
+
});
|
35
|
+
return response.data;
|
36
|
+
} catch (error) {
|
37
|
+
throw this._handleRequestError(error);
|
66
38
|
}
|
67
39
|
};
|
68
40
|
|
69
|
-
proto._response = function(obj) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
41
|
+
proto._response = function (obj) {
|
42
|
+
const data = {
|
43
|
+
errorCode: obj.error_code || 0,
|
44
|
+
errorDesc: obj.error_desc || 'Success',
|
45
|
+
};
|
74
46
|
|
75
|
-
|
76
|
-
|
77
|
-
|
47
|
+
if (is.object(obj) && obj.error_code) {
|
48
|
+
if (obj.error_code === 0) {
|
49
|
+
data.result = obj.result || {};
|
50
|
+
} else {
|
51
|
+
data.errorDesc = obj.error_desc || '';
|
52
|
+
data.result = {};
|
53
|
+
}
|
78
54
|
} else {
|
79
|
-
|
80
|
-
data.result = {};
|
55
|
+
data.result = obj;
|
81
56
|
}
|
82
|
-
} else {
|
83
|
-
data.result = obj;
|
84
|
-
}
|
85
57
|
|
86
|
-
|
58
|
+
return JSONbig.stringify(data);
|
87
59
|
};
|
88
60
|
|
89
61
|
proto._getBlockNumber = function* () {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
62
|
+
try {
|
63
|
+
const data = yield this._request('get', 'getLedger');
|
64
|
+
if (data && data.error_code === 0) {
|
65
|
+
const seq = data.result.header.seq;
|
66
|
+
return this._responseData({
|
67
|
+
header: {
|
68
|
+
blockNumber: seq,
|
69
|
+
},
|
70
|
+
});
|
71
|
+
} else {
|
72
|
+
return this._responseError(errors.INTERNAL_ERROR);
|
73
|
+
}
|
74
|
+
} catch (err) {
|
75
|
+
throw err;
|
101
76
|
}
|
102
|
-
} catch (err) {
|
103
|
-
throw err;
|
104
|
-
}
|
105
77
|
};
|
106
78
|
|
107
|
-
proto._isEmptyString = function(str) {
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
79
|
+
proto._isEmptyString = function (str) {
|
80
|
+
if (!is.string(str)) {
|
81
|
+
throw new Error('str must be a string');
|
82
|
+
}
|
83
|
+
return (str.trim().length === 0);
|
112
84
|
};
|
113
85
|
|
114
|
-
proto._postData = function(blob, signature) {
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
86
|
+
proto._postData = function (blob, signature) {
|
87
|
+
const data = {
|
88
|
+
items: [
|
89
|
+
{
|
90
|
+
transaction_blob: blob,
|
91
|
+
signatures: signature
|
92
|
+
},
|
93
|
+
],
|
94
|
+
};
|
95
|
+
return JSONbig.stringify(data);
|
124
96
|
};
|
125
97
|
|
126
98
|
proto._isBigNumber = function (object) {
|
127
|
-
|
128
|
-
|
99
|
+
return object instanceof BigNumber ||
|
100
|
+
(object && object.constructor && object.constructor.name === 'BigNumber');
|
129
101
|
};
|
130
102
|
|
131
|
-
proto._toBigNumber = function(number) {
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
103
|
+
proto._toBigNumber = function (number) {
|
104
|
+
number = number || 0;
|
105
|
+
//
|
106
|
+
if (this._isBigNumber(number)) {
|
107
|
+
return number;
|
108
|
+
}
|
109
|
+
return new BigNumber(number);
|
138
110
|
};
|
139
111
|
|
140
|
-
proto._stringFromBigNumber = function(number) {
|
141
|
-
|
112
|
+
proto._stringFromBigNumber = function (number) {
|
113
|
+
return this._toBigNumber(number).toString(10);
|
142
114
|
};
|
143
115
|
|
144
|
-
proto._verifyValue = function(str) {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
116
|
+
proto._verifyValue = function (str) {
|
117
|
+
const reg = /^[1-9]\d*$/;
|
118
|
+
return (
|
119
|
+
is.string(str) &&
|
120
|
+
reg.test(str) &&
|
121
|
+
long.fromValue(str).greaterThan(0) &&
|
122
|
+
long.fromValue(str).lessThanOrEqual(long.MAX_VALUE)
|
123
|
+
);
|
152
124
|
};
|
153
125
|
|
154
|
-
proto._isAvailableValue = function(str, from
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
126
|
+
proto._isAvailableValue = function (str, from = -1, to = long.MAX_VALUE) {
|
127
|
+
const reg = /^(0|([1-9]\d*))$/
|
128
|
+
return (
|
129
|
+
is.string(str) &&
|
130
|
+
reg.test(str) &&
|
131
|
+
long.fromValue(str).greaterThan(from) &&
|
132
|
+
long.fromValue(str).lessThanOrEqual(to)
|
133
|
+
);
|
162
134
|
};
|
163
135
|
|
164
136
|
proto._checkParams = function (obj) {
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
137
|
+
for (let prop in obj) {
|
138
|
+
if (obj.hasOwnProperty(prop)) {
|
139
|
+
let value = obj[prop];
|
140
|
+
if (!is.undefined(value)) {
|
141
|
+
if (!this._verifyValue(value)) {
|
142
|
+
throw new Error(errors.INVALID_FORMAT_OF_ARG.msg);
|
143
|
+
}
|
144
|
+
}
|
171
145
|
}
|
172
|
-
}
|
173
146
|
}
|
174
|
-
}
|
175
147
|
};
|
176
148
|
|
177
149
|
proto._getDefaultValue = function* () {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
150
|
+
try {
|
151
|
+
let ledgerInfo = yield this._request('get', 'getLedger', {
|
152
|
+
with_fee: true,
|
153
|
+
});
|
154
|
+
const gasPrice = long.fromValue(ledgerInfo.result.fees.gas_price);
|
155
|
+
const feeLimit = long.fromValue(1000).mul(gasPrice);
|
156
|
+
return {
|
157
|
+
gasPrice,
|
158
|
+
feeLimit,
|
159
|
+
}
|
160
|
+
} catch (err) {
|
161
|
+
throw err;
|
187
162
|
}
|
188
|
-
} catch (err) {
|
189
|
-
throw err;
|
190
|
-
}
|
191
163
|
};
|
192
164
|
|
193
|
-
proto._responseData = function(data) {
|
194
|
-
|
195
|
-
|
165
|
+
proto._responseData = function (data) {
|
166
|
+
const errorCode = 0;
|
167
|
+
const errorDesc = '';
|
196
168
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
169
|
+
return {
|
170
|
+
errorCode,
|
171
|
+
errorDesc,
|
172
|
+
result: data,
|
173
|
+
}
|
202
174
|
};
|
203
175
|
|
204
|
-
proto._responseError = function(message) {
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
176
|
+
proto._responseError = function (message) {
|
177
|
+
if (!message) {
|
178
|
+
throw new Error('require message');
|
179
|
+
}
|
180
|
+
const errorCode = message.CODE;
|
209
181
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
182
|
+
return {
|
183
|
+
errorCode,
|
184
|
+
errorDesc: message.MSG,
|
185
|
+
};
|
214
186
|
};
|
215
187
|
|
216
188
|
proto._submitTransaction = function* (data) {
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
189
|
+
try {
|
190
|
+
const res = yield this._request('post', 'submitTransaction', data);
|
191
|
+
const results = res.results;
|
192
|
+
if (Array.isArray(results) && results.length > 0) {
|
193
|
+
const info = results[0];
|
194
|
+
|
195
|
+
if (info.error_code === '0') {
|
196
|
+
return this._responseData({
|
197
|
+
hash: info.hash,
|
198
|
+
});
|
199
|
+
}
|
200
|
+
|
201
|
+
return {
|
202
|
+
errorCode: info.error_code,
|
203
|
+
errorDesc: info.error_desc,
|
204
|
+
};
|
205
|
+
}
|
228
206
|
|
229
|
-
|
230
|
-
|
231
|
-
errorDesc: info.error_desc,
|
232
|
-
};
|
207
|
+
} catch (err) {
|
208
|
+
throw err;
|
233
209
|
}
|
234
210
|
|
235
|
-
} catch (err) {
|
236
|
-
throw err;
|
237
|
-
}
|
238
|
-
|
239
211
|
};
|
240
212
|
|
241
|
-
proto._buildOperation = function(type, data) {
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
213
|
+
proto._buildOperation = function (type, data) {
|
214
|
+
try {
|
215
|
+
// 使用静态导入的操作类型映射,而不是动态require
|
216
|
+
const operationModule = require('./operation')(type);
|
217
|
+
return operationModule(data);
|
218
|
+
} catch (err) {
|
219
|
+
console.log(err);
|
220
|
+
throw new Error('Operation cannot be resolved');
|
221
|
+
}
|
248
222
|
};
|
249
223
|
|
250
|
-
proto._decodeOperation = function(hexString) {
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
224
|
+
proto._decodeOperation = function (hexString) {
|
225
|
+
const root = protobuf.Root.fromJSON(require('../crypto/protobuf/bundle.json'));
|
226
|
+
const operation = root.lookupType('protocol.Operation');
|
227
|
+
const msgBuffer = Buffer.from(hexString, 'hex');
|
228
|
+
return operation.decode(msgBuffer);
|
255
229
|
};
|
256
230
|
|
257
|
-
proto._buildBlob = function(args) {
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
const operationList = [];
|
231
|
+
proto._buildBlob = function (args) {
|
232
|
+
try {
|
233
|
+
let {sourceAddress, gasPrice, feeLimit, nonce, ceilLedgerSeq, operations, metadata} = args;
|
262
234
|
|
263
|
-
|
264
|
-
const type = item.type;
|
265
|
-
const argsData = item.data;
|
235
|
+
const operationList = [];
|
266
236
|
|
267
|
-
|
268
|
-
|
269
|
-
|
237
|
+
operations.forEach(item => {
|
238
|
+
const type = item.type;
|
239
|
+
const argsData = item.data;
|
270
240
|
|
271
|
-
|
272
|
-
|
241
|
+
const operationItem = this._buildOperation(type, argsData);
|
242
|
+
operationList.push(operationItem);
|
243
|
+
});
|
273
244
|
|
274
|
-
|
245
|
+
const root = protobuf.Root.fromJSON(require('../crypto/protobuf/bundle.json'));
|
246
|
+
const tx = root.lookupType('protocol.Transaction');
|
275
247
|
|
276
|
-
|
277
|
-
sourceAddress,
|
278
|
-
gasPrice: long.fromValue(gasPrice),
|
279
|
-
feeLimit: long.fromValue(feeLimit),
|
280
|
-
nonce: long.fromValue(nonce),
|
281
|
-
ceilLedgerSeq,
|
282
|
-
operations: operationList
|
283
|
-
};
|
248
|
+
ceilLedgerSeq = ceilLedgerSeq ? long.fromValue(ceilLedgerSeq) : undefined;
|
284
249
|
|
285
|
-
|
286
|
-
|
287
|
-
|
250
|
+
const payload = {
|
251
|
+
sourceAddress,
|
252
|
+
gasPrice: long.fromValue(gasPrice),
|
253
|
+
feeLimit: long.fromValue(feeLimit),
|
254
|
+
nonce: long.fromValue(nonce),
|
255
|
+
ceilLedgerSeq,
|
256
|
+
operations: operationList,
|
257
|
+
// metadata,
|
258
|
+
};
|
288
259
|
|
289
|
-
|
290
|
-
|
291
|
-
|
260
|
+
if (metadata) {
|
261
|
+
payload.metadata = tou8(Buffer.from(metadata));
|
262
|
+
}
|
292
263
|
|
293
|
-
|
264
|
+
const errMsg = tx.verify(payload);
|
294
265
|
|
295
|
-
|
296
|
-
|
297
|
-
|
266
|
+
if (errMsg) {
|
267
|
+
throw Error(errMsg);
|
268
|
+
}
|
298
269
|
|
299
|
-
|
300
|
-
|
270
|
+
const message = tx.create(payload);
|
271
|
+
const bufferData = tx.encode(message).finish();
|
301
272
|
|
302
|
-
|
303
|
-
|
273
|
+
return {
|
274
|
+
transactionBlob: Buffer.from(bufferData).toString('hex'),
|
275
|
+
}
|
276
|
+
} catch (err) {
|
277
|
+
throw err;
|
304
278
|
}
|
305
|
-
} catch (err) {
|
306
|
-
throw err;
|
307
|
-
}
|
308
279
|
};
|
309
280
|
|
310
|
-
proto._signBlob = function({
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
281
|
+
proto._signBlob = function ({privateKeys, blob} = args) {
|
282
|
+
try {
|
283
|
+
const buffer = Buffer.from(blob, 'hex');
|
284
|
+
const uint8ArrayData = tou8(buffer);
|
285
|
+
const signatureArr = [];
|
286
|
+
privateKeys.forEach(privateKey => {
|
287
|
+
signatureArr.push({
|
288
|
+
signData: signature.sign(uint8ArrayData, privateKey),
|
289
|
+
publicKey: keypair.getEncPublicKey(privateKey),
|
290
|
+
});
|
291
|
+
});
|
292
|
+
// return signatureArr;
|
293
|
+
return {
|
294
|
+
signatures: signatureArr,
|
295
|
+
};
|
296
|
+
} catch (err) {
|
297
|
+
throw err;
|
298
|
+
}
|
328
299
|
};
|
329
300
|
|
330
301
|
proto._submit = function* (args) {
|
331
|
-
|
332
|
-
|
333
|
-
|
302
|
+
const {blob, signature} = args;
|
303
|
+
const postData = this._postData(blob, signature);
|
304
|
+
return yield this._submitTransaction(postData);
|
334
305
|
};
|
335
306
|
|
336
307
|
|
337
|
-
proto._isHexString = function(str) {
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
308
|
+
proto._isHexString = function (str) {
|
309
|
+
if ((str === '' || !is.string(str))) {
|
310
|
+
return false;
|
311
|
+
}
|
312
|
+
// const hexString = Buffer.from(str, 'hex').toString('hex');
|
313
|
+
// return (hexString === str);
|
314
|
+
return true;
|
343
315
|
};
|
344
316
|
|
345
|
-
proto._isString = function(str) {
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
317
|
+
proto._isString = function (str) {
|
318
|
+
if (!is.string(str) ||
|
319
|
+
str.trim().length === 0 ||
|
320
|
+
str.length > 1024) {
|
321
|
+
return false;
|
322
|
+
}
|
323
|
+
return true;
|
352
324
|
};
|
353
325
|
|
354
|
-
proto._isTopic = function(str) {
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
326
|
+
proto._isTopic = function (str) {
|
327
|
+
if (!is.string(str) ||
|
328
|
+
str.trim().length === 0 ||
|
329
|
+
str.length > 128) {
|
330
|
+
return false;
|
331
|
+
}
|
332
|
+
return true;
|
361
333
|
};
|
362
334
|
|
363
|
-
proto._isSignature = function(arr) {
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
}
|
369
|
-
|
370
|
-
arr.some(item => {
|
371
|
-
if (!is.object(item)) {
|
372
|
-
tag = false;
|
373
|
-
return true;
|
335
|
+
proto._isSignature = function (arr) {
|
336
|
+
let tag = true;
|
337
|
+
if (!is.array(arr) || arr.length === 0) {
|
338
|
+
tag = false;
|
339
|
+
return tag;
|
374
340
|
}
|
375
341
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
342
|
+
arr.some(item => {
|
343
|
+
if (!is.object(item)) {
|
344
|
+
tag = false;
|
345
|
+
return true;
|
346
|
+
}
|
380
347
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
348
|
+
if (!item.signData || !item.publicKey) {
|
349
|
+
tag = false;
|
350
|
+
return true;
|
351
|
+
}
|
385
352
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
});
|
353
|
+
if (!this._isHexString(item.signData)) {
|
354
|
+
tag = false;
|
355
|
+
return true;
|
356
|
+
}
|
391
357
|
|
392
|
-
|
393
|
-
|
358
|
+
if (!keypair.checkEncPublicKey(item.publicKey)) {
|
359
|
+
tag = false;
|
360
|
+
return true;
|
361
|
+
}
|
362
|
+
});
|
394
363
|
|
395
|
-
proto._isOperation = function(arr) {
|
396
|
-
let tag = true;
|
397
|
-
if (!is.array(arr) || arr.length === 0) {
|
398
|
-
tag = false;
|
399
364
|
return tag;
|
400
|
-
|
365
|
+
};
|
401
366
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
367
|
+
proto._isOperation = function (arr) {
|
368
|
+
let tag = true;
|
369
|
+
if (!is.array(arr) || arr.length === 0) {
|
370
|
+
tag = false;
|
371
|
+
return tag;
|
406
372
|
}
|
407
|
-
if (!item.type || !item.data) {
|
408
|
-
tag = false;
|
409
|
-
return true;
|
410
|
-
}
|
411
|
-
});
|
412
373
|
|
413
|
-
|
374
|
+
arr.some(item => {
|
375
|
+
if (!is.object(item)) {
|
376
|
+
tag = false;
|
377
|
+
return true;
|
378
|
+
}
|
379
|
+
if (!item.type || !item.data) {
|
380
|
+
tag = false;
|
381
|
+
return true;
|
382
|
+
}
|
383
|
+
});
|
384
|
+
|
385
|
+
return tag;
|
414
386
|
};
|
415
387
|
|
388
|
+
proto._isDatas = function (arr) {
|
389
|
+
let tag = true;
|
390
|
+
if (!is.array(arr) || arr.length === 0) {
|
391
|
+
tag = false;
|
392
|
+
return tag;
|
393
|
+
}
|
394
|
+
|
395
|
+
arr.some(item => {
|
396
|
+
if (!is.string(item) ||
|
397
|
+
item.trim().length === 0 ||
|
398
|
+
item.length > 1024) {
|
399
|
+
tag = false;
|
400
|
+
return true;
|
401
|
+
}
|
402
|
+
});
|
416
403
|
|
417
|
-
proto._isPrivateKeys = function(arr) {
|
418
|
-
let tag = true;
|
419
|
-
if (!is.array(arr) || arr.length === 0) {
|
420
|
-
tag = false;
|
421
404
|
return tag;
|
422
|
-
|
405
|
+
};
|
406
|
+
|
423
407
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
408
|
+
proto._isPrivateKeys = function (arr) {
|
409
|
+
let tag = true;
|
410
|
+
if (!is.array(arr) || arr.length === 0) {
|
411
|
+
tag = false;
|
412
|
+
return tag;
|
428
413
|
}
|
429
|
-
});
|
430
414
|
|
431
|
-
|
415
|
+
arr.some(item => {
|
416
|
+
if (!keypair.checkEncPrivateKey(item)) {
|
417
|
+
tag = false;
|
418
|
+
return true;
|
419
|
+
}
|
420
|
+
});
|
421
|
+
|
422
|
+
return tag;
|
432
423
|
};
|
433
424
|
|
434
425
|
|
@@ -440,440 +431,457 @@ proto._isPrivateKeys = function(arr) {
|
|
440
431
|
* @private
|
441
432
|
*
|
442
433
|
* eg:
|
443
|
-
|
434
|
+
schema: {
|
444
435
|
required: false,
|
445
436
|
string: true,
|
446
437
|
address: true,
|
447
438
|
numeric: true,
|
448
439
|
}
|
449
440
|
*/
|
450
|
-
proto._validate = function(obj, schema) {
|
451
|
-
|
452
|
-
|
441
|
+
proto._validate = function (obj, schema) {
|
442
|
+
let tag = true;
|
443
|
+
let msg = '';
|
453
444
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
445
|
+
if (!is.object(obj) || !is.object(schema)) {
|
446
|
+
tag = false;
|
447
|
+
msg = 'INVALID_NUMBER_OF_ARG';
|
448
|
+
return {
|
449
|
+
tag,
|
450
|
+
msg,
|
451
|
+
};
|
452
|
+
}
|
462
453
|
|
463
|
-
|
454
|
+
Object.keys(schema).some(item => {
|
464
455
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
456
|
+
// required is true
|
457
|
+
if (schema[item].required && is.undefined(obj[item])) {
|
458
|
+
obj[item] = '';
|
459
|
+
}
|
469
460
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
461
|
+
// numeric is true
|
462
|
+
if (!is.undefined(obj[item]) &&
|
463
|
+
schema[item].numeric &&
|
464
|
+
!this._verifyValue(obj[item])) {
|
465
|
+
tag = false;
|
466
|
+
|
467
|
+
switch (item) {
|
468
|
+
case 'amount':
|
469
|
+
msg = 'INVALID_CCER_AMOUNT_ERROR';
|
470
|
+
break;
|
471
|
+
case 'ccerAmount':
|
472
|
+
msg = 'INVALID_CCER_AMOUNT_ERROR';
|
473
|
+
break;
|
474
|
+
case 'assetAmount':
|
475
|
+
msg = 'INVALID_ASSET_AMOUNT_ERROR';
|
476
|
+
break;
|
477
|
+
case 'gasPrice':
|
478
|
+
msg = 'INVALID_GASPRICE_ERROR';
|
479
|
+
break;
|
480
|
+
case 'feeLimit':
|
481
|
+
msg = 'INVALID_FEELIMIT_ERROR';
|
482
|
+
break;
|
483
|
+
case 'ceilLedgerSeq':
|
484
|
+
msg = 'INVALID_CEILLEDGERSEQ_ERROR';
|
485
|
+
break;
|
486
|
+
case 'nonce':
|
487
|
+
msg = 'INVALID_NONCE_ERROR';
|
488
|
+
break;
|
489
|
+
case 'initBalance':
|
490
|
+
msg = 'INVALID_INITBALANCE_ERROR';
|
491
|
+
break;
|
492
|
+
case 'signtureNumber':
|
493
|
+
msg = 'INVALID_SIGNATURENUMBER_ERROR';
|
494
|
+
break;
|
495
|
+
case 'totalSupply':
|
496
|
+
msg = 'INVALID_TOKEN_TOTALSUPPLY_ERROR';
|
497
|
+
break;
|
498
|
+
case 'tokenAmount':
|
499
|
+
msg = 'INVALID_TOKEN_AMOUNT_ERROR';
|
500
|
+
break;
|
501
|
+
default:
|
502
|
+
msg = 'INVALID_ARGUMENTS';
|
503
|
+
}
|
504
|
+
|
505
|
+
return true;
|
506
|
+
}
|
516
507
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
508
|
+
// privateKeys is true
|
509
|
+
if (!is.undefined(obj[item]) &&
|
510
|
+
schema[item].privateKeys &&
|
511
|
+
!this._isPrivateKeys(obj[item])) {
|
512
|
+
tag = false;
|
513
|
+
msg = `PRIVATEKEY_ONE_ERROR`;
|
514
|
+
return true;
|
515
|
+
}
|
525
516
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
517
|
+
// address is true
|
518
|
+
if (!is.undefined(obj[item]) &&
|
519
|
+
schema[item].address &&
|
520
|
+
!keypair.checkAddress(obj[item])) {
|
521
|
+
tag = false;
|
522
|
+
|
523
|
+
switch (item) {
|
524
|
+
case 'sourceAddress':
|
525
|
+
msg = 'INVALID_SOURCEADDRESS_ERROR';
|
526
|
+
break;
|
527
|
+
case 'destAddress':
|
528
|
+
msg = 'INVALID_DESTADDRESS_ERROR';
|
529
|
+
break;
|
530
|
+
case 'issuer':
|
531
|
+
msg = 'INVALID_ISSUER_ADDRESS_ERROR';
|
532
|
+
break;
|
533
|
+
case 'address':
|
534
|
+
msg = 'INVALID_ADDRESS_ERROR';
|
535
|
+
break;
|
536
|
+
case 'contractAddress':
|
537
|
+
msg = 'INVALID_CONTRACTADDRESS_ERROR';
|
538
|
+
break;
|
539
|
+
case 'fromAddress':
|
540
|
+
msg = 'INVALID_FROMADDRESS_ERROR';
|
541
|
+
break;
|
542
|
+
case 'spender':
|
543
|
+
msg = 'INVALID_SPENDER_ERROR';
|
544
|
+
break;
|
545
|
+
case 'tokenOwner':
|
546
|
+
msg = 'INVALID_TOKENOWNER_ERRPR';
|
547
|
+
break;
|
548
|
+
default:
|
549
|
+
msg = 'INVALID_ARGUMENTS';
|
550
|
+
}
|
551
|
+
|
552
|
+
return true;
|
553
|
+
}
|
563
554
|
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
555
|
+
// operations is true
|
556
|
+
if (!is.undefined(obj[item]) &&
|
557
|
+
schema[item].operations &&
|
558
|
+
!this._isOperation(obj[item])) {
|
559
|
+
tag = false;
|
560
|
+
msg = 'INVALID_OPERATIONS';
|
561
|
+
return true;
|
562
|
+
}
|
572
563
|
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
564
|
+
// signatures is true
|
565
|
+
if (!is.undefined(obj[item]) &&
|
566
|
+
schema[item].signatures &&
|
567
|
+
!this._isSignature(obj[item])) {
|
568
|
+
tag = false;
|
569
|
+
msg = 'INVALID_SIGNATURE_ERROR';
|
570
|
+
return true;
|
571
|
+
}
|
581
572
|
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
573
|
+
// hex is true
|
574
|
+
if (!is.undefined(obj[item]) &&
|
575
|
+
schema[item].hex &&
|
576
|
+
!this._isHexString(obj[item])) {
|
577
|
+
tag = false;
|
578
|
+
|
579
|
+
switch (item) {
|
580
|
+
case 'metadata':
|
581
|
+
msg = 'METADATA_NOT_HEX_STRING_ERROR';
|
582
|
+
break;
|
583
|
+
case 'blob':
|
584
|
+
msg = 'INVALID_BLOB_ERROR';
|
585
|
+
break;
|
586
|
+
default:
|
587
|
+
msg = 'METADATA_NOT_HEX_STRING_ERROR';
|
588
|
+
}
|
589
|
+
|
590
|
+
return true;
|
591
|
+
}
|
601
592
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
593
|
+
// string is true
|
594
|
+
if (!is.undefined(obj[item]) &&
|
595
|
+
schema[item].string &&
|
596
|
+
!this._isString(obj[item])) {
|
597
|
+
tag = false;
|
598
|
+
|
599
|
+
switch (item) {
|
600
|
+
case 'code':
|
601
|
+
msg = 'INVALID_ASSET_CODE_ERROR';
|
602
|
+
break;
|
603
|
+
case 'issuer':
|
604
|
+
msg = 'INVALID_ISSUER_ADDRESS_ERROR';
|
605
|
+
break;
|
606
|
+
case 'data':
|
607
|
+
msg = 'INVALID_LOG_DATA_ERROR';
|
608
|
+
break;
|
609
|
+
case 'metadata':
|
610
|
+
msg = 'INVALID_METADATA_ERROR';
|
611
|
+
break;
|
612
|
+
case 'payload':
|
613
|
+
msg = 'PAYLOAD_EMPTY_ERROR';
|
614
|
+
break;
|
615
|
+
case 'input':
|
616
|
+
msg = 'INVALID_INPUT_ERROR';
|
617
|
+
break;
|
618
|
+
case 'name':
|
619
|
+
msg = 'INVALID_TOKEN_NAME_ERROR';
|
620
|
+
break;
|
621
|
+
case 'symbol':
|
622
|
+
msg = 'INVALID_TOKEN_SYMBOL_ERROR';
|
623
|
+
break;
|
624
|
+
case 'key':
|
625
|
+
msg = 'INVALID_DATAKEY_ERROR';
|
626
|
+
break;
|
627
|
+
default:
|
628
|
+
msg = 'INVALID_ARGUMENTS';
|
629
|
+
}
|
630
|
+
|
631
|
+
return true;
|
632
|
+
}
|
642
633
|
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
634
|
+
// topic is true
|
635
|
+
if (!is.undefined(obj[item]) &&
|
636
|
+
schema[item].topic &&
|
637
|
+
!this._isTopic(obj[item])) {
|
638
|
+
tag = false;
|
639
|
+
msg = 'INVALID_LOG_TOPIC_ERROR';
|
640
|
+
return true;
|
641
|
+
}
|
651
642
|
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
msg = 'INVALID_DELETEFLAG_ERROR';
|
661
|
-
break;
|
662
|
-
default:
|
663
|
-
msg = 'INVALID_ARGUMENTS';
|
664
|
-
}
|
665
|
-
|
666
|
-
return true;
|
667
|
-
}
|
643
|
+
// datas is true
|
644
|
+
if (!is.undefined(obj[item]) &&
|
645
|
+
schema[item].datas &&
|
646
|
+
!this._isDatas(obj[item])) {
|
647
|
+
tag = false;
|
648
|
+
msg = `INVALID_LOG_DATAS_ERROR`;
|
649
|
+
return true;
|
650
|
+
}
|
668
651
|
|
669
|
-
|
652
|
+
// boolean is true
|
653
|
+
if (!is.undefined(obj[item]) &&
|
654
|
+
schema[item].boolean &&
|
655
|
+
(typeof obj[item] !== 'boolean')) {
|
656
|
+
tag = false;
|
657
|
+
|
658
|
+
switch (item) {
|
659
|
+
case 'deleteFlag':
|
660
|
+
msg = 'INVALID_DELETEFLAG_ERROR';
|
661
|
+
break;
|
662
|
+
default:
|
663
|
+
msg = 'INVALID_ARGUMENTS';
|
664
|
+
}
|
665
|
+
|
666
|
+
return true;
|
667
|
+
}
|
668
|
+
|
669
|
+
});
|
670
670
|
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
671
|
+
return {
|
672
|
+
tag,
|
673
|
+
msg,
|
674
|
+
};
|
675
675
|
};
|
676
676
|
|
677
|
-
proto._bufToHex = function(buf) {
|
678
|
-
|
679
|
-
|
677
|
+
proto._bufToHex = function (buf) {
|
678
|
+
const utf8Str = buf.toString('utf8');
|
679
|
+
return Buffer.from(utf8Str, 'utf8').toString('hex');
|
680
680
|
};
|
681
681
|
|
682
|
-
proto._bigNumberToString = function(obj, base) {
|
683
|
-
|
684
|
-
|
682
|
+
proto._bigNumberToString = function (obj, base) {
|
683
|
+
// setup base
|
684
|
+
base = base || 10;
|
685
685
|
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
686
|
+
// check if obj is type object, not an array and does not have BN properties
|
687
|
+
if (typeof obj === 'object' && obj !== null && !Array.isArray(obj) && !('lessThan' in obj)) {
|
688
|
+
// move through plain object
|
689
|
+
Object.keys(obj).forEach(function (key) {
|
690
|
+
// recurively converty item
|
691
|
+
obj[key] = proto._bigNumberToString(obj[key], base);
|
692
|
+
})
|
693
|
+
}
|
694
694
|
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
695
|
+
// obj is an array
|
696
|
+
if (Array.isArray(obj)) {
|
697
|
+
// convert items in array
|
698
|
+
obj = obj.map(function (item) {
|
699
|
+
// convert item to a string if bignumber
|
700
|
+
return proto._bigNumberToString(item, base);
|
701
|
+
})
|
702
|
+
}
|
703
703
|
|
704
|
-
|
705
|
-
|
704
|
+
// if obj is number, convert to string
|
705
|
+
if (typeof obj === 'number') return obj + '';
|
706
706
|
|
707
|
-
|
708
|
-
|
707
|
+
// if not an object bypass
|
708
|
+
if (typeof obj !== 'object' || obj === null) return obj;
|
709
709
|
|
710
|
-
|
711
|
-
|
710
|
+
// if the object to does not have BigNumber properties, bypass
|
711
|
+
if (!('toString' in obj) || !('lessThan' in obj)) return obj;
|
712
712
|
|
713
|
-
|
714
|
-
|
713
|
+
// if object has bignumber properties, convert to string with base
|
714
|
+
return obj.toString(base);
|
715
715
|
};
|
716
716
|
|
717
717
|
|
718
|
-
proto._longToInt = function(obj) {
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
718
|
+
proto._longToInt = function (obj) {
|
719
|
+
// check if obj is type object, not an array and does not have long properties
|
720
|
+
if (typeof obj === 'object' && obj !== null && !Array.isArray(obj) && !('low' in obj)) {
|
721
|
+
// move through plain object
|
722
|
+
Object.keys(obj).forEach(function (key) {
|
723
|
+
// recurively converty item
|
724
|
+
obj[key] = proto._longToInt(obj[key]);
|
725
|
+
})
|
726
|
+
}
|
727
727
|
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
728
|
+
// obj is an array
|
729
|
+
if (Array.isArray(obj)) {
|
730
|
+
// convert items in array
|
731
|
+
obj = obj.map(function (item) {
|
732
|
+
// convert item to an int if long
|
733
|
+
return proto._longToInt(item);
|
734
|
+
})
|
735
|
+
}
|
736
736
|
|
737
|
-
|
738
|
-
|
737
|
+
// if not an object bypass
|
738
|
+
if (typeof obj !== 'object' || obj === null) return obj;
|
739
739
|
|
740
|
-
|
741
|
-
|
740
|
+
// if the object to does not have long properties, bypass
|
741
|
+
if (!('low' in obj)) return obj;
|
742
742
|
|
743
|
-
|
744
|
-
|
743
|
+
// if object has long properties, convert to int
|
744
|
+
return long.fromValue(obj).toNumber();
|
745
745
|
};
|
746
746
|
|
747
747
|
proto._isContractAddress = function* (address) {
|
748
|
-
|
749
|
-
|
750
|
-
|
748
|
+
const data = yield this._request('get', 'getAccount', {
|
749
|
+
address,
|
750
|
+
});
|
751
751
|
|
752
|
-
|
753
|
-
|
754
|
-
|
752
|
+
if (data.error_code !== 0) {
|
753
|
+
return this._responseError(errors.ACCOUNT_NOT_EXIST);
|
754
|
+
}
|
755
755
|
|
756
|
-
|
756
|
+
const result = data.result;
|
757
757
|
|
758
|
-
|
759
|
-
|
760
|
-
|
758
|
+
if (result.contract) {
|
759
|
+
return true;
|
760
|
+
}
|
761
761
|
|
762
|
-
|
762
|
+
return false;
|
763
763
|
};
|
764
764
|
|
765
765
|
proto._isAvailableToken = function* (contractAddress) {
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
const isContractAddress = yield this._isContractAddress(contractAddress);
|
771
|
-
if (!isContractAddress) {
|
772
|
-
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
773
|
-
}
|
774
|
-
|
775
|
-
let data = yield this._request('get', 'getAccount', {
|
776
|
-
address: contractAddress,
|
777
|
-
});
|
766
|
+
if (!keypair.checkAddress(contractAddress)) {
|
767
|
+
return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
|
768
|
+
}
|
778
769
|
|
770
|
+
const isContractAddress = yield this._isContractAddress(contractAddress);
|
771
|
+
if (!isContractAddress) {
|
772
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
773
|
+
}
|
779
774
|
|
780
|
-
|
781
|
-
|
782
|
-
isValid: false,
|
775
|
+
let data = yield this._request('get', 'getAccount', {
|
776
|
+
address: contractAddress,
|
783
777
|
});
|
784
|
-
}
|
785
778
|
|
786
|
-
data = data.result;
|
787
|
-
const contract = data.contract.metadatas;
|
788
|
-
const metadatas = data.metadatas;
|
789
|
-
let key = '';
|
790
|
-
let value = '';
|
791
|
-
if (metadatas && is.array(metadatas)) {
|
792
|
-
|
793
|
-
metadatas.some(item => {
|
794
|
-
if (item.key === 'global_attribute') {
|
795
|
-
key = 'global_attribute';
|
796
|
-
value = item.value;
|
797
|
-
return true;
|
798
|
-
}
|
799
|
-
});
|
800
779
|
|
801
|
-
if (
|
802
|
-
|
803
|
-
|
804
|
-
|
780
|
+
if (data.error_code !== 0) {
|
781
|
+
return this._responseData({
|
782
|
+
isValid: false,
|
783
|
+
});
|
805
784
|
}
|
806
785
|
|
807
|
-
|
786
|
+
data = data.result;
|
787
|
+
const contract = data.contract.metadatas;
|
788
|
+
const metadatas = data.metadatas;
|
789
|
+
let key = '';
|
790
|
+
let value = '';
|
791
|
+
if (metadatas && is.array(metadatas)) {
|
808
792
|
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
793
|
+
metadatas.some(item => {
|
794
|
+
if (item.key === 'global_attribute') {
|
795
|
+
key = 'global_attribute';
|
796
|
+
value = item.value;
|
797
|
+
return true;
|
798
|
+
}
|
799
|
+
});
|
814
800
|
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
801
|
+
if (key !== 'global_attribute') {
|
802
|
+
return this._responseData({
|
803
|
+
isValid: false,
|
804
|
+
});
|
805
|
+
}
|
820
806
|
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
807
|
+
const info = JSON.parse(value);
|
808
|
+
|
809
|
+
if ('1.0' !== info.ctp) {
|
810
|
+
return this._responseData({
|
811
|
+
isValid: false,
|
812
|
+
});
|
813
|
+
}
|
814
|
+
|
815
|
+
if (!info.symbol || info.symbol < 0 || info.symbol > 8) {
|
816
|
+
return this._responseData({
|
817
|
+
isValid: false,
|
818
|
+
});
|
819
|
+
}
|
820
|
+
|
821
|
+
const schema = {
|
822
|
+
balance: {
|
823
|
+
required: true,
|
824
|
+
numeric: true,
|
825
|
+
},
|
826
|
+
name: {
|
827
|
+
required: true,
|
828
|
+
string: true,
|
829
|
+
},
|
830
|
+
symbol: {
|
831
|
+
required: true,
|
832
|
+
string: true,
|
833
|
+
},
|
834
|
+
totalSupply: {
|
835
|
+
required: true,
|
836
|
+
numeric: true,
|
837
|
+
},
|
838
|
+
contractOwner: {
|
839
|
+
required: true,
|
840
|
+
address: true,
|
841
|
+
},
|
842
|
+
};
|
843
|
+
|
844
|
+
if (!this._validate(info, schema).tag) {
|
845
|
+
return this._responseData({
|
846
|
+
isValid: false,
|
847
|
+
});
|
848
|
+
}
|
843
849
|
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
850
|
+
return this._responseData({
|
851
|
+
isValid: true,
|
852
|
+
});
|
853
|
+
|
854
|
+
} else {
|
855
|
+
return this._responseData({
|
856
|
+
isValid: false,
|
857
|
+
});
|
848
858
|
}
|
859
|
+
};
|
849
860
|
|
850
|
-
|
851
|
-
|
852
|
-
|
861
|
+
proto._isAvailableVersion = function (str) {
|
862
|
+
const reg = /^\d+(\.\d+)?$/;
|
863
|
+
return (
|
864
|
+
is.string(str) &&
|
865
|
+
reg.test(str) &&
|
866
|
+
long.fromValue(str).greaterThanOrEqual(0) &&
|
867
|
+
long.fromValue(str).lessThanOrEqual(long.MAX_VALUE)
|
868
|
+
);
|
869
|
+
};
|
853
870
|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
871
|
+
proto._isAvailableCcer = function (str) {
|
872
|
+
const reg = /^(([1-9]\d*)+|0)(\.\d{1,8})?$/;
|
873
|
+
return (
|
874
|
+
is.string(str) &&
|
875
|
+
reg.test(str) &&
|
876
|
+
long.fromValue(str).greaterThanOrEqual(0) &&
|
877
|
+
long.fromValue(str).lessThanOrEqual(long.MAX_VALUE.divide(Math.pow(10, 8)))
|
878
|
+
);
|
879
|
+
}
|
880
|
+
|
881
|
+
proto._handleRequestError = function(error) {
|
882
|
+
if (error.response) {
|
883
|
+
const { status, data } = error.response;
|
884
|
+
return new Error(`请求失败: 状态码 ${status}, 响应数据: ${JSON.stringify(data)}`);
|
858
885
|
}
|
886
|
+
return new Error(`网络连接失败: ${error.message}`);
|
859
887
|
};
|
860
|
-
|
861
|
-
proto._isAvailableVersion = function(str) {
|
862
|
-
const reg = /^\d+(\.\d+)?$/;
|
863
|
-
return (
|
864
|
-
is.string(str) &&
|
865
|
-
reg.test(str) &&
|
866
|
-
long.fromValue(str).greaterThanOrEqual(0) &&
|
867
|
-
long.fromValue(str).lessThanOrEqual(long.MAX_VALUE)
|
868
|
-
);
|
869
|
-
};
|
870
|
-
|
871
|
-
proto._isAvailableBu = function (str) {
|
872
|
-
const reg = /^(([1-9]\d*)+|0)(\.\d{1,8})?$/;
|
873
|
-
return (
|
874
|
-
is.string(str) &&
|
875
|
-
reg.test(str) &&
|
876
|
-
long.fromValue(str).greaterThanOrEqual(0) &&
|
877
|
-
long.fromValue(str).lessThanOrEqual(long.MAX_VALUE.divide(Math.pow(10, 8)))
|
878
|
-
);
|
879
|
-
}
|