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,128 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const BigNumber = require('bignumber.js');
|
5
|
+
|
6
|
+
const OpenChainSDK = require('../index');
|
7
|
+
|
8
|
+
const sdk = new OpenChainSDK({
|
9
|
+
host: 'localhost/node/api',
|
10
|
+
});
|
11
|
+
|
12
|
+
describe('Test build blob', function() {
|
13
|
+
|
14
|
+
it('test transaction.buildBlob()', async () => {
|
15
|
+
const sourceAddress = 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t';
|
16
|
+
const accountInfo = await sdk.account.getInfo(sourceAddress);
|
17
|
+
|
18
|
+
if (accountInfo.errorCode !== 0) {
|
19
|
+
console.log(accountInfo);
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
let nonce = accountInfo.result.nonce;
|
24
|
+
nonce = new BigNumber(nonce).plus(1).toString(10);
|
25
|
+
|
26
|
+
const acountActivateOperation = {
|
27
|
+
type: 'activateAccount',
|
28
|
+
data: {
|
29
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
30
|
+
destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
31
|
+
initBalance: '1000',
|
32
|
+
metadata: 'Test Account Activate',
|
33
|
+
},
|
34
|
+
};
|
35
|
+
|
36
|
+
let data = sdk.transaction.buildBlob({
|
37
|
+
sourceAddress,
|
38
|
+
gasPrice: '1234',
|
39
|
+
feeLimit: '123',
|
40
|
+
nonce: `${nonce}`,
|
41
|
+
ceilLedgerSeq: '1',
|
42
|
+
operations: [ acountActivateOperation ],
|
43
|
+
metadata: 'oh my test build blob',
|
44
|
+
});
|
45
|
+
|
46
|
+
data.errorCode.should.equal(0);
|
47
|
+
data.result.should.be.a('object');
|
48
|
+
data.result.should.have.property('transactionBlob');
|
49
|
+
|
50
|
+
// Invalid sourceAddress
|
51
|
+
data = sdk.transaction.buildBlob({
|
52
|
+
sourceAddress: '',
|
53
|
+
gasPrice: '1234',
|
54
|
+
feeLimit: '123',
|
55
|
+
nonce: `${nonce}`,
|
56
|
+
ceilLedgerSeq: '1',
|
57
|
+
operations: [ acountActivateOperation ],
|
58
|
+
metadata: 'oh my test build blob',
|
59
|
+
});
|
60
|
+
data.errorCode.should.equal(11002);
|
61
|
+
|
62
|
+
// Invalid gasPrice
|
63
|
+
data = sdk.transaction.buildBlob({
|
64
|
+
sourceAddress,
|
65
|
+
gasPrice: '-1234',
|
66
|
+
feeLimit: '123',
|
67
|
+
nonce: `${nonce}`,
|
68
|
+
ceilLedgerSeq: '1',
|
69
|
+
operations: [ acountActivateOperation ],
|
70
|
+
metadata: 'oh my test build blob',
|
71
|
+
});
|
72
|
+
data.errorCode.should.equal(11049);
|
73
|
+
|
74
|
+
// Invalid feeLimit
|
75
|
+
data = sdk.transaction.buildBlob({
|
76
|
+
sourceAddress,
|
77
|
+
gasPrice: '1234',
|
78
|
+
feeLimit: '',
|
79
|
+
nonce: `${nonce}`,
|
80
|
+
ceilLedgerSeq: '1',
|
81
|
+
operations: [ acountActivateOperation ],
|
82
|
+
metadata: 'oh my test build blob',
|
83
|
+
});
|
84
|
+
data.errorCode.should.equal(11050);
|
85
|
+
|
86
|
+
// Invalid nonce
|
87
|
+
data = sdk.transaction.buildBlob({
|
88
|
+
sourceAddress,
|
89
|
+
gasPrice: '100',
|
90
|
+
feeLimit: '1000',
|
91
|
+
nonce: '',
|
92
|
+
ceilLedgerSeq: '1',
|
93
|
+
operations: [ acountActivateOperation ],
|
94
|
+
metadata: 'oh my test build blob',
|
95
|
+
});
|
96
|
+
|
97
|
+
data.errorCode.should.equal(11048);
|
98
|
+
|
99
|
+
// Invalid metadata
|
100
|
+
data = sdk.transaction.buildBlob({
|
101
|
+
sourceAddress,
|
102
|
+
gasPrice: '100',
|
103
|
+
feeLimit: '1000',
|
104
|
+
nonce,
|
105
|
+
ceilLedgerSeq: '1',
|
106
|
+
operations: [ acountActivateOperation ],
|
107
|
+
metadata: 1234,
|
108
|
+
});
|
109
|
+
|
110
|
+
data.errorCode.should.equal(15028);
|
111
|
+
|
112
|
+
// Invalid operation
|
113
|
+
delete acountActivateOperation.type;
|
114
|
+
data = sdk.transaction.buildBlob({
|
115
|
+
sourceAddress,
|
116
|
+
gasPrice: '100',
|
117
|
+
feeLimit: '1000',
|
118
|
+
nonce,
|
119
|
+
ceilLedgerSeq: '1',
|
120
|
+
operations: [ acountActivateOperation ],
|
121
|
+
metadata: 'oh my test build blob',
|
122
|
+
});
|
123
|
+
|
124
|
+
data.errorCode.should.equal(15022);
|
125
|
+
|
126
|
+
});
|
127
|
+
|
128
|
+
});
|
@@ -0,0 +1,165 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const OpenChainSDK = require('../index');
|
5
|
+
|
6
|
+
const sdk = new OpenChainSDK({
|
7
|
+
host: 'localhost/node/api',
|
8
|
+
});
|
9
|
+
|
10
|
+
describe('Test openchain-sdk block service', function() {
|
11
|
+
|
12
|
+
it('test block.getNumber()', async() => {
|
13
|
+
let data = await sdk.block.getNumber();
|
14
|
+
data.errorCode.should.equal(0);
|
15
|
+
data.result.should.be.a('object');
|
16
|
+
data.result.should.have.property('header').be.a('object').have.property('blockNumber');
|
17
|
+
});
|
18
|
+
|
19
|
+
it('test block.checkBlockStatus()', async() => {
|
20
|
+
let data = await sdk.block.checkStatus();
|
21
|
+
data.errorCode.should.equal(0);
|
22
|
+
data.result.should.be.a('object').have.property('isSynchronous').be.a('boolean');
|
23
|
+
});
|
24
|
+
|
25
|
+
it('test block.getTransactions(blockNumber)', async() => {
|
26
|
+
let data = await sdk.block.getTransactions('100');
|
27
|
+
data.errorCode.should.equal(0);
|
28
|
+
data.result.should.be.a('object');
|
29
|
+
data.result.should.have.property('total_count');
|
30
|
+
data.result.should.have.property('transactions');
|
31
|
+
|
32
|
+
data = await sdk.block.getTransactions('1');
|
33
|
+
data.errorCode.should.equal(15014);
|
34
|
+
|
35
|
+
data = await sdk.block.getTransactions('abc');
|
36
|
+
data.errorCode.should.equal(11060);
|
37
|
+
|
38
|
+
data = await sdk.block.getTransactions('');
|
39
|
+
data.errorCode.should.equal(11060);
|
40
|
+
|
41
|
+
data = await sdk.block.getTransactions('0');
|
42
|
+
data.errorCode.should.equal(11060);
|
43
|
+
|
44
|
+
data = await sdk.block.getTransactions(123);
|
45
|
+
data.errorCode.should.equal(11060);
|
46
|
+
|
47
|
+
});
|
48
|
+
|
49
|
+
it('test block.getInfo(blockNumber)', async() => {
|
50
|
+
let data = await sdk.block.getInfo('100');
|
51
|
+
data.errorCode.should.equal(0);
|
52
|
+
data.result.should.be.a('object');
|
53
|
+
data.result.should.have.property('closeTime');
|
54
|
+
data.result.should.have.property('number');
|
55
|
+
data.result.should.have.property('txCount');
|
56
|
+
data.result.should.have.property('version');
|
57
|
+
|
58
|
+
data = await sdk.block.getInfo('');
|
59
|
+
data.errorCode.should.equal(11060);
|
60
|
+
|
61
|
+
data = await sdk.block.getInfo();
|
62
|
+
data.errorCode.should.equal(11060);
|
63
|
+
|
64
|
+
data = await sdk.block.getInfo(123);
|
65
|
+
data.errorCode.should.equal(11060);
|
66
|
+
|
67
|
+
data = await sdk.block.getInfo('-1');
|
68
|
+
data.errorCode.should.equal(11060);
|
69
|
+
});
|
70
|
+
|
71
|
+
|
72
|
+
it('test block.getLatestInfo()', async() => {
|
73
|
+
let data = await sdk.block.getLatestInfo();
|
74
|
+
data.errorCode.should.equal(0);
|
75
|
+
data.result.should.be.a('object');
|
76
|
+
data.result.should.have.property('closeTime');
|
77
|
+
data.result.should.have.property('number');
|
78
|
+
data.result.should.have.property('txCount');
|
79
|
+
data.result.should.have.property('version');
|
80
|
+
});
|
81
|
+
|
82
|
+
it('test block.getValidators(blockNumber)', async() => {
|
83
|
+
let data = await sdk.block.getValidators('100');
|
84
|
+
data.errorCode.should.equal(0);
|
85
|
+
data.result.should.be.a('object');
|
86
|
+
data.result.should.have.property('validators').be.a('array');
|
87
|
+
|
88
|
+
data = await sdk.block.getValidators('');
|
89
|
+
data.errorCode.should.equal(11060);
|
90
|
+
|
91
|
+
data = await sdk.block.getValidators();
|
92
|
+
data.errorCode.should.equal(11060);
|
93
|
+
|
94
|
+
data = await sdk.block.getValidators('abc');
|
95
|
+
data.errorCode.should.equal(11060);
|
96
|
+
});
|
97
|
+
|
98
|
+
it('test block.getLatestValidators()', async() => {
|
99
|
+
let data = await sdk.block.getLatestValidators();
|
100
|
+
data.errorCode.should.equal(0);
|
101
|
+
data.result.should.be.a('object');
|
102
|
+
data.result.should.have.property('validators').be.a('array');
|
103
|
+
});
|
104
|
+
|
105
|
+
it('test block.getReward(blockNumber)', async() => {
|
106
|
+
let data = await sdk.block.getReward('100');
|
107
|
+
data.errorCode.should.equal(0);
|
108
|
+
data.result.should.be.a('object');
|
109
|
+
data.result.should.have.property('blockReward');
|
110
|
+
data.result.should.have.property('validatorsReward');
|
111
|
+
|
112
|
+
data = await sdk.block.getReward();
|
113
|
+
data.errorCode.should.equal(11060);
|
114
|
+
|
115
|
+
data = await sdk.block.getReward('');
|
116
|
+
data.errorCode.should.equal(11060);
|
117
|
+
|
118
|
+
data = await sdk.block.getReward('abc');
|
119
|
+
data.errorCode.should.equal(11060);
|
120
|
+
});
|
121
|
+
|
122
|
+
it('test block.getLatestReward()', async() => {
|
123
|
+
let data = await sdk.block.getLatestReward();
|
124
|
+
data.errorCode.should.equal(0);
|
125
|
+
data.result.should.be.a('object');
|
126
|
+
data.result.should.have.property('blockReward');
|
127
|
+
data.result.should.have.property('validatorsReward');
|
128
|
+
});
|
129
|
+
|
130
|
+
|
131
|
+
it('test getFees(blockNumber)', async() => {
|
132
|
+
let data = await sdk.block.getFees('100');
|
133
|
+
data.errorCode.should.equal(0);
|
134
|
+
data.result.should.be.a('object');
|
135
|
+
data.result.should.have.property('fees');
|
136
|
+
data.result.fees.should.have.property('base_reserve');
|
137
|
+
data.result.fees.should.have.property('gas_price');
|
138
|
+
|
139
|
+
data = await sdk.block.getFees();
|
140
|
+
data.errorCode.should.equal(11060);
|
141
|
+
|
142
|
+
data = await sdk.block.getFees('');
|
143
|
+
data.errorCode.should.equal(11060);
|
144
|
+
|
145
|
+
data = await sdk.block.getFees('abc');
|
146
|
+
data.errorCode.should.equal(11060);
|
147
|
+
|
148
|
+
data = await sdk.block.getFees(-1);
|
149
|
+
data.errorCode.should.equal(11060);
|
150
|
+
|
151
|
+
data = await sdk.block.getFees(0.1);
|
152
|
+
data.errorCode.should.equal(11060);
|
153
|
+
|
154
|
+
});
|
155
|
+
|
156
|
+
it('test getLatestFees()', async() => {
|
157
|
+
const data = await sdk.block.getLatestFees();
|
158
|
+
data.errorCode.should.equal(0);
|
159
|
+
data.result.should.be.a('object');
|
160
|
+
data.result.should.have.property('fees');
|
161
|
+
data.result.fees.should.have.property('base_reserve');
|
162
|
+
data.result.fees.should.have.property('gas_price');
|
163
|
+
});
|
164
|
+
|
165
|
+
});
|
@@ -0,0 +1,64 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const OpenChainSDK = require('../index');
|
5
|
+
|
6
|
+
|
7
|
+
const sdk = new OpenChainSDK({
|
8
|
+
host: 'localhost/node/api',
|
9
|
+
});
|
10
|
+
|
11
|
+
describe('Test bu send operation', function() {
|
12
|
+
|
13
|
+
it('test operation.buSendOperation()', function() {
|
14
|
+
let data = sdk.operation.buSendOperation({
|
15
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
16
|
+
destAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
|
17
|
+
buAmount: '6000',
|
18
|
+
metadata: 'oh my send bu',
|
19
|
+
});
|
20
|
+
data.errorCode.should.equal(0);
|
21
|
+
data.result.should.be.a('object');
|
22
|
+
data.result.should.have.property('operation');
|
23
|
+
data.result.operation.should.be.a('object');
|
24
|
+
data.result.operation.should.have.property('type').equal('payCoin');
|
25
|
+
data.result.operation.should.have.property('data');
|
26
|
+
|
27
|
+
// Invalid sourceAddress
|
28
|
+
data = sdk.operation.buSendOperation({
|
29
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2tA',
|
30
|
+
destAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
|
31
|
+
buAmount: '6000',
|
32
|
+
metadata: 'oh my send bu',
|
33
|
+
});
|
34
|
+
data.errorCode.should.equal(11002);
|
35
|
+
|
36
|
+
data = sdk.operation.buSendOperation({
|
37
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
38
|
+
destAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2A',
|
39
|
+
buAmount: '6000',
|
40
|
+
metadata: 'oh my send bu',
|
41
|
+
});
|
42
|
+
data.errorCode.should.equal(11003);
|
43
|
+
|
44
|
+
// Invalid buAmount
|
45
|
+
data = sdk.operation.buSendOperation({
|
46
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
47
|
+
destAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
|
48
|
+
buAmount: '6000A',
|
49
|
+
metadata: 'oh my send bu',
|
50
|
+
});
|
51
|
+
data.errorCode.should.equal(11026);
|
52
|
+
|
53
|
+
// Invalid metadata
|
54
|
+
data = sdk.operation.buSendOperation({
|
55
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
56
|
+
destAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
|
57
|
+
buAmount: '6000',
|
58
|
+
metadata: '',
|
59
|
+
});
|
60
|
+
|
61
|
+
data.errorCode.should.equal(15028);
|
62
|
+
});
|
63
|
+
|
64
|
+
});
|
@@ -0,0 +1,64 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const OpenChainSDK = require('../index');
|
5
|
+
|
6
|
+
const sdk = new OpenChainSDK({
|
7
|
+
host: 'localhost/node/api',
|
8
|
+
});
|
9
|
+
|
10
|
+
describe('Test openchain-sdk contract service', function() {
|
11
|
+
|
12
|
+
it('test contract.getInfo()', async() => {
|
13
|
+
let data = await sdk.contract.getInfo('G49ScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r');
|
14
|
+
data.errorCode.should.equal(0);
|
15
|
+
data = await sdk.contract.getInfo('G49SqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2');
|
16
|
+
data.errorCode.should.equal(11038);
|
17
|
+
data = await sdk.contract.getInfo('G49SqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2A');
|
18
|
+
data.errorCode.should.equal(11006);
|
19
|
+
|
20
|
+
data = await sdk.contract.getInfo('G49ScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r');
|
21
|
+
data.errorCode.should.equal(11038);
|
22
|
+
|
23
|
+
});
|
24
|
+
|
25
|
+
it('test contract.checkValid()', async() => {
|
26
|
+
|
27
|
+
let data = await sdk.contract.checkValid('G49ScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r');
|
28
|
+
data.errorCode.should.equal(0);
|
29
|
+
data.result.should.be.a('object');
|
30
|
+
data.result.isValid.should.equal(false);
|
31
|
+
|
32
|
+
data = await sdk.contract.checkValid('G49ScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r');
|
33
|
+
data.errorCode.should.equal(0);
|
34
|
+
data.result.should.be.a('object');
|
35
|
+
data.result.isValid.should.equal(true);
|
36
|
+
|
37
|
+
data = await sdk.contract.checkValid('G49ScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3rA');
|
38
|
+
data.errorCode.should.equal(11037);
|
39
|
+
});
|
40
|
+
|
41
|
+
it('test contract.getAddress()', async() => {
|
42
|
+
let hash = 'f298d08ec3987adc3aeef73e81cbb49cbad2316145ba190700de2d78657880c0';
|
43
|
+
// hash = 'G49ScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3rA';
|
44
|
+
let data = await sdk.contract.getAddress(hash);
|
45
|
+
console.log(data);
|
46
|
+
console.log(JSON.stringify(data))
|
47
|
+
});
|
48
|
+
|
49
|
+
it('test contract.call()', async() => {
|
50
|
+
|
51
|
+
let data = await sdk.contract.call({
|
52
|
+
optType: 2,
|
53
|
+
// code: 'leo'
|
54
|
+
// contractAddress: 'G49SqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
|
55
|
+
contractAddress: 'G49SqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
|
56
|
+
input: JSON.stringify({
|
57
|
+
// method: 'contractInfo',
|
58
|
+
method: 'name',
|
59
|
+
}),
|
60
|
+
});
|
61
|
+
console.log(JSON.stringify(data));
|
62
|
+
});
|
63
|
+
|
64
|
+
});
|
@@ -0,0 +1,41 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const OpenChainSDK = require('../index');
|
5
|
+
|
6
|
+
const sdk = new OpenChainSDK({
|
7
|
+
host: 'localhost/node/api',
|
8
|
+
});
|
9
|
+
|
10
|
+
describe('Test contract create operation', function() {
|
11
|
+
|
12
|
+
it('test operation.contractCreateOperation()', function() {
|
13
|
+
|
14
|
+
let contractCreateOperation = sdk.operation.contractCreateOperation({
|
15
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
16
|
+
initBalance: '1000',
|
17
|
+
type: 0,
|
18
|
+
payload: 'afasfsaff',
|
19
|
+
initInput: 'aaaaa',
|
20
|
+
metadata: 'Test contract create operation',
|
21
|
+
});
|
22
|
+
|
23
|
+
if (contractCreateOperation.errorCode !== 0) {
|
24
|
+
console.log(contractCreateOperation);
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
28
|
+
const operationItem = contractCreateOperation.result.operation;
|
29
|
+
|
30
|
+
const blobInfo = sdk.transaction.buildBlob({
|
31
|
+
sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
32
|
+
gasPrice: '1000',
|
33
|
+
feeLimit: '1000000',
|
34
|
+
nonce: '123',
|
35
|
+
operations: [ operationItem ],
|
36
|
+
});
|
37
|
+
|
38
|
+
console.log(blobInfo);
|
39
|
+
});
|
40
|
+
|
41
|
+
});
|
@@ -0,0 +1,116 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const BigNumber = require('bignumber.js');
|
5
|
+
const co = require('co');
|
6
|
+
|
7
|
+
const OpenChainSDK = require('../index');
|
8
|
+
|
9
|
+
const sdk = new OpenChainSDK({
|
10
|
+
host: 'localhost/node/api',
|
11
|
+
// host: '192.168.1.34:36002',
|
12
|
+
});
|
13
|
+
|
14
|
+
describe('Test create contract account transaction', function() {
|
15
|
+
|
16
|
+
it('test create contract account ', function() {
|
17
|
+
const privateKey = 'private key';
|
18
|
+
const sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
|
19
|
+
|
20
|
+
co(function* () {
|
21
|
+
const result = yield sdk.account.getNonce(sourceAddress);
|
22
|
+
|
23
|
+
if (result.errorCode !== 0) {
|
24
|
+
console.log(result);
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
let nonce = result.result.nonce;
|
28
|
+
|
29
|
+
nonce = new BigNumber(nonce).plus(1).toString(10);
|
30
|
+
|
31
|
+
let contractCreateOperation = sdk.operation.contractCreateOperation({
|
32
|
+
sourceAddress,
|
33
|
+
initBalance: '100000000',
|
34
|
+
type: 0,
|
35
|
+
payload: `
|
36
|
+
"use strict";
|
37
|
+
function init(bar)
|
38
|
+
{
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
function main(input)
|
43
|
+
{
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
`,
|
47
|
+
initInput: 'aaaaa',
|
48
|
+
// metadata: 'Test contract create operation',
|
49
|
+
});
|
50
|
+
|
51
|
+
if (contractCreateOperation.errorCode !== 0) {
|
52
|
+
console.log(contractCreateOperation);
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
|
56
|
+
const operationItem = contractCreateOperation.result.operation;
|
57
|
+
|
58
|
+
const args = {
|
59
|
+
sourceAddress,
|
60
|
+
nonce,
|
61
|
+
operations: [operationItem],
|
62
|
+
signtureNumber: '100',
|
63
|
+
// metadata: 'Test evaluation fee',
|
64
|
+
};
|
65
|
+
|
66
|
+
let feeData = yield sdk.transaction.evaluateFee(args);
|
67
|
+
if (feeData.errorCode !== 0) {
|
68
|
+
console.log(feeData);
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
|
72
|
+
let feeLimit = feeData.result.feeLimit;
|
73
|
+
let gasPrice = feeData.result.gasPrice;
|
74
|
+
|
75
|
+
// 2. build blob
|
76
|
+
let blobInfo = sdk.transaction.buildBlob({
|
77
|
+
sourceAddress: sourceAddress,
|
78
|
+
gasPrice,
|
79
|
+
feeLimit,
|
80
|
+
nonce: nonce,
|
81
|
+
operations: [ operationItem ],
|
82
|
+
});
|
83
|
+
|
84
|
+
if (blobInfo.errorCode !== 0) {
|
85
|
+
console.log(blobInfo);
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
|
89
|
+
let blob = blobInfo.result.transactionBlob;
|
90
|
+
|
91
|
+
// 3. sign blob
|
92
|
+
let signatureInfo = sdk.transaction.sign({
|
93
|
+
privateKeys: [ privateKey ],
|
94
|
+
blob,
|
95
|
+
});
|
96
|
+
|
97
|
+
if (signatureInfo.errorCode !== 0) {
|
98
|
+
console.log(signatureInfo);
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
|
102
|
+
let signature = signatureInfo.result.signatures;
|
103
|
+
// 4. submit transaction
|
104
|
+
let transactionInfo = yield sdk.transaction.submit({
|
105
|
+
blob,
|
106
|
+
signature: signature,
|
107
|
+
});
|
108
|
+
|
109
|
+
console.log(transactionInfo);
|
110
|
+
|
111
|
+
}).catch(err => {
|
112
|
+
console.log(err);
|
113
|
+
});
|
114
|
+
});
|
115
|
+
|
116
|
+
});
|
@@ -0,0 +1,109 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
require('chai').should();
|
4
|
+
const BigNumber = require('bignumber.js');
|
5
|
+
const co = require('co');
|
6
|
+
|
7
|
+
const OpenChainSDK = require('../index');
|
8
|
+
|
9
|
+
const sdk = new OpenChainSDK({
|
10
|
+
host: 'localhost/node/api',
|
11
|
+
});
|
12
|
+
|
13
|
+
describe('Test contract invoke by asset operation transaction', function() {
|
14
|
+
|
15
|
+
it('test contract invoke by asset operation' , function() {
|
16
|
+
|
17
|
+
const privateKey = 'private key';
|
18
|
+
const sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
|
19
|
+
// const contractAddress = 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2';
|
20
|
+
const contractAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
|
21
|
+
co(function* () {
|
22
|
+
const result = yield sdk.account.getNonce(sourceAddress);
|
23
|
+
|
24
|
+
if (result.errorCode !== 0) {
|
25
|
+
console.log(result);
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
let nonce = result.result.nonce;
|
29
|
+
|
30
|
+
nonce = new BigNumber(nonce).plus(1).toString(10);
|
31
|
+
|
32
|
+
let contractInvokeByBUOperation = yield sdk.operation.contractInvokeByAssetOperation({
|
33
|
+
contractAddress,
|
34
|
+
sourceAddress,
|
35
|
+
assetAmount: '1000',
|
36
|
+
input: 'aaaa',
|
37
|
+
code: 'leo',
|
38
|
+
issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
|
39
|
+
// metadata: 'Test contract create operation',
|
40
|
+
});
|
41
|
+
|
42
|
+
if (contractInvokeByBUOperation.errorCode !== 0) {
|
43
|
+
console.log(contractInvokeByBUOperation);
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
// console.log(contractInvokeByBUOperation);
|
48
|
+
// return;
|
49
|
+
const operationItem = contractInvokeByBUOperation.result.operation;
|
50
|
+
|
51
|
+
const args = {
|
52
|
+
sourceAddress,
|
53
|
+
nonce,
|
54
|
+
operations: [operationItem],
|
55
|
+
signtureNumber: '100',
|
56
|
+
// metadata: 'Test evaluation fee',
|
57
|
+
};
|
58
|
+
|
59
|
+
let feeData = yield sdk.transaction.evaluateFee(args);
|
60
|
+
if (feeData.errorCode !== 0) {
|
61
|
+
console.log(feeData);
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
|
65
|
+
let feeLimit = feeData.result.feeLimit;
|
66
|
+
let gasPrice = feeData.result.gasPrice;
|
67
|
+
|
68
|
+
// 2. build blob
|
69
|
+
let blobInfo = sdk.transaction.buildBlob({
|
70
|
+
sourceAddress: sourceAddress,
|
71
|
+
gasPrice,
|
72
|
+
feeLimit,
|
73
|
+
nonce: nonce,
|
74
|
+
operations: [ operationItem ],
|
75
|
+
});
|
76
|
+
|
77
|
+
if (blobInfo.errorCode !== 0) {
|
78
|
+
console.log(blobInfo);
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
|
82
|
+
let blob = blobInfo.result.transactionBlob;
|
83
|
+
|
84
|
+
// 3. sign blob
|
85
|
+
let signatureInfo = sdk.transaction.sign({
|
86
|
+
privateKeys: [ privateKey ],
|
87
|
+
blob,
|
88
|
+
});
|
89
|
+
|
90
|
+
if (signatureInfo.errorCode !== 0) {
|
91
|
+
console.log(signatureInfo);
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
|
95
|
+
let signature = signatureInfo.result.signatures;
|
96
|
+
// 4. submit transaction
|
97
|
+
let transactionInfo = yield sdk.transaction.submit({
|
98
|
+
blob,
|
99
|
+
signature: signature,
|
100
|
+
});
|
101
|
+
|
102
|
+
console.log(transactionInfo);
|
103
|
+
|
104
|
+
}).catch(err => {
|
105
|
+
console.log(err);
|
106
|
+
});
|
107
|
+
});
|
108
|
+
|
109
|
+
});
|