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.
Files changed (76) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +66 -0
  3. package/_config.yml +1 -0
  4. package/doc/SDK_CN.md +2003 -0
  5. package/example/atp10TokenDemo.js +319 -0
  6. package/example/exchange.js +184 -0
  7. package/example/offlineSignatureDemo.js +83 -0
  8. package/example/submitTransactionDemo.js +92 -0
  9. package/index.d.ts +186 -0
  10. package/index.js +9 -0
  11. package/lib/account/index.js +234 -0
  12. package/lib/blockchain/block.js +380 -0
  13. package/lib/blockchain/transaction.js +264 -0
  14. package/lib/common/ctp.js +5 -0
  15. package/lib/common/operation/accountSetMetadata.js +55 -0
  16. package/lib/common/operation/accountSetPrivilege.js +90 -0
  17. package/lib/common/operation/activateAccount.js +58 -0
  18. package/lib/common/operation/contractCreate.js +72 -0
  19. package/lib/common/operation/contractInvokeByAsset.js +75 -0
  20. package/lib/common/operation/contractInvokeByBU.js +53 -0
  21. package/lib/common/operation/createLog.js +44 -0
  22. package/lib/common/operation/ctp10TokenApprove.js +59 -0
  23. package/lib/common/operation/ctp10TokenAssign.js +59 -0
  24. package/lib/common/operation/ctp10TokenChangeOwner.js +58 -0
  25. package/lib/common/operation/ctp10TokenIssue.js +78 -0
  26. package/lib/common/operation/ctp10TokenTransfer.js +59 -0
  27. package/lib/common/operation/ctp10TokenTransferFrom.js +60 -0
  28. package/lib/common/operation/issueAsset.js +35 -0
  29. package/lib/common/operation/payAsset.js +62 -0
  30. package/lib/common/operation/payCoin.js +44 -0
  31. package/lib/common/util.js +880 -0
  32. package/lib/contract/index.js +212 -0
  33. package/lib/crypto/protobuf/bundle.json +1643 -0
  34. package/lib/exception/customErrors.js +56 -0
  35. package/lib/exception/errors.js +240 -0
  36. package/lib/exception/index.js +8 -0
  37. package/lib/operation/account.js +193 -0
  38. package/lib/operation/asset.js +106 -0
  39. package/lib/operation/bu.js +52 -0
  40. package/lib/operation/contract.js +184 -0
  41. package/lib/operation/ctp10Token.js +394 -0
  42. package/lib/operation/index.js +30 -0
  43. package/lib/operation/log.js +47 -0
  44. package/lib/sdk.js +70 -0
  45. package/lib/token/asset.js +79 -0
  46. package/lib/token/ctp10Token.js +301 -0
  47. package/lib/token/index.js +17 -0
  48. package/lib/util/index.js +86 -0
  49. package/openchain-sdk-nodejs.iml +9 -0
  50. package/package.json +39 -0
  51. package/test/Ctp10Token.test.js +96 -0
  52. package/test/account.test.js +132 -0
  53. package/test/accountActivateOperation.test.js +99 -0
  54. package/test/accountSetMetadata.test.js +102 -0
  55. package/test/accountSetPrivilege.test.js +66 -0
  56. package/test/asset.test.js +63 -0
  57. package/test/assetIssueOperation.test.js +77 -0
  58. package/test/assetSendOperation.test.js +103 -0
  59. package/test/blob.test.js +128 -0
  60. package/test/block.test.js +165 -0
  61. package/test/buSendOperation.test.js +64 -0
  62. package/test/contract.test.js +64 -0
  63. package/test/contractCreateOperation.test.js +41 -0
  64. package/test/contractCreateTransaction.test.js +116 -0
  65. package/test/contractInvokeByAssetOperation.test.js +109 -0
  66. package/test/contractInvokeByBUOperation.test.js +107 -0
  67. package/test/ctp10TokenApproveOperation.test.js +98 -0
  68. package/test/ctp10TokenAssignOperation.test.js +99 -0
  69. package/test/ctp10TokenChangeOwnerOperation.test.js +98 -0
  70. package/test/ctp10TokenIssueOperation.test.js +40 -0
  71. package/test/ctp10TokenIssueOperationTransaction.test.js +106 -0
  72. package/test/ctp10TokenTransferFromOperation.test.js +101 -0
  73. package/test/ctp10TokenTransferOperation.test.js +98 -0
  74. package/test/log.transaction.test.js +103 -0
  75. package/test/transaction.test.js +166 -0
  76. 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
+ };