openchain-nodejs-ts-yxl 1.0.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/LICENSE +661 -0
- package/README.md +66 -0
- package/_config.yml +1 -0
- package/doc/SDK_CN.md +2003 -0
- package/example/atp10TokenDemo.js +319 -0
- package/example/exchange.js +184 -0
- package/example/offlineSignatureDemo.js +83 -0
- package/example/submitTransactionDemo.js +92 -0
- package/index.d.ts +186 -0
- package/index.js +9 -0
- package/lib/account/index.js +234 -0
- package/lib/blockchain/block.js +380 -0
- package/lib/blockchain/transaction.js +264 -0
- package/lib/common/ctp.js +5 -0
- package/lib/common/operation/accountSetMetadata.js +55 -0
- package/lib/common/operation/accountSetPrivilege.js +90 -0
- package/lib/common/operation/activateAccount.js +58 -0
- package/lib/common/operation/contractCreate.js +72 -0
- package/lib/common/operation/contractInvokeByAsset.js +75 -0
- package/lib/common/operation/contractInvokeByBU.js +53 -0
- package/lib/common/operation/createLog.js +44 -0
- package/lib/common/operation/ctp10TokenApprove.js +59 -0
- package/lib/common/operation/ctp10TokenAssign.js +59 -0
- package/lib/common/operation/ctp10TokenChangeOwner.js +58 -0
- package/lib/common/operation/ctp10TokenIssue.js +78 -0
- package/lib/common/operation/ctp10TokenTransfer.js +59 -0
- package/lib/common/operation/ctp10TokenTransferFrom.js +60 -0
- package/lib/common/operation/issueAsset.js +35 -0
- package/lib/common/operation/payAsset.js +62 -0
- package/lib/common/operation/payCoin.js +44 -0
- package/lib/common/util.js +880 -0
- package/lib/contract/index.js +212 -0
- package/lib/crypto/protobuf/bundle.json +1643 -0
- package/lib/exception/customErrors.js +56 -0
- package/lib/exception/errors.js +240 -0
- package/lib/exception/index.js +8 -0
- package/lib/operation/account.js +193 -0
- package/lib/operation/asset.js +106 -0
- package/lib/operation/bu.js +52 -0
- package/lib/operation/contract.js +184 -0
- package/lib/operation/ctp10Token.js +394 -0
- package/lib/operation/index.js +30 -0
- package/lib/operation/log.js +47 -0
- package/lib/sdk.js +70 -0
- package/lib/token/asset.js +79 -0
- package/lib/token/ctp10Token.js +301 -0
- package/lib/token/index.js +17 -0
- package/lib/util/index.js +86 -0
- package/openchain-sdk-nodejs.iml +9 -0
- package/package.json +39 -0
- package/test/Ctp10Token.test.js +96 -0
- package/test/account.test.js +132 -0
- package/test/accountActivateOperation.test.js +99 -0
- package/test/accountSetMetadata.test.js +102 -0
- package/test/accountSetPrivilege.test.js +66 -0
- package/test/asset.test.js +63 -0
- package/test/assetIssueOperation.test.js +77 -0
- package/test/assetSendOperation.test.js +103 -0
- package/test/blob.test.js +128 -0
- package/test/block.test.js +165 -0
- package/test/buSendOperation.test.js +64 -0
- package/test/contract.test.js +64 -0
- package/test/contractCreateOperation.test.js +41 -0
- package/test/contractCreateTransaction.test.js +116 -0
- package/test/contractInvokeByAssetOperation.test.js +109 -0
- package/test/contractInvokeByBUOperation.test.js +107 -0
- package/test/ctp10TokenApproveOperation.test.js +98 -0
- package/test/ctp10TokenAssignOperation.test.js +99 -0
- package/test/ctp10TokenChangeOwnerOperation.test.js +98 -0
- package/test/ctp10TokenIssueOperation.test.js +40 -0
- package/test/ctp10TokenIssueOperationTransaction.test.js +106 -0
- package/test/ctp10TokenTransferFromOperation.test.js +101 -0
- package/test/ctp10TokenTransferOperation.test.js +98 -0
- package/test/log.transaction.test.js +103 -0
- package/test/transaction.test.js +166 -0
- package/test/util.test.js +93 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const wrap = require('co-wrap-all');
|
4
|
+
const is = require('is-type-of');
|
5
|
+
const merge = require('merge-descriptors');
|
6
|
+
const errors = require('../exception');
|
7
|
+
|
8
|
+
|
9
|
+
module.exports = Asset;
|
10
|
+
|
11
|
+
function Asset(options) {
|
12
|
+
if (!(this instanceof Asset)) {
|
13
|
+
return new Asset(options);
|
14
|
+
}
|
15
|
+
this.options = options;
|
16
|
+
}
|
17
|
+
|
18
|
+
const proto = Asset.prototype;
|
19
|
+
|
20
|
+
merge(proto, require('../common/util'));
|
21
|
+
|
22
|
+
proto.getInfo = function* (args) {
|
23
|
+
try {
|
24
|
+
if (is.array(args) || !is.object(args)) {
|
25
|
+
return this._responseError(errors.INVALID_ARGUMENTS);
|
26
|
+
}
|
27
|
+
|
28
|
+
const { address, code, issuer } = args;
|
29
|
+
|
30
|
+
const schema = {
|
31
|
+
address: {
|
32
|
+
required: true,
|
33
|
+
address: true,
|
34
|
+
},
|
35
|
+
code: {
|
36
|
+
required: true,
|
37
|
+
string: true,
|
38
|
+
},
|
39
|
+
issuer: {
|
40
|
+
required: true,
|
41
|
+
address: true,
|
42
|
+
},
|
43
|
+
};
|
44
|
+
|
45
|
+
if (!this._validate(args, schema).tag) {
|
46
|
+
const msg = this._validate(args, schema).msg;
|
47
|
+
return this._responseError(errors[msg]);
|
48
|
+
}
|
49
|
+
|
50
|
+
const data = yield this._request('get', 'getAccountAssets', {
|
51
|
+
address,
|
52
|
+
});
|
53
|
+
if (data.error_code === 0 && data.result && data.result.length > 0 ) {
|
54
|
+
let obj = [];
|
55
|
+
data.result.some(item => {
|
56
|
+
if (item.key.code === code &&
|
57
|
+
item.key.issuer === issuer) {
|
58
|
+
obj.push(item);
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
});
|
62
|
+
|
63
|
+
|
64
|
+
return this._responseData({
|
65
|
+
assets: obj,
|
66
|
+
});
|
67
|
+
|
68
|
+
} else {
|
69
|
+
return this._responseData({
|
70
|
+
assets: [],
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
} catch (err) {
|
75
|
+
throw err;
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
wrap(proto);
|
@@ -0,0 +1,301 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const wrap = require('co-wrap-all');
|
4
|
+
const is = require('is-type-of');
|
5
|
+
const merge = require('merge-descriptors');
|
6
|
+
const humps = require('humps');
|
7
|
+
const JSONbig = require('json-bigint');
|
8
|
+
const { keypair } = require('yxchain-encryption-nodejs');
|
9
|
+
|
10
|
+
const errors = require('../exception');
|
11
|
+
|
12
|
+
|
13
|
+
module.exports = Ctp10Token;
|
14
|
+
|
15
|
+
function Ctp10Token(options) {
|
16
|
+
if (!(this instanceof Ctp10Token)) {
|
17
|
+
return new Ctp10Token(options);
|
18
|
+
}
|
19
|
+
this.options = options;
|
20
|
+
}
|
21
|
+
|
22
|
+
const proto = Ctp10Token.prototype;
|
23
|
+
|
24
|
+
merge(proto, require('../common/util'));
|
25
|
+
|
26
|
+
proto.checkValid = function* (contractAddress) {
|
27
|
+
try {
|
28
|
+
return yield this._isAvailableToken(contractAddress)
|
29
|
+
} catch (err) {
|
30
|
+
throw err;
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
|
35
|
+
proto.getInfo = function* (contractAddress) {
|
36
|
+
try {
|
37
|
+
if (!keypair.checkAddress(contractAddress)) {
|
38
|
+
return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
|
39
|
+
}
|
40
|
+
|
41
|
+
const isContractAddress = yield this._isContractAddress(contractAddress);
|
42
|
+
|
43
|
+
if (!isContractAddress) {
|
44
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
45
|
+
}
|
46
|
+
|
47
|
+
let args = {
|
48
|
+
optType: 2,
|
49
|
+
contractAddress,
|
50
|
+
input: JSON.stringify({
|
51
|
+
method: 'contractInfo',
|
52
|
+
}),
|
53
|
+
};
|
54
|
+
|
55
|
+
args = humps.decamelizeKeys(args, { separator: '_' });
|
56
|
+
// convert long to int
|
57
|
+
args = this._longToInt(args);
|
58
|
+
args = JSONbig.stringify(args);
|
59
|
+
|
60
|
+
let info = yield this._request('post', 'callContract', args);
|
61
|
+
info = JSONbig.parse(info.result.query_rets[0].result.value);
|
62
|
+
const contractInfo = info.contractInfo;
|
63
|
+
|
64
|
+
return this._responseData({
|
65
|
+
ctp: contractInfo.ctp,
|
66
|
+
name: contractInfo.name,
|
67
|
+
symbol: contractInfo.symbol,
|
68
|
+
totalSupply: contractInfo.totalSupply,
|
69
|
+
decimals: contractInfo.decimals,
|
70
|
+
contractOwner: contractInfo.contractOwner,
|
71
|
+
});
|
72
|
+
} catch (err) {
|
73
|
+
throw err;
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
|
78
|
+
proto.getName = function* (contractAddress) {
|
79
|
+
try {
|
80
|
+
if (!keypair.checkAddress(contractAddress)) {
|
81
|
+
return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
|
82
|
+
}
|
83
|
+
|
84
|
+
const isContractAddress = yield this._isContractAddress(contractAddress);
|
85
|
+
if (!isContractAddress) {
|
86
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
87
|
+
}
|
88
|
+
|
89
|
+
const data = yield this.getInfo(contractAddress);
|
90
|
+
|
91
|
+
if (data.result === '') {
|
92
|
+
return this._responseData('');
|
93
|
+
}
|
94
|
+
|
95
|
+
return this._responseData({
|
96
|
+
name: data.result.name,
|
97
|
+
});
|
98
|
+
} catch (err) {
|
99
|
+
throw err;
|
100
|
+
}
|
101
|
+
};
|
102
|
+
|
103
|
+
proto.getSymbol = function* (contractAddress) {
|
104
|
+
try {
|
105
|
+
if (!keypair.checkAddress(contractAddress)) {
|
106
|
+
return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
|
107
|
+
}
|
108
|
+
|
109
|
+
const isContractAddress = yield this._isContractAddress(contractAddress);
|
110
|
+
if (!isContractAddress) {
|
111
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
112
|
+
}
|
113
|
+
|
114
|
+
const data = yield this.getInfo(contractAddress);
|
115
|
+
|
116
|
+
if (data.result === '') {
|
117
|
+
return this._responseData('');
|
118
|
+
}
|
119
|
+
|
120
|
+
return this._responseData({
|
121
|
+
symbol: data.result.symbol,
|
122
|
+
});
|
123
|
+
} catch (err) {
|
124
|
+
throw err;
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
proto.getDecimals = function* (contractAddress) {
|
129
|
+
try {
|
130
|
+
if (!keypair.checkAddress(contractAddress)) {
|
131
|
+
return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
|
132
|
+
}
|
133
|
+
|
134
|
+
const isContractAddress = yield this._isContractAddress(contractAddress);
|
135
|
+
if (!isContractAddress) {
|
136
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
137
|
+
}
|
138
|
+
|
139
|
+
const data = yield this.getInfo(contractAddress);
|
140
|
+
|
141
|
+
if (data.result === '') {
|
142
|
+
return this._responseData('');
|
143
|
+
}
|
144
|
+
|
145
|
+
return this._responseData({
|
146
|
+
decimals: data.result.decimals,
|
147
|
+
});
|
148
|
+
} catch (err) {
|
149
|
+
throw err;
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
proto.getTotalSupply = function* (contractAddress) {
|
154
|
+
try {
|
155
|
+
if (!keypair.checkAddress(contractAddress)) {
|
156
|
+
return this._responseError(errors.INVALID_CONTRACTADDRESS_ERROR);
|
157
|
+
}
|
158
|
+
|
159
|
+
const isContractAddress = yield this._isContractAddress(contractAddress);
|
160
|
+
if (!isContractAddress) {
|
161
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
162
|
+
}
|
163
|
+
|
164
|
+
const data = yield this.getInfo(contractAddress);
|
165
|
+
|
166
|
+
if (data.result === '') {
|
167
|
+
return this._responseData('');
|
168
|
+
}
|
169
|
+
|
170
|
+
return this._responseData({
|
171
|
+
totalSupply: data.result.totalSupply,
|
172
|
+
});
|
173
|
+
} catch (err) {
|
174
|
+
throw err;
|
175
|
+
}
|
176
|
+
};
|
177
|
+
|
178
|
+
|
179
|
+
proto.getBalance = function* (args) {
|
180
|
+
try {
|
181
|
+
|
182
|
+
if (is.array(args) || !is.object(args)) {
|
183
|
+
return this._responseError(errors.INVALID_ARGUMENTS);
|
184
|
+
}
|
185
|
+
|
186
|
+
const schema = {
|
187
|
+
contractAddress: {
|
188
|
+
required: true,
|
189
|
+
address: true,
|
190
|
+
},
|
191
|
+
tokenOwner: {
|
192
|
+
required: true,
|
193
|
+
address: true,
|
194
|
+
},
|
195
|
+
};
|
196
|
+
|
197
|
+
if (!this._validate(args, schema).tag) {
|
198
|
+
const msg = this._validate(args, schema).msg;
|
199
|
+
return this._responseError(errors[msg]);
|
200
|
+
}
|
201
|
+
|
202
|
+
const isContractAddress = yield this._isContractAddress(args.contractAddress);
|
203
|
+
|
204
|
+
if (!isContractAddress) {
|
205
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
206
|
+
}
|
207
|
+
|
208
|
+
let data = {
|
209
|
+
optType: 2,
|
210
|
+
contractAddress: args.contractAddress,
|
211
|
+
input: JSON.stringify({
|
212
|
+
method: 'balanceOf',
|
213
|
+
params: {
|
214
|
+
address: args.tokenOwner,
|
215
|
+
}
|
216
|
+
}),
|
217
|
+
};
|
218
|
+
|
219
|
+
data = humps.decamelizeKeys(data, { separator: '_' });
|
220
|
+
// convert long to int
|
221
|
+
data = this._longToInt(data);
|
222
|
+
data = JSONbig.stringify(data);
|
223
|
+
|
224
|
+
let info = yield this._request('post', 'callContract', data);
|
225
|
+
|
226
|
+
if (info.result.query_rets[0].result) {
|
227
|
+
info = JSONbig.parse(info.result.query_rets[0].result.value);
|
228
|
+
return this._responseData(info);
|
229
|
+
} else {
|
230
|
+
return this._responseError(errors.NO_SUCH_TOKEN_ERROR);
|
231
|
+
}
|
232
|
+
} catch (err) {
|
233
|
+
throw err;
|
234
|
+
}
|
235
|
+
};
|
236
|
+
|
237
|
+
proto.allowance = function* (args) {
|
238
|
+
try {
|
239
|
+
|
240
|
+
if (is.array(args) || !is.object(args)) {
|
241
|
+
return this._responseError(errors.INVALID_ARGUMENTS);
|
242
|
+
}
|
243
|
+
|
244
|
+
const schema = {
|
245
|
+
contractAddress: {
|
246
|
+
required: true,
|
247
|
+
address: true,
|
248
|
+
},
|
249
|
+
tokenOwner: {
|
250
|
+
required: true,
|
251
|
+
address: true,
|
252
|
+
},
|
253
|
+
spender: {
|
254
|
+
required: true,
|
255
|
+
address: true,
|
256
|
+
}
|
257
|
+
};
|
258
|
+
|
259
|
+
if (!this._validate(args, schema).tag) {
|
260
|
+
const msg = this._validate(args, schema).msg;
|
261
|
+
return this._responseError(errors[msg]);
|
262
|
+
}
|
263
|
+
|
264
|
+
const isContractAddress = yield this._isContractAddress(args.contractAddress);
|
265
|
+
|
266
|
+
if (!isContractAddress) {
|
267
|
+
return this._responseError(errors.CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR);
|
268
|
+
}
|
269
|
+
|
270
|
+
let data = {
|
271
|
+
optType: 2,
|
272
|
+
contractAddress: args.contractAddress,
|
273
|
+
input: JSON.stringify({
|
274
|
+
method: 'allowance',
|
275
|
+
params: {
|
276
|
+
owner: args.tokenOwner,
|
277
|
+
spender: args.spender,
|
278
|
+
}
|
279
|
+
}),
|
280
|
+
};
|
281
|
+
|
282
|
+
data = humps.decamelizeKeys(data, { separator: '_' });
|
283
|
+
// convert long to int
|
284
|
+
data = this._longToInt(data);
|
285
|
+
data = JSONbig.stringify(data);
|
286
|
+
|
287
|
+
let info = yield this._request('post', 'callContract', data);
|
288
|
+
|
289
|
+
if (info.result.query_rets[0].result) {
|
290
|
+
info = JSONbig.parse(info.result.query_rets[0].result.value);
|
291
|
+
return this._responseData(info);
|
292
|
+
} else {
|
293
|
+
return this._responseError(errors.NO_SUCH_TOKEN_ERROR);
|
294
|
+
}
|
295
|
+
} catch (err) {
|
296
|
+
throw err;
|
297
|
+
}
|
298
|
+
};
|
299
|
+
|
300
|
+
|
301
|
+
wrap(proto);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Asset = require('./asset');
|
4
|
+
const Ctp10Token = require('./ctp10Token');
|
5
|
+
|
6
|
+
module.exports = Collection;
|
7
|
+
|
8
|
+
function Collection(options) {
|
9
|
+
if (!(this instanceof Collection)) {
|
10
|
+
return new Collection(options);
|
11
|
+
}
|
12
|
+
|
13
|
+
this.options = options;
|
14
|
+
|
15
|
+
this.asset = new Asset(options);
|
16
|
+
this.ctp10Token = new Ctp10Token(options);
|
17
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const wrap = require('co-wrap-all');
|
4
|
+
const merge = require('merge-descriptors');
|
5
|
+
const BigNumber = require('bignumber.js');
|
6
|
+
const is = require('is-type-of');
|
7
|
+
const long = require('long');
|
8
|
+
|
9
|
+
module.exports = Util;
|
10
|
+
|
11
|
+
function Util(options) {
|
12
|
+
if (!(this instanceof Util)) {
|
13
|
+
return new Util(options);
|
14
|
+
}
|
15
|
+
|
16
|
+
this.options = options;
|
17
|
+
}
|
18
|
+
|
19
|
+
const proto = Util.prototype;
|
20
|
+
|
21
|
+
merge(proto, require('../common/util'));
|
22
|
+
|
23
|
+
proto.isBigNumber = function (object) {
|
24
|
+
return this._isBigNumber(object);
|
25
|
+
};
|
26
|
+
|
27
|
+
proto.toBigNumber = function(data) {
|
28
|
+
return this._toBigNumber(data);
|
29
|
+
};
|
30
|
+
|
31
|
+
proto.utfToHex = function(str) {
|
32
|
+
if (!is.string(str)) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
|
36
|
+
return Buffer.from(str, 'utf8').toString('hex');
|
37
|
+
};
|
38
|
+
|
39
|
+
proto.hexToUtf = function(str) {
|
40
|
+
if (!is.string(str) ||
|
41
|
+
str === '' ||
|
42
|
+
!this._isHexString(str)) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
|
46
|
+
return Buffer.from(str, 'hex').toString('utf8');
|
47
|
+
};
|
48
|
+
|
49
|
+
proto.buToMo = function(bu) {
|
50
|
+
if (!this._isAvailableBu(bu)) {
|
51
|
+
return '';
|
52
|
+
}
|
53
|
+
|
54
|
+
const oneMo = Math.pow(10, 8);
|
55
|
+
const mo = new BigNumber(bu).times(oneMo);
|
56
|
+
return mo.toString();
|
57
|
+
};
|
58
|
+
|
59
|
+
proto.moToBu = function(mo) {
|
60
|
+
if (!this._isAvailableValue(mo)) {
|
61
|
+
return '';
|
62
|
+
}
|
63
|
+
|
64
|
+
const oneMo = Math.pow(10, 8);
|
65
|
+
const bu = new BigNumber(mo).dividedBy(oneMo);
|
66
|
+
return bu.toString();
|
67
|
+
};
|
68
|
+
|
69
|
+
proto.unitWithDecimals = function(amount, decimals) {
|
70
|
+
const reg = /^[0-9]+$/;
|
71
|
+
|
72
|
+
if (!reg.test(amount) || !reg.test(decimals)) {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
|
76
|
+
amount = new BigNumber(amount);
|
77
|
+
decimals = new BigNumber(Math.pow(10, decimals));
|
78
|
+
const amountWithDecimals = amount.times(decimals);
|
79
|
+
|
80
|
+
if (amountWithDecimals.isGreaterThanOrEqualTo(0) && amountWithDecimals.isLessThanOrEqualTo(long.MAX_VALUE.toString())) {
|
81
|
+
return amountWithDecimals.toString();
|
82
|
+
}
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
|
86
|
+
wrap(proto);
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="WEB_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
6
|
+
<orderEntry type="inheritedJdk" />
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
8
|
+
</component>
|
9
|
+
</module>
|
package/package.json
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"name": "openchain-nodejs-ts-yxl",
|
3
|
+
"version": "1.0.1",
|
4
|
+
"description": "openchain sdk",
|
5
|
+
"main": "index.js",
|
6
|
+
"types": "index.d.ts",
|
7
|
+
"scripts": {
|
8
|
+
"test": "mocha"
|
9
|
+
},
|
10
|
+
"keywords": [
|
11
|
+
"openchain",
|
12
|
+
"openchain-sdk"
|
13
|
+
],
|
14
|
+
"author": "OpenChain",
|
15
|
+
"license": "ISC",
|
16
|
+
"dependencies": {
|
17
|
+
"bignumber.js": "^7.2.1",
|
18
|
+
"buffer-to-uint8array": "^1.1.0",
|
19
|
+
"co-wrap-all": "^1.0.0",
|
20
|
+
"humps": "^2.0.1",
|
21
|
+
"is-type-of": "^1.2.0",
|
22
|
+
"json-bigint": "^0.2.3",
|
23
|
+
"long": "^4.0.0",
|
24
|
+
"merge-descriptors": "^1.0.1",
|
25
|
+
"protobufjs": "^6.8.8",
|
26
|
+
"request": "^2.87.0",
|
27
|
+
"request-promise": "^4.2.2",
|
28
|
+
"yxchain-encryption-nodejs": "^1.0.1"
|
29
|
+
},
|
30
|
+
"devDependencies": {
|
31
|
+
"chai": "^4.1.2",
|
32
|
+
"mocha": "^5.2.0"
|
33
|
+
},
|
34
|
+
"repository": {
|
35
|
+
"type": "git",
|
36
|
+
"url": "",
|
37
|
+
"web": ""
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const OpenChainSDK = require('../index');
|
5
|
+
|
6
|
+
const sdk = new OpenChainSDK({
|
7
|
+
host: 'http://localhost/node/api',
|
8
|
+
});
|
9
|
+
|
10
|
+
describe('Test token.ctp10Token', function() {
|
11
|
+
|
12
|
+
it('test token.ctp10Token.checkValid()', async() => {
|
13
|
+
let address = 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse';
|
14
|
+
let data = await sdk.token.ctp10Token.checkValid(address);
|
15
|
+
data.result.isValid.should.equal(true);
|
16
|
+
address = 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t';
|
17
|
+
data = await sdk.token.ctp10Token.checkValid(address);
|
18
|
+
data.errorCode.should.equal(11037)
|
19
|
+
});
|
20
|
+
|
21
|
+
|
22
|
+
it('test token.ctp10Token.getInfo()', async() => {
|
23
|
+
let address = 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse';
|
24
|
+
let data = await sdk.token.ctp10Token.getInfo(address);
|
25
|
+
console.log(data);
|
26
|
+
});
|
27
|
+
|
28
|
+
it('test token.ctp10Token.getName()', async() => {
|
29
|
+
let address = 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse';
|
30
|
+
let data = await sdk.token.ctp10Token.getName(address);
|
31
|
+
console.log(data);
|
32
|
+
});
|
33
|
+
|
34
|
+
it('test token.ctp10Token.getSymbol()', async() => {
|
35
|
+
let address = 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse';
|
36
|
+
let data = await sdk.token.ctp10Token.getSymbol(address);
|
37
|
+
console.log(data);
|
38
|
+
});
|
39
|
+
|
40
|
+
it('test token.ctp10Token.getDecimals()', async() => {
|
41
|
+
let address = 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse';
|
42
|
+
let data = await sdk.token.ctp10Token.getDecimals(address);
|
43
|
+
console.log(data);
|
44
|
+
});
|
45
|
+
|
46
|
+
it('test token.ctp10Token.getTotalSupply()', async() => {
|
47
|
+
let address = 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse';
|
48
|
+
let data = await sdk.token.ctp10Token.getTotalSupply(address);
|
49
|
+
console.log(data);
|
50
|
+
});
|
51
|
+
|
52
|
+
it('test token.ctp10Token.getBalance()', async() => {
|
53
|
+
let data = await sdk.token.ctp10Token.getBalance({
|
54
|
+
contractAddress: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
55
|
+
tokenOwner: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
56
|
+
});
|
57
|
+
data.errorCode.should.equal(0);
|
58
|
+
|
59
|
+
data = await sdk.token.ctp10Token.getBalance({
|
60
|
+
contractAddress: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
61
|
+
tokenOwner: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
|
62
|
+
});
|
63
|
+
data.errorCode.should.equal(11030);
|
64
|
+
|
65
|
+
data = await sdk.token.ctp10Token.getBalance({
|
66
|
+
contractAddress: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pseA',
|
67
|
+
tokenOwner: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
|
68
|
+
});
|
69
|
+
data.errorCode.should.equal(11037);
|
70
|
+
|
71
|
+
data = await sdk.token.ctp10Token.getBalance({
|
72
|
+
contractAddress: '',
|
73
|
+
tokenOwner: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
|
74
|
+
});
|
75
|
+
data.errorCode.should.equal(11037);
|
76
|
+
|
77
|
+
data = await sdk.token.ctp10Token.getBalance({
|
78
|
+
contractAddress: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
79
|
+
tokenOwner: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3rA',
|
80
|
+
});
|
81
|
+
data.errorCode.should.equal(11035);
|
82
|
+
|
83
|
+
});
|
84
|
+
|
85
|
+
it('test token.ctp10Token.allowance()', async() => {
|
86
|
+
|
87
|
+
let data = await sdk.token.ctp10Token.allowance({
|
88
|
+
contractAddress: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
89
|
+
tokenOwner: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
90
|
+
spender: 'YxLSTjYcKBcCJ3tDnBM6z8u8uvFNaZ7L8pse',
|
91
|
+
});
|
92
|
+
console.log(data);
|
93
|
+
});
|
94
|
+
|
95
|
+
|
96
|
+
});
|