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.
@@ -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 { keypair, signature } = require('yxchain-encryption-nodejs');
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
- proto._request = async function (method, path, data = {}) {
27
+ // 替换原有request实现
28
+ proto._request = async function(method, endpoint, data) {
25
29
  try {
26
- const protocol = this.options.secure ? 'https://' : 'http://';
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: uri,
46
- timeout: this.options.timeout,
47
- };
48
-
49
- if (method.toLowerCase() === 'get') {
50
- options.params = data;
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
- const data = {
71
- errorCode: obj.error_code || 0,
72
- errorDesc: obj.error_desc || 'Success',
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
- if (is.object(obj) && obj.error_code) {
76
- if (obj.error_code === 0) {
77
- data.result = obj.result || {};
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
- data.errorDesc = obj.error_desc || '';
80
- data.result = {};
55
+ data.result = obj;
81
56
  }
82
- } else {
83
- data.result = obj;
84
- }
85
57
 
86
- return JSONbig.stringify(data);
58
+ return JSONbig.stringify(data);
87
59
  };
88
60
 
89
61
  proto._getBlockNumber = function* () {
90
- try {
91
- const data = yield this._request('get', 'getLedger');
92
- if (data && data.error_code === 0) {
93
- const seq = data.result.header.seq;
94
- return this._responseData({
95
- header: {
96
- blockNumber: seq,
97
- },
98
- });
99
- } else {
100
- return this._responseError(errors.INTERNAL_ERROR);
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
- if (!is.string(str)) {
109
- throw new Error('str must be a string');
110
- }
111
- return (str.trim().length === 0);
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
- const data = {
116
- items: [
117
- {
118
- transaction_blob: blob,
119
- signatures: signature
120
- },
121
- ],
122
- };
123
- return JSONbig.stringify(data);
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
- return object instanceof BigNumber ||
128
- (object && object.constructor && object.constructor.name === 'BigNumber');
99
+ return object instanceof BigNumber ||
100
+ (object && object.constructor && object.constructor.name === 'BigNumber');
129
101
  };
130
102
 
131
- proto._toBigNumber = function(number) {
132
- number = number || 0;
133
- //
134
- if (this._isBigNumber(number)) {
135
- return number;
136
- }
137
- return new BigNumber(number);
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
- return this._toBigNumber(number).toString(10);
112
+ proto._stringFromBigNumber = function (number) {
113
+ return this._toBigNumber(number).toString(10);
142
114
  };
143
115
 
144
- proto._verifyValue = function(str) {
145
- const reg = /^[1-9]\d*$/;
146
- return (
147
- is.string(str) &&
148
- reg.test(str) &&
149
- long.fromValue(str).greaterThan(0) &&
150
- long.fromValue(str).lessThanOrEqual(long.MAX_VALUE)
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=-1, to=long.MAX_VALUE) {
155
- const reg = /^(0|([1-9]\d*))$/
156
- return (
157
- is.string(str) &&
158
- reg.test(str) &&
159
- long.fromValue(str).greaterThan(from) &&
160
- long.fromValue(str).lessThanOrEqual(to)
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
- for (let prop in obj) {
166
- if (obj.hasOwnProperty(prop)) {
167
- let value = obj[prop];
168
- if (!is.undefined(value)) {
169
- if (!this._verifyValue(value)) {
170
- throw new Error(errors.INVALID_FORMAT_OF_ARG.msg);
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
- try {
179
- let ledgerInfo = yield this._request('get', 'getLedger', {
180
- with_fee: true,
181
- });
182
- const gasPrice = long.fromValue(ledgerInfo.result.fees.gas_price);
183
- const feeLimit = long.fromValue(1000).mul(gasPrice);
184
- return {
185
- gasPrice,
186
- feeLimit,
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
- const errorCode = 0;
195
- const errorDesc = '';
165
+ proto._responseData = function (data) {
166
+ const errorCode = 0;
167
+ const errorDesc = '';
196
168
 
197
- return {
198
- errorCode,
199
- errorDesc,
200
- result: data,
201
- }
169
+ return {
170
+ errorCode,
171
+ errorDesc,
172
+ result: data,
173
+ }
202
174
  };
203
175
 
204
- proto._responseError = function(message) {
205
- if (!message) {
206
- throw new Error('require message');
207
- }
208
- const errorCode = message.CODE;
176
+ proto._responseError = function (message) {
177
+ if (!message) {
178
+ throw new Error('require message');
179
+ }
180
+ const errorCode = message.CODE;
209
181
 
210
- return {
211
- errorCode,
212
- errorDesc: message.MSG,
213
- };
182
+ return {
183
+ errorCode,
184
+ errorDesc: message.MSG,
185
+ };
214
186
  };
215
187
 
216
188
  proto._submitTransaction = function* (data) {
217
- try {
218
- const res = yield this._request('post', 'submitTransaction', data);
219
- const results = res.results;
220
- if (Array.isArray(results) && results.length > 0) {
221
- const info = results[0];
222
-
223
- if (info.error_code === '0') {
224
- return this._responseData({
225
- hash: info.hash,
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
- return {
230
- errorCode: info.error_code,
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
- try {
243
- return require(`./operation/${type}`)(data);
244
- } catch (err) {
245
- console.log(err);
246
- throw new Error('Operation cannot be resolved');
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
- const root = protobuf.Root.fromJSON(require('../crypto/protobuf/bundle.json'));
252
- const operation = root.lookupType('protocol.Operation');
253
- const msgBuffer = Buffer.from(hexString, 'hex');
254
- return operation.decode(msgBuffer);
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
- try {
259
- let { sourceAddress, gasPrice, feeLimit, nonce, ceilLedgerSeq, operations, metadata } = args;
260
-
261
- const operationList = [];
231
+ proto._buildBlob = function (args) {
232
+ try {
233
+ let {sourceAddress, gasPrice, feeLimit, nonce, ceilLedgerSeq, operations, metadata} = args;
262
234
 
263
- operations.forEach(item => {
264
- const type = item.type;
265
- const argsData = item.data;
235
+ const operationList = [];
266
236
 
267
- const operationItem = this._buildOperation(type, argsData);
268
- operationList.push(operationItem);
269
- });
237
+ operations.forEach(item => {
238
+ const type = item.type;
239
+ const argsData = item.data;
270
240
 
271
- const root = protobuf.Root.fromJSON(require('../crypto/protobuf/bundle.json'));
272
- const tx = root.lookupType('protocol.Transaction');
241
+ const operationItem = this._buildOperation(type, argsData);
242
+ operationList.push(operationItem);
243
+ });
273
244
 
274
- ceilLedgerSeq = ceilLedgerSeq ? long.fromValue(ceilLedgerSeq) : undefined;
245
+ const root = protobuf.Root.fromJSON(require('../crypto/protobuf/bundle.json'));
246
+ const tx = root.lookupType('protocol.Transaction');
275
247
 
276
- const payload = {
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
- if (this.options.chainId > 0) {
286
- payload.chainId = this.options.chainId
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
- if (metadata) {
290
- payload.metadata = tou8(Buffer.from(metadata));
291
- }
260
+ if (metadata) {
261
+ payload.metadata = tou8(Buffer.from(metadata));
262
+ }
292
263
 
293
- const errMsg = tx.verify(payload);
264
+ const errMsg = tx.verify(payload);
294
265
 
295
- if (errMsg) {
296
- throw Error(errMsg);
297
- }
266
+ if (errMsg) {
267
+ throw Error(errMsg);
268
+ }
298
269
 
299
- const message = tx.create(payload);
300
- const bufferData = tx.encode(message).finish();
270
+ const message = tx.create(payload);
271
+ const bufferData = tx.encode(message).finish();
301
272
 
302
- return {
303
- transactionBlob: bufferData.toString('hex'),
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({ privateKeys, blob } = args) {
311
- try {
312
- const buffer = Buffer.from(blob, 'hex');
313
- const uint8ArrayData = tou8(buffer);
314
- const signatureArr = [];
315
- privateKeys.forEach(privateKey => {
316
- signatureArr.push({
317
- signData: signature.sign(uint8ArrayData, privateKey),
318
- publicKey: keypair.getEncPublicKey(privateKey),
319
- });
320
- });
321
- // return signatureArr;
322
- return {
323
- signatures: signatureArr,
324
- };
325
- } catch (err) {
326
- throw err;
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
- const { blob, signature} = args;
332
- const postData = this._postData(blob, signature);
333
- return yield this._submitTransaction(postData);
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
- if ((str === '' || !is.string(str))) {
339
- return false;
340
- }
341
- const hexString = Buffer.from(str, 'hex').toString('hex');
342
- return (hexString === str);
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
- if (!is.string(str) ||
347
- str.trim().length === 0 ||
348
- str.length > 1024) {
349
- return false;
350
- }
351
- return true;
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
- if (!is.string(str) ||
356
- str.trim().length === 0 ||
357
- str.length > 128) {
358
- return false;
359
- }
360
- return true;
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
- let tag = true;
365
- if (!is.array(arr) || arr.length === 0) {
366
- tag = false;
367
- return tag;
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
- if (!item.signData || !item.publicKey) {
377
- tag = false;
378
- return true;
379
- }
342
+ arr.some(item => {
343
+ if (!is.object(item)) {
344
+ tag = false;
345
+ return true;
346
+ }
380
347
 
381
- if (!this._isHexString(item.signData)) {
382
- tag = false;
383
- return true;
384
- }
348
+ if (!item.signData || !item.publicKey) {
349
+ tag = false;
350
+ return true;
351
+ }
385
352
 
386
- if (!keypair.checkEncPublicKey(item.publicKey)) {
387
- tag = false;
388
- return true;
389
- }
390
- });
353
+ if (!this._isHexString(item.signData)) {
354
+ tag = false;
355
+ return true;
356
+ }
391
357
 
392
- return tag;
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
- arr.some(item => {
403
- if (!is.object(item)) {
404
- tag = false;
405
- return true;
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
- return tag;
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
- arr.some(item => {
425
- if (!keypair.checkEncPrivateKey(item)) {
426
- tag = false;
427
- return true;
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
- return tag;
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
- schema: {
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
- let tag = true;
452
- let msg = '';
441
+ proto._validate = function (obj, schema) {
442
+ let tag = true;
443
+ let msg = '';
453
444
 
454
- if (!is.object(obj) || !is.object(schema)) {
455
- tag = false;
456
- msg = 'INVALID_NUMBER_OF_ARG';
457
- return {
458
- tag,
459
- msg,
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
- Object.keys(schema).some(item => {
454
+ Object.keys(schema).some(item => {
464
455
 
465
- // required is true
466
- if (schema[item].required && is.undefined(obj[item])) {
467
- obj[item] = '';
468
- }
456
+ // required is true
457
+ if (schema[item].required && is.undefined(obj[item])) {
458
+ obj[item] = '';
459
+ }
469
460
 
470
- // numeric is true
471
- if (!is.undefined(obj[item]) &&
472
- schema[item].numeric &&
473
- !this._verifyValue(obj[item])) {
474
- tag = false;
475
-
476
- switch(item) {
477
- case 'amount':
478
- msg = 'INVALID_BU_AMOUNT_ERROR';
479
- break;
480
- case 'buAmount':
481
- msg = 'INVALID_BU_AMOUNT_ERROR';
482
- break;
483
- case 'assetAmount':
484
- msg = 'INVALID_ASSET_AMOUNT_ERROR';
485
- break;
486
- case 'gasPrice':
487
- msg = 'INVALID_GASPRICE_ERROR';
488
- break;
489
- case 'feeLimit':
490
- msg = 'INVALID_FEELIMIT_ERROR';
491
- break;
492
- case 'ceilLedgerSeq':
493
- msg = 'INVALID_CEILLEDGERSEQ_ERROR';
494
- break;
495
- case 'nonce':
496
- msg = 'INVALID_NONCE_ERROR';
497
- break;
498
- case 'initBalance':
499
- msg = 'INVALID_INITBALANCE_ERROR';
500
- break;
501
- case 'signtureNumber':
502
- msg = 'INVALID_SIGNATURENUMBER_ERROR';
503
- break;
504
- case 'totalSupply':
505
- msg = 'INVALID_TOKEN_TOTALSUPPLY_ERROR';
506
- break;
507
- case 'tokenAmount':
508
- msg = 'INVALID_TOKEN_AMOUNT_ERROR';
509
- break;
510
- default:
511
- msg = 'INVALID_ARGUMENTS';
512
- }
513
-
514
- return true;
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
- // privateKeys is true
518
- if (!is.undefined(obj[item]) &&
519
- schema[item].privateKeys &&
520
- !this._isPrivateKeys(obj[item])) {
521
- tag = false;
522
- msg = `PRIVATEKEY_ONE_ERROR`;
523
- return true;
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
- // address is true
527
- if (!is.undefined(obj[item]) &&
528
- schema[item].address &&
529
- !keypair.checkAddress(obj[item])) {
530
- tag = false;
531
-
532
- switch(item) {
533
- case 'sourceAddress':
534
- msg = 'INVALID_SOURCEADDRESS_ERROR';
535
- break;
536
- case 'destAddress':
537
- msg = 'INVALID_DESTADDRESS_ERROR';
538
- break;
539
- case 'issuer':
540
- msg = 'INVALID_ISSUER_ADDRESS_ERROR';
541
- break;
542
- case 'address':
543
- msg = 'INVALID_ADDRESS_ERROR';
544
- break;
545
- case 'contractAddress':
546
- msg = 'INVALID_CONTRACTADDRESS_ERROR';
547
- break;
548
- case 'fromAddress':
549
- msg = 'INVALID_FROMADDRESS_ERROR';
550
- break;
551
- case 'spender':
552
- msg = 'INVALID_SPENDER_ERROR';
553
- break;
554
- case 'tokenOwner':
555
- msg = 'INVALID_TOKENOWNER_ERRPR';
556
- break;
557
- default:
558
- msg = 'INVALID_ARGUMENTS';
559
- }
560
-
561
- return true;
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
- // operations is true
565
- if (!is.undefined(obj[item]) &&
566
- schema[item].operations &&
567
- !this._isOperation(obj[item])) {
568
- tag = false;
569
- msg = 'INVALID_OPERATIONS';
570
- return true;
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
- // signatures is true
574
- if (!is.undefined(obj[item]) &&
575
- schema[item].signatures &&
576
- !this._isSignature(obj[item])) {
577
- tag = false;
578
- msg = 'INVALID_SIGNATURE_ERROR';
579
- return true;
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
- // hex is true
583
- if (!is.undefined(obj[item]) &&
584
- schema[item].hex &&
585
- !this._isHexString(obj[item])) {
586
- tag = false;
587
-
588
- switch(item) {
589
- case 'metadata':
590
- msg = 'METADATA_NOT_HEX_STRING_ERROR';
591
- break;
592
- case 'blob':
593
- msg = 'INVALID_BLOB_ERROR';
594
- break;
595
- default:
596
- msg = 'METADATA_NOT_HEX_STRING_ERROR';
597
- }
598
-
599
- return true;
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
- // string is true
603
- if (!is.undefined(obj[item]) &&
604
- schema[item].string &&
605
- !this._isString(obj[item])) {
606
- tag = false;
607
-
608
- switch(item) {
609
- case 'code':
610
- msg = 'INVALID_ASSET_CODE_ERROR';
611
- break;
612
- case 'issuer':
613
- msg = 'INVALID_ISSUER_ADDRESS_ERROR';
614
- break;
615
- case 'data':
616
- msg = 'INVALID_LOG_DATA_ERROR';
617
- break;
618
- case 'metadata':
619
- msg = 'INVALID_METADATA_ERROR';
620
- break;
621
- case 'payload':
622
- msg = 'PAYLOAD_EMPTY_ERROR';
623
- break;
624
- case 'input':
625
- msg = 'INVALID_INPUT_ERROR';
626
- break;
627
- case 'name':
628
- msg = 'INVALID_TOKEN_NAME_ERROR';
629
- break;
630
- case 'symbol':
631
- msg = 'INVALID_TOKEN_SYMBOL_ERROR';
632
- break;
633
- case 'key':
634
- msg = 'INVALID_DATAKEY_ERROR';
635
- break;
636
- default:
637
- msg = 'INVALID_ARGUMENTS';
638
- }
639
-
640
- return true;
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
- // topic is true
644
- if (!is.undefined(obj[item]) &&
645
- schema[item].topic &&
646
- !this._isTopic(obj[item])) {
647
- tag = false;
648
- msg = 'INVALID_LOG_TOPIC_ERROR';
649
- return true;
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
- // 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
- }
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
- return {
672
- tag,
673
- msg,
674
- };
671
+ return {
672
+ tag,
673
+ msg,
674
+ };
675
675
  };
676
676
 
677
- proto._bufToHex = function(buf) {
678
- const utf8Str = buf.toString('utf8');
679
- return Buffer.from(utf8Str, 'utf8').toString('hex');
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
- // setup base
684
- base = base || 10;
682
+ proto._bigNumberToString = function (obj, base) {
683
+ // setup base
684
+ base = base || 10;
685
685
 
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
- }
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
- // 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
- }
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
- // if obj is number, convert to string
705
- if (typeof obj === 'number') return obj + '';
704
+ // if obj is number, convert to string
705
+ if (typeof obj === 'number') return obj + '';
706
706
 
707
- // if not an object bypass
708
- if (typeof obj !== 'object' || obj === null) return obj;
707
+ // if not an object bypass
708
+ if (typeof obj !== 'object' || obj === null) return obj;
709
709
 
710
- // if the object to does not have BigNumber properties, bypass
711
- if (!('toString' in obj) || !('lessThan' in obj)) return obj;
710
+ // if the object to does not have BigNumber properties, bypass
711
+ if (!('toString' in obj) || !('lessThan' in obj)) return obj;
712
712
 
713
- // if object has bignumber properties, convert to string with base
714
- return obj.toString(base);
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
- // 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
- }
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
- // 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
- }
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
- // if not an object bypass
738
- if (typeof obj !== 'object' || obj === null) return obj;
737
+ // if not an object bypass
738
+ if (typeof obj !== 'object' || obj === null) return obj;
739
739
 
740
- // if the object to does not have long properties, bypass
741
- if (!('low' in obj)) return obj;
740
+ // if the object to does not have long properties, bypass
741
+ if (!('low' in obj)) return obj;
742
742
 
743
- // if object has long properties, convert to int
744
- return long.fromValue(obj).toNumber();
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
- const data = yield this._request('get', 'getAccount', {
749
- address,
750
- });
748
+ const data = yield this._request('get', 'getAccount', {
749
+ address,
750
+ });
751
751
 
752
- if (data.error_code !== 0) {
753
- return this._responseError(errors.ACCOUNT_NOT_EXIST);
754
- }
752
+ if (data.error_code !== 0) {
753
+ return this._responseError(errors.ACCOUNT_NOT_EXIST);
754
+ }
755
755
 
756
- const result = data.result;
756
+ const result = data.result;
757
757
 
758
- if (result.contract) {
759
- return true;
760
- }
758
+ if (result.contract) {
759
+ return true;
760
+ }
761
761
 
762
- return false;
762
+ return false;
763
763
  };
764
764
 
765
765
  proto._isAvailableToken = function* (contractAddress) {
766
- if (!keypair.checkAddress(contractAddress)) {
767
- return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
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
- if (data.error_code !== 0) {
781
- return this._responseData({
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 (key !== 'global_attribute') {
802
- return this._responseData({
803
- isValid: false,
804
- });
780
+ if (data.error_code !== 0) {
781
+ return this._responseData({
782
+ isValid: false,
783
+ });
805
784
  }
806
785
 
807
- const info = JSON.parse(value);
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
- if ('1.0' !== info.ctp) {
810
- return this._responseData({
811
- isValid: false,
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
- if (!info.symbol || info.symbol < 0 || info.symbol > 8) {
816
- return this._responseData({
817
- isValid: false,
818
- });
819
- }
801
+ if (key !== 'global_attribute') {
802
+ return this._responseData({
803
+ isValid: false,
804
+ });
805
+ }
820
806
 
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
- };
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
- if (!this._validate(info, schema).tag) {
845
- return this._responseData({
846
- isValid: false,
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
- return this._responseData({
851
- isValid: true,
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
- } else {
855
- return this._responseData({
856
- isValid: false,
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
- }