@caict/bop-typescript-sdk 1.0.0
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/CHANGELOG.md +34 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +112 -0
- package/package.json +90 -0
- package/src/bop/bop-base/README.md +5 -0
- package/src/bop/bop-base/base.ts +366 -0
- package/src/bop/bop-base/index.ts +83 -0
- package/src/bop/bop-base/permit.ts +116 -0
- package/src/bop/bop-base/test/base.test.ts +867 -0
- package/src/bop/bop-base/test/index.test.ts +69 -0
- package/src/bop/bop-base/test/permit.test.ts +125 -0
- package/src/bop/bop-base/tsconfig.json +8 -0
- package/src/bop/bop-proto/README.md +2 -0
- package/src/bop/bop-proto/bop-ws.proto +266 -0
- package/src/bop/bop-proto/bop-ws.ts +4447 -0
- package/src/bop/bop-proto/bop.proto +898 -0
- package/src/bop/bop-proto/bop.ts +12890 -0
- package/src/bop/bop-proto/tsconfig.json +8 -0
- package/src/bop/bop-ws/index.ts +315 -0
- package/src/bop/bop-ws/sample/sample.ts +107 -0
- package/src/bop/bop-ws/tsconfig.json +8 -0
- package/src/bop/index.ts +14 -0
- package/src/bop-sdk/index.ts +22 -0
- package/src/bop-sdk/interface/abstract-service/abstract-account.ts +23 -0
- package/src/bop-sdk/interface/abstract-service/abstract-chain.ts +9 -0
- package/src/bop-sdk/interface/abstract-service/abstract-contract.ts +16 -0
- package/src/bop-sdk/interface/abstract-service/abstract-ledger.ts +15 -0
- package/src/bop-sdk/interface/abstract-service/abstract-provider.ts +13 -0
- package/src/bop-sdk/interface/abstract-service/abstract-signer.ts +133 -0
- package/src/bop-sdk/interface/abstract-service/abstract-transaction.ts +86 -0
- package/src/bop-sdk/interface/provider-ws.ts +10 -0
- package/src/bop-sdk/interface/provider.ts +22 -0
- package/src/bop-sdk/interface/service/3rd.ts +54 -0
- package/src/bop-sdk/interface/service/account.ts +86 -0
- package/src/bop-sdk/interface/service/chain.ts +27 -0
- package/src/bop-sdk/interface/service/contract.ts +51 -0
- package/src/bop-sdk/interface/service/helper.ts +426 -0
- package/src/bop-sdk/interface/service/ledger.ts +75 -0
- package/src/bop-sdk/interface/service/offline/check/index.js +138 -0
- package/src/bop-sdk/interface/service/offline/common/constant.js +6 -0
- package/src/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
- package/src/bop-sdk/interface/service/offline/common/util.js +511 -0
- package/src/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
- package/src/bop-sdk/interface/service/offline/exception/errors.js +90 -0
- package/src/bop-sdk/interface/service/offline/exception/index.js +5 -0
- package/src/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
- package/src/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
- package/src/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
- package/src/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
- package/src/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
- package/src/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
- package/src/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
- package/src/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
- package/src/bop-sdk/interface/service/offline/operation/index.js +20 -0
- package/src/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
- package/src/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
- package/src/bop-sdk/interface/service/offline/transaction/index.js +988 -0
- package/src/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
- package/src/bop-sdk/interface/service/offline/validate/account.js +152 -0
- package/src/bop-sdk/interface/service/offline/validate/contract.js +101 -0
- package/src/bop-sdk/interface/service/offline/validate/index.js +10 -0
- package/src/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
- package/src/bop-sdk/interface/service/transaction.ts +731 -0
- package/src/bop-sdk/interface/signer.ts +46 -0
- package/src/bop-sdk/interface/test/3rd.test.ts +1571 -0
- package/src/bop-sdk/interface/test/account.test.ts +284 -0
- package/src/bop-sdk/interface/test/chain.test.ts +45 -0
- package/src/bop-sdk/interface/test/contract.test.ts +283 -0
- package/src/bop-sdk/interface/test/ledger.test.ts +166 -0
- package/src/bop-sdk/interface/test/provider.test.ts +407 -0
- package/src/bop-sdk/interface/test/signer.test.ts +105 -0
- package/src/bop-sdk/interface/test/transaction.test.ts +713 -0
- package/src/bop-sdk/proto/bop-sdk-common.proto +159 -0
- package/src/bop-sdk/proto/bop-sdk-common.ts +829 -0
- package/src/bop-sdk/proto/bop-sdk-interface.proto +581 -0
- package/src/bop-sdk/proto/bop-sdk-interface.ts +10839 -0
- package/src/bop-sdk/proto/bop-sdk-utils.proto +86 -0
- package/src/bop-sdk/proto/bop-sdk-utils.ts +1495 -0
- package/src/bop-sdk/utils/abi/abi-coder.ts +147 -0
- package/src/bop-sdk/utils/abi/address.ts +109 -0
- package/src/bop-sdk/utils/abi/bignumber.ts +403 -0
- package/src/bop-sdk/utils/abi/bytes.ts +565 -0
- package/src/bop-sdk/utils/abi/coders/abstract-coder.ts +239 -0
- package/src/bop-sdk/utils/abi/coders/address.ts +58 -0
- package/src/bop-sdk/utils/abi/coders/anonymous.ts +25 -0
- package/src/bop-sdk/utils/abi/coders/array.ts +275 -0
- package/src/bop-sdk/utils/abi/coders/boolean.ts +21 -0
- package/src/bop-sdk/utils/abi/coders/bytes.ts +36 -0
- package/src/bop-sdk/utils/abi/coders/fixed-bytes.ts +35 -0
- package/src/bop-sdk/utils/abi/coders/null.ts +25 -0
- package/src/bop-sdk/utils/abi/coders/number.ts +56 -0
- package/src/bop-sdk/utils/abi/coders/string.ts +24 -0
- package/src/bop-sdk/utils/abi/coders/tuple.ts +73 -0
- package/src/bop-sdk/utils/abi/constants/addresses.ts +1 -0
- package/src/bop-sdk/utils/abi/constants/bignumbers.ts +30 -0
- package/src/bop-sdk/utils/abi/constants/hashes.ts +2 -0
- package/src/bop-sdk/utils/abi/constants/index.ts +15 -0
- package/src/bop-sdk/utils/abi/constants/strings.ts +2 -0
- package/src/bop-sdk/utils/abi/fragments.ts +1243 -0
- package/src/bop-sdk/utils/abi/id.ts +6 -0
- package/src/bop-sdk/utils/abi/index.ts +46 -0
- package/src/bop-sdk/utils/abi/interface.ts +921 -0
- package/src/bop-sdk/utils/abi/keccak256.ts +9 -0
- package/src/bop-sdk/utils/abi/properties.ts +172 -0
- package/src/bop-sdk/utils/abi/strings/bytes32.ts +40 -0
- package/src/bop-sdk/utils/abi/strings/idna.ts +258 -0
- package/src/bop-sdk/utils/abi/strings/index.ts +28 -0
- package/src/bop-sdk/utils/abi/strings/utf8.ts +373 -0
- package/src/bop-sdk/utils/encryption-address.ts +501 -0
- package/src/bop-sdk/utils/encryption-crypto.ts +427 -0
- package/src/bop-sdk/utils/encryption-mnemonics.ts +120 -0
- package/src/bop-sdk/utils/index.ts +27 -0
- package/src/bop-sdk/utils/logger.ts +480 -0
- package/src/index.ts +35 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const long = require("long");
|
|
2
|
+
const chain_pb = require("../proto/chain_pb");
|
|
3
|
+
const is = require("is-type-of");
|
|
4
|
+
const keypair = require("@caict/bif-encryption");
|
|
5
|
+
const errors = require("../exception");
|
|
6
|
+
|
|
7
|
+
function payCoin(args = {}) {
|
|
8
|
+
const { from, to, amount, input, metadata } = args;
|
|
9
|
+
|
|
10
|
+
const payCoin = new chain_pb.OperationPayCoin();
|
|
11
|
+
payCoin.setDestAddress(to);
|
|
12
|
+
if (amount !== 0 && amount !== "0") {
|
|
13
|
+
payCoin.setAmount(long.fromValue(amount));
|
|
14
|
+
}
|
|
15
|
+
if (input) {
|
|
16
|
+
payCoin.setInput(input);
|
|
17
|
+
}
|
|
18
|
+
let operation = new chain_pb.Operation();
|
|
19
|
+
operation.setType(chain_pb.Operation.Type.PAY_COIN);
|
|
20
|
+
operation.setPayCoin(payCoin);
|
|
21
|
+
if (metadata) {
|
|
22
|
+
operation.setMetadata(Uint8Array.from(Buffer.from(metadata, "utf8")));
|
|
23
|
+
}
|
|
24
|
+
if (from) {
|
|
25
|
+
operation.setSourceAddress(from);
|
|
26
|
+
}
|
|
27
|
+
return operation;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function activateAccount(args = {}) {
|
|
31
|
+
const { to, initBalance } = args;
|
|
32
|
+
|
|
33
|
+
const defaultTxThreshold = 1;
|
|
34
|
+
const defaultMasterWeight = 1;
|
|
35
|
+
|
|
36
|
+
let threshold = new chain_pb.AccountThreshold();
|
|
37
|
+
threshold.setTxThreshold(defaultTxThreshold);
|
|
38
|
+
|
|
39
|
+
let privilege = new chain_pb.AccountPrivilege();
|
|
40
|
+
privilege.setThresholds(threshold);
|
|
41
|
+
privilege.setMasterWeight(defaultMasterWeight);
|
|
42
|
+
|
|
43
|
+
let createAccount = new chain_pb.OperationCreateAccount();
|
|
44
|
+
createAccount.setDestAddress(to);
|
|
45
|
+
if (initBalance !== 0 && initBalance !== "0") {
|
|
46
|
+
createAccount.setInitBalance(long.fromValue(initBalance));
|
|
47
|
+
}
|
|
48
|
+
createAccount.setPriv(privilege);
|
|
49
|
+
|
|
50
|
+
let operation = new chain_pb.Operation();
|
|
51
|
+
operation.setType(chain_pb.Operation.Type.CREATE_ACCOUNT);
|
|
52
|
+
operation.setCreateAccount(createAccount);
|
|
53
|
+
return operation;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function setMetadata(args = {}) {
|
|
57
|
+
const { key, value, version, deleteFlag } = args;
|
|
58
|
+
|
|
59
|
+
const setMetadata = new chain_pb.OperationSetMetadata();
|
|
60
|
+
setMetadata.setKey(key);
|
|
61
|
+
setMetadata.setValue(value);
|
|
62
|
+
setMetadata.setVersion(version);
|
|
63
|
+
setMetadata.setDeleteFlag(deleteFlag);
|
|
64
|
+
let operation = new chain_pb.Operation();
|
|
65
|
+
operation.setType(chain_pb.Operation.Type.SET_METADATA);
|
|
66
|
+
operation.setSetMetadata(setMetadata);
|
|
67
|
+
return operation;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function createContract(args = {}) {
|
|
71
|
+
const { initBalance, payload, sourceAddress, initInput, type } = args;
|
|
72
|
+
|
|
73
|
+
const defaultTxThreshold = 1;
|
|
74
|
+
const defaultMasterWeight = 0;
|
|
75
|
+
|
|
76
|
+
const threshold = new chain_pb.AccountThreshold();
|
|
77
|
+
threshold.setTxThreshold(defaultTxThreshold);
|
|
78
|
+
|
|
79
|
+
const privilege = new chain_pb.AccountPrivilege();
|
|
80
|
+
privilege.setThresholds(threshold);
|
|
81
|
+
if (defaultMasterWeight !== 0 && defaultMasterWeight !== "0") {
|
|
82
|
+
privilege.setMasterWeight(defaultMasterWeight);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const contractMsg = new chain_pb.Contract();
|
|
86
|
+
contractMsg.setPayload(payload);
|
|
87
|
+
contractMsg.setType(type);
|
|
88
|
+
const createAccount = new chain_pb.OperationCreateAccount();
|
|
89
|
+
if (initBalance !== 0 && initBalance !== "0") {
|
|
90
|
+
createAccount.setInitBalance(long.fromValue(initBalance));
|
|
91
|
+
}
|
|
92
|
+
createAccount.setPriv(privilege);
|
|
93
|
+
createAccount.setContract(contractMsg);
|
|
94
|
+
if (initInput) {
|
|
95
|
+
createAccount.setInitInput(initInput);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const operation = new chain_pb.Operation();
|
|
99
|
+
operation.setType(chain_pb.Operation.Type.CREATE_ACCOUNT);
|
|
100
|
+
operation.setCreateAccount(createAccount);
|
|
101
|
+
if (sourceAddress) {
|
|
102
|
+
operation.setSourceAddress(sourceAddress);
|
|
103
|
+
}
|
|
104
|
+
return operation;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isAvailableValue(str, from = -1, to = long.MAX_VALUE) {
|
|
108
|
+
const reg = /^(0|([1-9]\d*))$/;
|
|
109
|
+
return (
|
|
110
|
+
is.string(str) &&
|
|
111
|
+
reg.test(str) &&
|
|
112
|
+
long.fromValue(str).greaterThan(from) &&
|
|
113
|
+
long.fromValue(str).lessThanOrEqual(to)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function accountSetPrivilegeOperation(args = {}) {
|
|
118
|
+
const { signers } = args;
|
|
119
|
+
const { typeThresholds } = args;
|
|
120
|
+
const signerList = [];
|
|
121
|
+
const typeThresholdsList = [];
|
|
122
|
+
const signer = new chain_pb.Signer();
|
|
123
|
+
if (is.array(signers) && signers.length > 0) {
|
|
124
|
+
let msg = "";
|
|
125
|
+
signers.some((item) => {
|
|
126
|
+
if (!keypair.isAddress(item.address)) {
|
|
127
|
+
msg = "INVALID_SIGNER_ADDRESS_ERROR";
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
let maxInt32 = Math.pow(2, 32) - 1;
|
|
131
|
+
if (!isAvailableValue(item.weight, -1, maxInt32)) {
|
|
132
|
+
msg = "INVALID_SIGNER_WEIGHT_ERROR";
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
signer.setAddress(item.address);
|
|
136
|
+
signer.setWeight(item.weight);
|
|
137
|
+
signerList.push(signer);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (msg !== "") {
|
|
141
|
+
return this._responseError(errors[msg]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const typeThreshold = new chain_pb.OperationTypeThreshold();
|
|
145
|
+
if (is.array(typeThresholds) && typeThresholds.length > 0) {
|
|
146
|
+
let msg = "";
|
|
147
|
+
typeThresholds.some((item) => {
|
|
148
|
+
if (!isAvailableValue(item.type, -1, 100)) {
|
|
149
|
+
msg = "INVALID_OPERATION_TYPE_ERROR";
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!isAvailableValue(item.threshold)) {
|
|
154
|
+
msg = "INVALID_TYPE_THRESHOLD_ERROR";
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
typeThreshold.setType(item.type);
|
|
158
|
+
typeThreshold.setThreshold(item.threshold);
|
|
159
|
+
typeThresholdsList.push(typeThreshold);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (msg !== "") {
|
|
163
|
+
return this._responseError(errors[msg]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const setPrivilege = new chain_pb.OperationSetPrivilege();
|
|
168
|
+
setPrivilege.setSignersList(signerList);
|
|
169
|
+
setPrivilege.setTxThreshold(args.txThreshold);
|
|
170
|
+
setPrivilege.setTypeThresholdsList(typeThresholdsList);
|
|
171
|
+
let maxInt32 = Math.pow(2, 32) - 1;
|
|
172
|
+
if (isAvailableValue(args.masterWeight, 1, maxInt32)) {
|
|
173
|
+
setPrivilege.setMasterWeight(args.masterWeight);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let operation = new chain_pb.Operation();
|
|
177
|
+
operation.setType(chain_pb.Operation.Type.SET_PRIVILEGE);
|
|
178
|
+
operation.setSetPrivilege(setPrivilege);
|
|
179
|
+
return operation;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = {
|
|
183
|
+
payCoin,
|
|
184
|
+
accountSetPrivilegeOperation,
|
|
185
|
+
activateAccount,
|
|
186
|
+
setMetadata,
|
|
187
|
+
createContract,
|
|
188
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const is = require("is-type-of");
|
|
2
|
+
const keypair = require("@caict/bif-encryption");
|
|
3
|
+
const errors = require("../exception");
|
|
4
|
+
const proto = exports;
|
|
5
|
+
|
|
6
|
+
proto.accountActivateOperation = function (args) {
|
|
7
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
8
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const schema = {
|
|
12
|
+
sourceAddress: {
|
|
13
|
+
required: true,
|
|
14
|
+
address: true,
|
|
15
|
+
},
|
|
16
|
+
destAddress: {
|
|
17
|
+
required: true,
|
|
18
|
+
address: true,
|
|
19
|
+
},
|
|
20
|
+
initBalance: {
|
|
21
|
+
required: true,
|
|
22
|
+
numeric: true,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (!this._validate(args, schema).tag) {
|
|
27
|
+
const { msg } = this._validate(args, schema);
|
|
28
|
+
return this._responseError(errors[msg]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this._responseData(true);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
proto.accountSetMetadataOperation = function (args) {
|
|
35
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
36
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const schema = {
|
|
40
|
+
key: {
|
|
41
|
+
required: true,
|
|
42
|
+
string: true,
|
|
43
|
+
},
|
|
44
|
+
value: {
|
|
45
|
+
required: true,
|
|
46
|
+
string: true,
|
|
47
|
+
},
|
|
48
|
+
sourceAddress: {
|
|
49
|
+
required: true,
|
|
50
|
+
address: true,
|
|
51
|
+
},
|
|
52
|
+
deleteFlag: {
|
|
53
|
+
required: false,
|
|
54
|
+
boolean: true,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (!this._validate(args, schema).tag) {
|
|
59
|
+
const { msg } = this._validate(args, schema);
|
|
60
|
+
return this._responseError(errors[msg]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let { value } = args;
|
|
64
|
+
|
|
65
|
+
if (!is.string(value) || value.trim().length === 0 || value.length > 256000) {
|
|
66
|
+
return this._responseError(errors.INVALID_DATAVALUE_ERROR);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (args.version && !this._isAvailableVersion(args.version)) {
|
|
70
|
+
return this._responseError(errors.INVALID_DATAVERSION_ERROR);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return this._responseData(true);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
proto.accountSetPrivilegeOperation = function (args = {}) {
|
|
77
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
78
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const schema = {
|
|
82
|
+
sourceAddress: {
|
|
83
|
+
required: false,
|
|
84
|
+
address: true,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if (!this._validate(args, schema).tag) {
|
|
89
|
+
const { msg } = this._validate(args, schema);
|
|
90
|
+
return this._responseError(errors[msg]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let maxInt32 = Math.pow(2, 32) - 1;
|
|
94
|
+
|
|
95
|
+
if (
|
|
96
|
+
!is.undefined(args.masterWeight) &&
|
|
97
|
+
!this._isAvailableValue(args.masterWeight, -1, maxInt32)
|
|
98
|
+
) {
|
|
99
|
+
return this._responseError(errors.INVALID_MASTERWEIGHT_ERROR);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log(args.txThreshold);
|
|
103
|
+
if (
|
|
104
|
+
!is.undefined(args.txThreshold) &&
|
|
105
|
+
!this._isAvailableValue(args.txThreshold, -1, maxInt32)
|
|
106
|
+
) {
|
|
107
|
+
return this._responseError(errors.INVALID_TX_THRESHOLD_ERROR);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { signers } = args;
|
|
111
|
+
const { typeThresholds } = args;
|
|
112
|
+
|
|
113
|
+
if (is.array(signers) && signers.length > 0) {
|
|
114
|
+
let msg = "";
|
|
115
|
+
signers.some((item) => {
|
|
116
|
+
if (!keypair.isAddress(item.address)) {
|
|
117
|
+
msg = "INVALID_SIGNER_ADDRESS_ERROR";
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!this._isAvailableValue(item.weight, -1, maxInt32)) {
|
|
122
|
+
msg = "INVALID_SIGNER_WEIGHT_ERROR";
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (msg !== "") {
|
|
128
|
+
return this._responseError(errors[msg]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (is.array(typeThresholds) && typeThresholds.length > 0) {
|
|
133
|
+
let msg = "";
|
|
134
|
+
typeThresholds.some((item) => {
|
|
135
|
+
if (!this._isAvailableValue(item.type, -1, 100)) {
|
|
136
|
+
msg = "INVALID_OPERATION_TYPE_ERROR";
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!this._isAvailableValue(item.threshold)) {
|
|
141
|
+
msg = "INVALID_TYPE_THRESHOLD_ERROR";
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (msg !== "") {
|
|
147
|
+
return this._responseError(errors[msg]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return this._responseData(true);
|
|
152
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const is = require("is-type-of");
|
|
2
|
+
const errors = require("../exception");
|
|
3
|
+
const proto = exports;
|
|
4
|
+
const chain_pb = require("../proto/chain_pb");
|
|
5
|
+
|
|
6
|
+
proto.contractCreateOperation = function (args) {
|
|
7
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
8
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const schema = {
|
|
12
|
+
sourceAddress: {
|
|
13
|
+
required: true,
|
|
14
|
+
string: true,
|
|
15
|
+
address: true,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (!this._validate(args, schema).tag) {
|
|
20
|
+
const { msg } = this._validate(args, schema);
|
|
21
|
+
return this._responseError(errors[msg]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const evm = chain_pb.Contract.ContractType.EVM;
|
|
25
|
+
const javascript = chain_pb.Contract.ContractType.JAVASCRIPT;
|
|
26
|
+
const system = chain_pb.Contract.ContractType.SYSTEM;
|
|
27
|
+
if (
|
|
28
|
+
args.type != evm &&
|
|
29
|
+
args.type != javascript &&
|
|
30
|
+
args.type != system &&
|
|
31
|
+
args.type != null &&
|
|
32
|
+
args.type != ""
|
|
33
|
+
) {
|
|
34
|
+
return this._responseError(errors.INVALID_CONTRACT_TYPE_ERROR);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!is.string(args.payload) || args.payload.trim().length === 0) {
|
|
38
|
+
return this._responseError(errors.PAYLOAD_EMPTY_ERROR);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return this._responseData(true);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
proto.contractInvokeOperation = function (args) {
|
|
45
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
46
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const schema = {
|
|
50
|
+
contractAddress: {
|
|
51
|
+
required: true,
|
|
52
|
+
address: true,
|
|
53
|
+
},
|
|
54
|
+
sourceAddress: {
|
|
55
|
+
required: false,
|
|
56
|
+
address: true,
|
|
57
|
+
},
|
|
58
|
+
amount: {
|
|
59
|
+
required: true,
|
|
60
|
+
numeric: true,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (!this._validate(args, schema).tag) {
|
|
65
|
+
const { msg } = this._validate(args, schema);
|
|
66
|
+
return this._responseError(errors[msg]);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!is.undefined(args.amount)) {
|
|
70
|
+
if (!this._isAvailableValue(args.amount)) {
|
|
71
|
+
return this._responseError(errors.INVALID_AMOUNT_ERROR);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return this._responseData(true);
|
|
76
|
+
};
|
|
77
|
+
proto.contractInvokeRequestOperation = function (args) {
|
|
78
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
79
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const schema = {
|
|
83
|
+
senderAddress: {
|
|
84
|
+
required: true,
|
|
85
|
+
address: true,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (!this._validate(args, schema).tag) {
|
|
90
|
+
const { msg } = this._validate(args, schema);
|
|
91
|
+
return this._responseError(errors[msg]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!is.undefined(args.amount)) {
|
|
95
|
+
if (!this._isAvailableValue(args.amount)) {
|
|
96
|
+
return this._responseError(errors.INVALID_AMOUNT_ERROR);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return this._responseData(true);
|
|
101
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const wrap = require("co-wrap-all");
|
|
2
|
+
const merge = require("merge-descriptors");
|
|
3
|
+
module.exports = Operation;
|
|
4
|
+
function Operation() {}
|
|
5
|
+
const proto = Operation.prototype;
|
|
6
|
+
merge(proto, require("../common/util"));
|
|
7
|
+
merge(proto, require("./transaction"));
|
|
8
|
+
merge(proto, require("./account"));
|
|
9
|
+
merge(proto, require("./contract"));
|
|
10
|
+
wrap(proto);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const is = require("is-type-of");
|
|
2
|
+
const errors = require("../exception");
|
|
3
|
+
const proto = exports;
|
|
4
|
+
|
|
5
|
+
proto.SendOperation = function (args) {
|
|
6
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
7
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const schema = {
|
|
11
|
+
sourceAddress: {
|
|
12
|
+
required: true,
|
|
13
|
+
address: true,
|
|
14
|
+
},
|
|
15
|
+
destAddress: {
|
|
16
|
+
required: true,
|
|
17
|
+
address: true,
|
|
18
|
+
},
|
|
19
|
+
amount: {
|
|
20
|
+
required: true,
|
|
21
|
+
numeric: true,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (!this._validate(args, schema).tag) {
|
|
26
|
+
const { msg } = this._validate(args, schema);
|
|
27
|
+
return this._responseError(errors[msg]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return this._responseData(true);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
proto.GasSendRequestOperation = function (args) {
|
|
34
|
+
if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
|
|
35
|
+
return this._responseError(errors.REQUEST_NULL_ERROR);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const schema = {
|
|
39
|
+
senderAddress: {
|
|
40
|
+
required: true,
|
|
41
|
+
address: true,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (!this._validate(args, schema).tag) {
|
|
46
|
+
const { msg } = this._validate(args, schema);
|
|
47
|
+
return this._responseError(errors[msg]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return this._responseData(true);
|
|
51
|
+
};
|