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,56 @@
1
+ 'use strict';
2
+ // custom error code: from 15001 to 17000
3
+ module.exports = {
4
+ ACCOUNT_NOT_EXIST: {
5
+ CODE: 15001,
6
+ MSG: 'Account not exist',
7
+ },
8
+ INVALID_NUMBER_OF_ARG: {
9
+ CODE: 15006,
10
+ MSG: 'Invalid number of arguments to the function',
11
+ },
12
+ QUERY_RESULT_NOT_EXIST: {
13
+ CODE: 15014,
14
+ MSG: 'Query result not exist',
15
+ },
16
+ INVALID_ARGUMENTS: {
17
+ CODE: 15016,
18
+ MSG: 'Invalid arguments to the function',
19
+ },
20
+ FAIL: {
21
+ CODE: 15017,
22
+ MSG: 'Fail',
23
+ },
24
+ INVALID_FORMAT_OF_ARG: {
25
+ CODE: 15019,
26
+ MSG: 'Invalid format of argument to the function',
27
+ },
28
+ INVALID_OPERATIONS: {
29
+ CODE: 15022,
30
+ MSG: 'Invalid operation',
31
+ },
32
+ INVALID_SIGNATURE_ERROR: {
33
+ CODE: 15027,
34
+ MSG: 'Invalid signature',
35
+ },
36
+ INVALID_METADATA_ERROR: {
37
+ CODE: 15028,
38
+ MSG: 'Invalid metadata',
39
+ },
40
+ INVALID_INPUT_ERROR: {
41
+ CODE: 15028,
42
+ MSG: 'Invalid input',
43
+ },
44
+ INVALID_DELETEFLAG_ERROR: {
45
+ CODE: 15029,
46
+ MSG: 'DeleteFlag must be a boolean',
47
+ },
48
+ INVALID_CONTRACT_BU_AMOUNT_ERROR: {
49
+ CODE: 15030,
50
+ MSG: 'BuAmount must between 0 and max(int64)',
51
+ },
52
+ INVALID_CONTRACT_ASSET_AMOUNT_ERROR: {
53
+ CODE: 15031,
54
+ MSG: 'AssetAmount must between 0 and max(int64)',
55
+ },
56
+ };
@@ -0,0 +1,240 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ ACCOUNT_CREATE_ERROR: {
5
+ CODE: 11001,
6
+ MSG: 'Create account failed',
7
+ },
8
+ INVALID_SOURCEADDRESS_ERROR: {
9
+ CODE: 11002,
10
+ MSG: 'Invalid sourceAddress',
11
+ },
12
+ INVALID_DESTADDRESS_ERROR: {
13
+ CODE: 11003,
14
+ MSG: 'Invalid destAddress',
15
+ },
16
+ INVALID_INITBALANCE_ERROR: {
17
+ CODE: 11004,
18
+ MSG: 'InitBalance must between 1 and max(int64)',
19
+ },
20
+ SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR: {
21
+ CODE: 11005,
22
+ MSG: 'SourceAddress cannot be equal to destAddress',
23
+ },
24
+ INVALID_ADDRESS_ERROR: {
25
+ CODE: 11006,
26
+ MSG: 'Invalid address',
27
+ },
28
+ CONNECTNETWORK_ERROR: {
29
+ CODE: 11007,
30
+ MSG: 'Connect network failed',
31
+ },
32
+ INVALID_ISSUE_AMMOUNT_ERROR: {
33
+ CODE: 11008,
34
+ MSG: 'AssetAmount this will be issued mustbetween 1 and max(int64)',
35
+ },
36
+ NO_METADATA_ERROR: {
37
+ CODE: 11010,
38
+ MSG: 'This account does not have this metadata',
39
+ },
40
+ INVALID_DATAKEY_ERROR: {
41
+ CODE: 11011,
42
+ MSG: 'The length of key must between 1 and 1024',
43
+ },
44
+ INVALID_DATAVALUE_ERROR: {
45
+ CODE: 11012,
46
+ MSG: 'The length of value must between 0 and 256000',
47
+ },
48
+ INVALID_DATAVERSION_ERROR: {
49
+ CODE: 11013,
50
+ MSG: 'The version must be equal or bigger than 0',
51
+ },
52
+ INVALID_MASTERWEIGHT_ERROR: {
53
+ CODE: 11015,
54
+ MSG: 'MasterWeight must between 0 and max(uint32)',
55
+ },
56
+ INVALID_SIGNER_ADDRESS_ERROR: {
57
+ CODE: 11016,
58
+ MSG: 'Invalid signer address',
59
+ },
60
+ INVALID_SIGNER_WEIGHT_ERROR: {
61
+ CODE: 11017,
62
+ MSG: 'Signer weight must between 0 and max(uint32)',
63
+ },
64
+ INVALID_TX_THRESHOLD_ERROR: {
65
+ CODE: 11018,
66
+ MSG: 'TxThreshold must between 0 and max(int64)',
67
+ },
68
+ INVALID_OPERATION_TYPE_ERROR: {
69
+ CODE: 11019,
70
+ MSG: 'Type of typeThreshold is invalid',
71
+ },
72
+ INVALID_TYPE_THRESHOLD_ERROR: {
73
+ CODE: 11020,
74
+ MSG: 'TypeThreshold must between 0 and max(int64)',
75
+ },
76
+ INVALID_ASSET_CODE_ERROR: {
77
+ CODE: 11023,
78
+ MSG: 'Invalid code',
79
+ },
80
+ INVALID_ASSET_AMOUNT_ERROR: {
81
+ CODE: 11024,
82
+ MSG: 'AssetAmount must between 1 and max(int64)',
83
+ },
84
+ INVALID_CONTRACT_HASH_ERROR: {
85
+ CODE: 11025,
86
+ MSG: 'Invalid transaction hash to create contract'
87
+ },
88
+ INVALID_BU_AMOUNT_ERROR: {
89
+ CODE: 11026,
90
+ MSG: 'BuAmount must between 1 and max(int64)',
91
+ },
92
+ INVALID_ISSUER_ADDRESS_ERROR: {
93
+ CODE: 11027,
94
+ MSG: 'Invalid issuer address',
95
+ },
96
+ NO_SUCH_TOKEN_ERROR: {
97
+ CODE: 11030,
98
+ MSG: 'No such token',
99
+ },
100
+ INVALID_TOKEN_NAME_ERROR: {
101
+ CODE: 11031,
102
+ MSG: 'The length of token name must between 1 and 1024',
103
+ },
104
+ INVALID_TOKEN_SYMBOL_ERROR: {
105
+ CODE: 11032,
106
+ MSG: 'The length of symbol must between 1 and 1024',
107
+ },
108
+ INVALID_TOKEN_DECIMALS_ERROR: {
109
+ CODE: 11033,
110
+ MSG: 'Decimals must between 0 and 8',
111
+ },
112
+ INVALID_TOKEN_TOTALSUPPLY_ERROR: {
113
+ CODE: 11034,
114
+ MSG: 'TotalSupply must between 1 and max(int64)',
115
+ },
116
+ INVALID_TOKENOWNER_ERRPR: {
117
+ CODE: 11035,
118
+ MSG: 'Invalid token owner',
119
+ },
120
+ INVALID_CONTRACTADDRESS_ERROR: {
121
+ CODE: 11037,
122
+ MSG: 'Invalid contract address',
123
+ },
124
+ CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR: {
125
+ CODE: 11038,
126
+ MSG: 'ContractAddress is not a contract account',
127
+ },
128
+ INVALID_TOKEN_AMOUNT_ERROR: {
129
+ CODE: 11039,
130
+ MSG: 'Token amount must between 1 and max(int64)',
131
+ },
132
+ SOURCEADDRESS_EQUAL_CONTRACTADDRESS_ERROR: {
133
+ CODE: 11040,
134
+ MSG: 'SourceAddress cannot be equal to contractAddress',
135
+ },
136
+ INVALID_FROMADDRESS_ERROR: {
137
+ CODE: 11041,
138
+ MSG: 'Invalid fromAddress',
139
+ },
140
+ FROMADDRESS_EQUAL_DESTADDRESS_ERROR: {
141
+ CODE: 11042,
142
+ MSG: 'FromAddress cannot be equal to destAddress',
143
+ },
144
+ INVALID_SPENDER_ERROR: {
145
+ CODE: 11043,
146
+ MSG: 'Invalid spender',
147
+ },
148
+ PAYLOAD_EMPTY_ERROR: {
149
+ CODE: 11044,
150
+ MSG: 'Payload must be a non-empty string',
151
+ },
152
+ INVALID_LOG_TOPIC_ERROR: {
153
+ CODE: 11045,
154
+ MSG: 'The length of log topic must between 1 and 128',
155
+ },
156
+ INVALID_LOG_DATA_ERROR: {
157
+ CODE: 11046,
158
+ MSG: 'The length of one of log data must between 1 and 1024',
159
+ },
160
+ INVALID_CONTRACT_TYPE_ERROR: {
161
+ CODE: 11047,
162
+ MSG: 'Invalid contract type',
163
+ },
164
+ INVALID_NONCE_ERROR: {
165
+ CODE: 11048,
166
+ MSG: 'Nonce must between 1 and max(int64)',
167
+ },
168
+ INVALID_GASPRICE_ERROR: {
169
+ CODE: 11049,
170
+ MSG: 'GasPrice must between 1 and max(int64)',
171
+ },
172
+ INVALID_FEELIMIT_ERROR: {
173
+ CODE: 11050,
174
+ MSG: 'FeeLimit must between 1 and max(int64)',
175
+ },
176
+ OPERATIONS_EMPTY_ERROR: {
177
+ CODE: 11051,
178
+ MSG: 'Operations cannot be empty',
179
+ },
180
+ INVALID_CEILLEDGERSEQ_ERROR: {
181
+ CODE: 11052,
182
+ MSG: 'CeilLedgerSeq must be equal to or greater than 0',
183
+ },
184
+ OPERATIONS_ONE_ERROR: {
185
+ CODE: 11053,
186
+ MSG: 'One of operations error',
187
+ },
188
+ INVALID_SIGNATURENUMBER_ERROR: {
189
+ CODE: 11054,
190
+ MSG: 'SignagureNumber must between 1 and max(int32)',
191
+ },
192
+ INVALID_HASH_ERROR: {
193
+ CODE: 11055,
194
+ MSG: 'Invalid transaction hash',
195
+ },
196
+ INVALID_BLOB_ERROR: {
197
+ CODE: 11056,
198
+ MSG: 'Invalid blob',
199
+ },
200
+ PRIVATEKEY_NULL_ERROR: {
201
+ CODE: 11057,
202
+ MSG: 'PrivateKeys cannot be empty',
203
+ },
204
+ PRIVATEKEY_ONE_ERROR: {
205
+ CODE: 11058,
206
+ MSG: 'One of privateKeys is invalid',
207
+ },
208
+ INVALID_BLOCKNUMBER_ERROR: {
209
+ CODE: 11060,
210
+ MSG: 'BlockNumber must bigger than 0',
211
+ },
212
+ URL_EMPTY_ERROR: {
213
+ CODE: 11062,
214
+ MSG: 'Url cannot be empty',
215
+ },
216
+ CONTRACTADDRESS_CODE_BOTH_NULL_ERROR: {
217
+ CODE: 11063,
218
+ MSG: 'ContractAddress and code cannot be empty at the same time',
219
+ },
220
+ INVALID_OPTTYPE_ERROR: {
221
+ CODE: 11064,
222
+ MSG: 'OptType must between 0 and 2',
223
+ },
224
+ GET_ALLOWANCE_ERROR: {
225
+ CODE: 11065,
226
+ MSG: 'Get allowance failed',
227
+ },
228
+ GET_TOKEN_INFO_ERROR: {
229
+ CODE: 11066,
230
+ MSG: 'Fail to get token info',
231
+ },
232
+ CONNECTN_BLOCKCHAIN_ERROR: {
233
+ CODE: 19999,
234
+ MSG: 'Connect blockchain failed',
235
+ },
236
+ SYSTEM_ERROR: {
237
+ CODE: 20000,
238
+ MSG: 'System error',
239
+ },
240
+ };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const merge = require('merge-descriptors');
4
+
5
+ const proto = module.exports = {};
6
+
7
+ merge(proto, require('./errors'));
8
+ merge(proto, require('./customErrors'));
@@ -0,0 +1,193 @@
1
+ 'use strict';
2
+
3
+ const is = require('is-type-of');
4
+ const { keypair } = require('yxchain-encryption-nodejs');
5
+ const errors = require('../exception');
6
+
7
+ const proto = exports;
8
+
9
+ proto.accountActivateOperation = function(args) {
10
+ try {
11
+
12
+ if (is.array(args) || !is.object(args)) {
13
+ return this._responseError(errors.INVALID_ARGUMENTS);
14
+ }
15
+
16
+ const schema = {
17
+ sourceAddress: {
18
+ required: false,
19
+ address: true,
20
+ },
21
+ destAddress: {
22
+ required: true,
23
+ address: true,
24
+ },
25
+ initBalance: {
26
+ required: true,
27
+ numeric: true,
28
+ },
29
+ metadata: {
30
+ required: false,
31
+ string: true,
32
+ }
33
+ };
34
+
35
+ if (!this._validate(args, schema).tag) {
36
+ const msg = this._validate(args, schema).msg;
37
+ return this._responseError(errors[msg]);
38
+ }
39
+
40
+ if (args.sourceAddress && args.destAddress === args.sourceAddress) {
41
+ return this._responseError(errors.SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR);
42
+ }
43
+
44
+ return this._responseData({
45
+ operation: {
46
+ type: 'activateAccount',
47
+ data: args,
48
+ },
49
+ });
50
+ } catch (err) {
51
+ throw err;
52
+ }
53
+ };
54
+
55
+ proto.accountSetMetadataOperation = function(args) {
56
+ try {
57
+
58
+ if (is.array(args) || !is.object(args)) {
59
+ return this._responseError(errors.INVALID_ARGUMENTS);
60
+ }
61
+
62
+ const schema = {
63
+ key: {
64
+ required: true,
65
+ string: true,
66
+ },
67
+ sourceAddress: {
68
+ required: false,
69
+ address: true,
70
+ },
71
+ deleteFlag: {
72
+ required: false,
73
+ boolean: true,
74
+ },
75
+ metadata: {
76
+ required: false,
77
+ string: true,
78
+ }
79
+ };
80
+
81
+ if (!this._validate(args, schema).tag) {
82
+ const msg = this._validate(args, schema).msg;
83
+ return this._responseError(errors[msg]);
84
+ }
85
+
86
+ let value = args.value;
87
+
88
+ if (!is.string(value) ||
89
+ value.trim().length === 0 ||
90
+ value.length > 256000) {
91
+ return this._responseError(errors.INVALID_DATAVALUE_ERROR);
92
+ }
93
+
94
+ if (args.version && !this._isAvailableVersion(args.version)) {
95
+ return this._responseError(errors.INVALID_DATAVERSION_ERROR)
96
+ }
97
+
98
+ return this._responseData({
99
+ operation: {
100
+ type: 'accountSetMetadata',
101
+ data: args,
102
+ },
103
+ });
104
+ } catch (err) {
105
+ throw err;
106
+ }
107
+ };
108
+
109
+
110
+ proto.accountSetPrivilegeOperation = function(args = {}) {
111
+ try {
112
+
113
+ if (is.array(args) || !is.object(args)) {
114
+ return this._responseError(errors.INVALID_ARGUMENTS);
115
+ }
116
+
117
+ const schema = {
118
+ sourceAddress: {
119
+ required: false,
120
+ address: true,
121
+ },
122
+ metadata: {
123
+ required: false,
124
+ string: true,
125
+ },
126
+ };
127
+
128
+ if (!this._validate(args, schema).tag) {
129
+ const msg = this._validate(args, schema).msg;
130
+ return this._responseError(errors[msg]);
131
+ }
132
+
133
+ let maxInt32 = Math.pow(2, 32) - 1;
134
+
135
+ if (!is.undefined(args.masterWeight) && !this._isAvailableValue(args.masterWeight, -1, maxInt32)) {
136
+ return this._responseError(errors.INVALID_MASTERWEIGHT_ERROR)
137
+ }
138
+
139
+ if (!is.undefined(args.txThreshold) && !this._isAvailableValue(args.txThreshold)) {
140
+ return this._responseError(errors.INVALID_TX_THRESHOLD_ERROR)
141
+ }
142
+
143
+ const signers = args.signers;
144
+ const typeThresholds = args.typeThresholds;
145
+
146
+ if (is.array(signers) && signers.length > 0) {
147
+ let msg = '';
148
+ signers.some(item => {
149
+ if (!keypair.checkAddress(item.address)) {
150
+ msg = 'INVALID_SIGNER_ADDRESS_ERROR';
151
+ return true;
152
+ }
153
+
154
+ if (!this._isAvailableValue(item.weight, -1, maxInt32)) {
155
+ msg = 'INVALID_SIGNER_WEIGHT_ERROR';
156
+ return true;
157
+ }
158
+ });
159
+
160
+ if (msg !== '') {
161
+ return this._responseError(errors[msg]);
162
+ }
163
+ }
164
+
165
+ if (is.array(typeThresholds) && typeThresholds.length > 0) {
166
+ let msg = '';
167
+ typeThresholds.some(item => {
168
+ if (!this._isAvailableValue(item.type, -1, 100)) {
169
+ msg = 'INVALID_OPERATION_TYPE_ERROR';
170
+ return true;
171
+ }
172
+
173
+ if (!this._isAvailableValue(item.threshold)) {
174
+ msg = 'INVALID_TYPE_THRESHOLD_ERROR';
175
+ return true;
176
+ }
177
+ });
178
+
179
+ if (msg !== '') {
180
+ return this._responseError(errors[msg]);
181
+ }
182
+ }
183
+
184
+ return this._responseData({
185
+ operation: {
186
+ type: 'accountSetPrivilege',
187
+ data: args,
188
+ },
189
+ });
190
+ } catch (err) {
191
+ throw err;
192
+ }
193
+ };
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+
3
+ const is = require('is-type-of');
4
+ const errors = require('../exception');
5
+
6
+ const proto = exports;
7
+
8
+ proto.assetIssueOperation = function(args) {
9
+ try {
10
+ if (is.array(args) || !is.object(args)) {
11
+ return this._responseError(errors.INVALID_ARGUMENTS);
12
+ }
13
+
14
+ const schema = {
15
+ sourceAddress: {
16
+ required: false,
17
+ address: true,
18
+ },
19
+ code: {
20
+ required: true,
21
+ string: true,
22
+ },
23
+ assetAmount: {
24
+ required: true,
25
+ numeric: true,
26
+ },
27
+ metadata: {
28
+ required: false,
29
+ string: true,
30
+ }
31
+ };
32
+
33
+ if (!this._validate(args, schema).tag) {
34
+ const msg = this._validate(args, schema).msg;
35
+ return this._responseError(errors[msg]);
36
+ }
37
+
38
+ if (args.sourceAddress && args.destAddress === args.sourceAddress) {
39
+ return this._responseError(errors.SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR);
40
+ }
41
+
42
+ return this._responseData({
43
+ operation: {
44
+ type: 'issueAsset',
45
+ data: args,
46
+ },
47
+ });
48
+ } catch (err) {
49
+ throw err;
50
+ }
51
+ };
52
+
53
+
54
+ proto.assetSendOperation = function(args) {
55
+ try {
56
+ if (is.array(args) || !is.object(args)) {
57
+ return this._responseError(errors.INVALID_ARGUMENTS);
58
+ }
59
+
60
+ const schema = {
61
+ sourceAddress: {
62
+ required: false,
63
+ address: true,
64
+ },
65
+ destAddress: {
66
+ required: true,
67
+ address: true,
68
+ },
69
+ code: {
70
+ required: true,
71
+ string: true,
72
+ },
73
+ issuer: {
74
+ required: true,
75
+ string: true,
76
+ address: true,
77
+ },
78
+ assetAmount: {
79
+ required: true,
80
+ numeric: true,
81
+ },
82
+ metadata: {
83
+ required: false,
84
+ string: true,
85
+ }
86
+ };
87
+
88
+ if (!this._validate(args, schema).tag) {
89
+ const msg = this._validate(args, schema).msg;
90
+ return this._responseError(errors[msg]);
91
+ }
92
+
93
+ if (args.sourceAddress && args.destAddress === args.sourceAddress) {
94
+ return this._responseError(errors.SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR);
95
+ }
96
+
97
+ return this._responseData({
98
+ operation: {
99
+ type: 'payAsset',
100
+ data: args,
101
+ },
102
+ });
103
+ } catch (err) {
104
+ throw err;
105
+ }
106
+ };
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ const is = require('is-type-of');
4
+ const errors = require('../exception');
5
+
6
+ const proto = exports;
7
+
8
+ proto.buSendOperation = function(args) {
9
+ try {
10
+
11
+ if (is.array(args) || !is.object(args)) {
12
+ return this._responseError(errors.INVALID_ARGUMENTS);
13
+ }
14
+
15
+ const schema = {
16
+ sourceAddress: {
17
+ required: false,
18
+ address: true,
19
+ },
20
+ destAddress: {
21
+ required: true,
22
+ address: true,
23
+ },
24
+ buAmount: {
25
+ required: true,
26
+ numeric: true,
27
+ },
28
+ metadata: {
29
+ required: false,
30
+ string: true,
31
+ }
32
+ };
33
+
34
+ if (!this._validate(args, schema).tag) {
35
+ const msg = this._validate(args, schema).msg;
36
+ return this._responseError(errors[msg]);
37
+ }
38
+
39
+ if (args.sourceAddress && args.destAddress === args.sourceAddress) {
40
+ return this._responseError(errors.SOURCEADDRESS_EQUAL_DESTADDRESS_ERROR);
41
+ }
42
+
43
+ return this._responseData({
44
+ operation: {
45
+ type: 'payCoin',
46
+ data: args,
47
+ },
48
+ });
49
+ } catch (err) {
50
+ throw err;
51
+ }
52
+ };