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,60 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const is = require('is-type-of');
|
4
|
+
const protobuf = require('protobufjs');
|
5
|
+
const long = require('long');
|
6
|
+
const ctp = require('../ctp');
|
7
|
+
|
8
|
+
/**
|
9
|
+
* ctp10TokenTransferFromOperation
|
10
|
+
* @param args
|
11
|
+
* @return {payload}
|
12
|
+
*/
|
13
|
+
module.exports = function (args) {
|
14
|
+
try {
|
15
|
+
const { contractAddress, fromAddress, destAddress, tokenAmount, sourceAddress, metadata } = args;
|
16
|
+
const root = protobuf.Root.fromJSON(require('../../crypto/protobuf/bundle.json'));
|
17
|
+
const payCoin = root.lookupType('protocol.OperationPayCoin');
|
18
|
+
const opt = {
|
19
|
+
destAddress: contractAddress,
|
20
|
+
// amount: 0,
|
21
|
+
};
|
22
|
+
|
23
|
+
let inputObj = {
|
24
|
+
method: 'transferFrom',
|
25
|
+
params: {
|
26
|
+
to: destAddress,
|
27
|
+
value: tokenAmount,
|
28
|
+
from: fromAddress,
|
29
|
+
},
|
30
|
+
};
|
31
|
+
|
32
|
+
opt.input = JSON.stringify(inputObj);
|
33
|
+
|
34
|
+
const payCoinMsg = payCoin.create(opt);
|
35
|
+
|
36
|
+
const operation = root.lookupType('protocol.Operation');
|
37
|
+
const payload = {
|
38
|
+
payCoin: payCoinMsg,
|
39
|
+
type: operation.Type.PAY_COIN,
|
40
|
+
};
|
41
|
+
|
42
|
+
if (sourceAddress) {
|
43
|
+
payload.sourceAddress = sourceAddress;
|
44
|
+
}
|
45
|
+
|
46
|
+
if (metadata) {
|
47
|
+
payload.metadata = metadata;
|
48
|
+
}
|
49
|
+
|
50
|
+
const err = operation.verify(payload);
|
51
|
+
|
52
|
+
if (err) {
|
53
|
+
throw Error(err);
|
54
|
+
}
|
55
|
+
|
56
|
+
return operation.create(payload);
|
57
|
+
} catch (err) {
|
58
|
+
throw err;
|
59
|
+
}
|
60
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const is = require('is-type-of');
|
4
|
+
const protobuf = require('protobufjs');
|
5
|
+
const long = require('long');
|
6
|
+
|
7
|
+
/**
|
8
|
+
* issueAsset operation
|
9
|
+
* @param {string} args
|
10
|
+
* @returns {string}
|
11
|
+
*/
|
12
|
+
module.exports = function (args) {
|
13
|
+
try {
|
14
|
+
const { sourceAddress, code, assetAmount, metadata } = args;
|
15
|
+
const root = protobuf.Root.fromJSON(require('../../crypto/protobuf/bundle.json'));
|
16
|
+
|
17
|
+
const issueAsset = root.lookupType('protocol.OperationIssueAsset');
|
18
|
+
const issueAssetMsg = issueAsset.create({
|
19
|
+
sourceAddress,
|
20
|
+
code: code,
|
21
|
+
amount: long.fromValue(assetAmount),
|
22
|
+
});
|
23
|
+
|
24
|
+
const operation = root.lookupType('protocol.Operation');
|
25
|
+
return operation.create({
|
26
|
+
issueAsset: issueAssetMsg,
|
27
|
+
type: operation.Type.ISSUE_ASSET,
|
28
|
+
});
|
29
|
+
|
30
|
+
// const buffer = operation.encode(operationMsg).finish();
|
31
|
+
// return buffer.toString('hex');
|
32
|
+
} catch (err) {
|
33
|
+
throw err;
|
34
|
+
}
|
35
|
+
};
|
@@ -0,0 +1,62 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const is = require('is-type-of');
|
4
|
+
const protobuf = require('protobufjs');
|
5
|
+
const long = require('long');
|
6
|
+
const tou8 = require('buffer-to-uint8array');
|
7
|
+
|
8
|
+
/**
|
9
|
+
* payAsset operation
|
10
|
+
* @param {object} args
|
11
|
+
* @returns {string}
|
12
|
+
*/
|
13
|
+
module.exports = function (args) {
|
14
|
+
try {
|
15
|
+
const { sourceAddress, destAddress, code, issuer, assetAmount, metadata } = args;
|
16
|
+
|
17
|
+
const root = protobuf.Root.fromJSON(require('../../crypto/protobuf/bundle.json'));
|
18
|
+
|
19
|
+
const assetKey = root.lookupType('protocol.AssetKey');
|
20
|
+
const assetKeyMsg = assetKey.create({
|
21
|
+
issuer,
|
22
|
+
code,
|
23
|
+
});
|
24
|
+
|
25
|
+
const asset = root.lookupType('protocol.Asset');
|
26
|
+
const assetMsg = asset.create({
|
27
|
+
key: assetKeyMsg,
|
28
|
+
amount: long.fromValue(assetAmount),
|
29
|
+
});
|
30
|
+
|
31
|
+
const operationPayAsset = root.lookupType('protocol.OperationPayAsset');
|
32
|
+
const operationPayAssetMsg = operationPayAsset.create({
|
33
|
+
destAddress,
|
34
|
+
asset: assetMsg,
|
35
|
+
});
|
36
|
+
|
37
|
+
const operation = root.lookupType('protocol.Operation');
|
38
|
+
|
39
|
+
const payload = {
|
40
|
+
payAsset: operationPayAssetMsg,
|
41
|
+
type: operation.Type.PAY_ASSET,
|
42
|
+
};
|
43
|
+
|
44
|
+
if (sourceAddress) {
|
45
|
+
payload.sourceAddress = sourceAddress;
|
46
|
+
}
|
47
|
+
|
48
|
+
if (metadata) {
|
49
|
+
payload.metadata = tou8(Buffer.from(metadata, 'utf8'));
|
50
|
+
}
|
51
|
+
|
52
|
+
const err = operation.verify(payload);
|
53
|
+
|
54
|
+
if (err) {
|
55
|
+
throw Error(err);
|
56
|
+
}
|
57
|
+
|
58
|
+
return operation.create(payload);
|
59
|
+
} catch (err) {
|
60
|
+
throw err;
|
61
|
+
}
|
62
|
+
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const is = require('is-type-of');
|
4
|
+
const protobuf = require('protobufjs');
|
5
|
+
const long = require('long');
|
6
|
+
const tou8 = require('buffer-to-uint8array');
|
7
|
+
|
8
|
+
/**
|
9
|
+
* payCoin operation
|
10
|
+
* @param {string} args
|
11
|
+
* @returns {string}
|
12
|
+
*/
|
13
|
+
module.exports = function (args) {
|
14
|
+
try {
|
15
|
+
const { sourceAddress, destAddress, buAmount, metadata } = args;
|
16
|
+
const root = protobuf.Root.fromJSON(require('../../crypto/protobuf/bundle.json'));
|
17
|
+
const payCoin = root.lookupType('protocol.OperationPayCoin');
|
18
|
+
const payCoinMsg = payCoin.create({
|
19
|
+
destAddress,
|
20
|
+
amount: long.fromValue(buAmount),
|
21
|
+
});
|
22
|
+
|
23
|
+
const operation = root.lookupType('protocol.Operation');
|
24
|
+
const payload = {
|
25
|
+
payCoin: payCoinMsg,
|
26
|
+
type: operation.Type.PAY_COIN,
|
27
|
+
sourceAddress,
|
28
|
+
};
|
29
|
+
|
30
|
+
if (metadata) {
|
31
|
+
payload.metadata = tou8(Buffer.from(metadata, 'utf8'));
|
32
|
+
}
|
33
|
+
|
34
|
+
const err = operation.verify(payload);
|
35
|
+
|
36
|
+
if (err) {
|
37
|
+
throw Error(err);
|
38
|
+
}
|
39
|
+
|
40
|
+
return operation.create(payload);
|
41
|
+
} catch (err) {
|
42
|
+
throw err;
|
43
|
+
}
|
44
|
+
};
|