openchain-nodejs-ts-yxl 1.0.3 → 1.0.4

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 (2) hide show
  1. package/index.d.ts +910 -18
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -39,82 +39,163 @@ declare class OpenChainSDK {
39
39
  * @example
40
40
  * sdk.account.create().then(console.log);
41
41
  *
42
+ * // 返回示例:
43
+ * {
44
+ * errorCode: 0,
45
+ * result: {
46
+ * privateKey: 'priv4FXWYaYMpGMeYtEPyUWBCH5aGVGtGR5uvtXGKxgBU2',
47
+ * publicKey: 'b001d8236a15923c91eab5b36dc0ea7c5faad04ed9184246a5d18c4547b06c89e4b',
48
+ * address: 'adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF'
49
+ * }
50
+ * }
51
+ *
42
52
  * // 错误码:
43
53
  * // - SYSTEM_ERROR 20000 系统错误
54
+ * // - KEYPAIR_CREATE_ERROR 11031 密钥对创建失败
44
55
  */
45
56
  create(): Promise<{ errorCode: number; result: { privateKey: string; publicKey: string; address: string } }>;
57
+
46
58
  /**
47
59
  * 查询账户信息
48
- * @param {string} address 账户地址
60
+ * @param {string} address 账户地址(需以'adx'开头的base58编码格式)
49
61
  * @returns {Promise<{errorCode:number, result:AccountInfoResult}>}
50
62
  * @example
51
- * sdk.account.getInfo('adxS...').then(console.log);
63
+ * sdk.account.getInfo('adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF').then(console.log);
64
+ *
65
+ * // 返回示例:
66
+ * {
67
+ * errorCode: 0,
68
+ * result: {
69
+ * address: 'adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF',
70
+ * balance: '1000000000',
71
+ * nonce: '1',
72
+ * type_thresholds: [{
73
+ * type: 1,
74
+ * threshold: '1'
75
+ * }]
76
+ * }
77
+ * }
52
78
  *
53
79
  * // 错误码:
54
- * // - INVALID_SOURCEADDRESS_ERROR 11002 无效地址
80
+ * // - INVALID_ADDRESS_ERROR 11002 无效地址
81
+ * // - ACCOUNT_NOT_EXIST 11003 账户不存在
82
+ * // - ACCOUNT_NOT_ACTIVATED 11004 账户未激活
55
83
  */
56
84
  getInfo(address: string): Promise<{ errorCode: number; result: AccountInfoResult }>;
85
+
57
86
  /**
58
87
  * 校验账户地址有效性
59
- * @param {string} address 待校验的区块链地址(需符合adx开头base58编码格式)
88
+ * @param {string} address 待校验的区块链地址(需以'adx'开头的base58编码格式)
60
89
  * @returns {Promise<{errorCode:number, result:{isValid:boolean}}>}
61
90
  * @example
62
- * sdk.account.checkValid('adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2').then(console.log);
91
+ * sdk.account.checkValid('adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF').then(console.log);
92
+ *
93
+ * // 返回示例:
94
+ * {
95
+ * errorCode: 0,
96
+ * result: {
97
+ * isValid: true
98
+ * }
99
+ * }
63
100
  *
64
101
  * // 错误码:
65
102
  * // - INVALID_ADDRESS_ERROR 11002 地址格式错误
103
+ * // - ADDRESS_LENGTH_ERROR 11003 地址长度错误
104
+ * // - ADDRESS_CHECKSUM_ERROR 11004 地址校验和错误
66
105
  */
67
106
  checkValid(address: string): Promise<{ errorCode: number; result: { isValid: boolean } }>;
68
107
 
69
108
  /**
70
109
  * 查询账户余额
71
- * @param {string} address 账户地址
110
+ * @param {string} address 账户地址(需以'adx'开头的base58编码格式)
72
111
  * @returns {Promise<{errorCode:number, result:{balance:string}}>} 余额单位MO(1 MO = 1e8 stroop)
73
112
  * @example
74
- * sdk.account.getBalance('adxS...').then(console.log);
113
+ * sdk.account.getBalance('adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF').then(console.log);
114
+ *
115
+ * // 返回示例:
116
+ * {
117
+ * errorCode: 0,
118
+ * result: {
119
+ * balance: '1000000000' // 10 MO
120
+ * }
121
+ * }
75
122
  *
76
123
  * // 错误码:
77
124
  * // - INVALID_ADDRESS_ERROR 11002 无效地址
78
125
  * // - ACCOUNT_NOT_EXIST 11003 账户不存在
126
+ * // - ACCOUNT_NOT_ACTIVATED 11004 账户未激活
79
127
  */
80
128
  getBalance(address: string): Promise<{ errorCode: number; result: { balance: string } }>;
81
129
 
82
130
  /**
83
131
  * 获取账户交易序列号
84
- * @param {string} address 账户地址
132
+ * @param {string} address 账户地址(需以'adx'开头的base58编码格式)
85
133
  * @returns {Promise<{errorCode:number, result:{nonce:string}}>} nonce值用于防止重放攻击
86
134
  * @example
87
- * sdk.account.getNonce('adxS...').then(console.log);
135
+ * sdk.account.getNonce('adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF').then(console.log);
136
+ *
137
+ * // 返回示例:
138
+ * {
139
+ * errorCode: 0,
140
+ * result: {
141
+ * nonce: '1'
142
+ * }
143
+ * }
88
144
  *
89
145
  * // 错误码:
90
146
  * // - INVALID_ADDRESS_ERROR 11002 无效地址
91
147
  * // - ACCOUNT_NOT_EXIST 11003 账户不存在
148
+ * // - ACCOUNT_NOT_ACTIVATED 11004 账户未激活
92
149
  */
93
150
  getNonce(address: string): Promise<{ errorCode: number; result: { nonce: string } }>;
94
151
 
95
152
  /**
96
153
  * 查询账户元数据
97
154
  * @param {Object} params 查询参数
98
- * @param {string} params.address 账户地址
99
- * @param {string} params.key 元数据键
155
+ * @param {string} params.address 账户地址(需以'adx'开头的base58编码格式)
156
+ * @param {string} params.key 元数据键(不超过1024字节)
100
157
  * @returns {Promise<{errorCode:number, result:MetadataResult}>} 包含版本号和值的元数据
101
158
  * @example
102
- * sdk.account.getMetadata({address:'adxS...', key:'kyc_info'}).then(console.log);
159
+ * sdk.account.getMetadata({
160
+ * address: 'adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF',
161
+ * key: 'kyc_info'
162
+ * }).then(console.log);
163
+ *
164
+ * // 返回示例:
165
+ * {
166
+ * errorCode: 0,
167
+ * result: {
168
+ * version: '1',
169
+ * value: 'metadata value'
170
+ * }
171
+ * }
103
172
  *
104
173
  * // 错误码:
105
174
  * // - METADATA_NOT_FOUND 12001 元数据不存在
106
175
  * // - INVALID_ADDRESS_ERROR 11002 无效地址
176
+ * // - INVALID_DATAKEY_ERROR 11011 无效的元数据键
177
+ * // - ACCOUNT_NOT_EXIST 11003 账户不存在
107
178
  */
108
179
  getMetadata(params: { address: string; key: string }): Promise<{ errorCode: number; result: MetadataResult }>;
109
180
 
110
181
  /**
111
182
  * 检查账户是否激活
112
- * @param {string} address 待检查账户地址
183
+ * @param {string} address 待检查账户地址(需以'adx'开头的base58编码格式)
113
184
  * @returns {Promise<{errorCode:number, result:{isActivated:boolean}}>}
114
185
  * @example
115
- * 参见test/accountActivateOperation.test.js示例
186
+ * sdk.account.isActivated('adxSZHxE1YzrDRyQCJVpx7aStghSvyJTQAzF').then(console.log);
187
+ *
188
+ * // 返回示例:
189
+ * {
190
+ * errorCode: 0,
191
+ * result: {
192
+ * isActivated: true
193
+ * }
194
+ * }
116
195
  *
117
196
  * // 错误码:
197
+ * // - INVALID_ADDRESS_ERROR 11002 无效地址
198
+ * // - ACCOUNT_NOT_EXIST 11003 账户不存在
118
199
  * // - ACCOUNT_NOT_ACTIVATED 11004 账户未激活
119
200
  */
120
201
  isActivated(address: string): Promise<{ errorCode: number; result: { isActivated: boolean } }>;
@@ -128,9 +209,21 @@ declare class OpenChainSDK {
128
209
  * @example
129
210
  * sdk.contract.getInfo('adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r').then(console.log);
130
211
  *
212
+ * // 返回示例:
213
+ * {
214
+ * errorCode: 0,
215
+ * result: {
216
+ * contract: {
217
+ * type: 0,
218
+ * payload: '...'
219
+ * }
220
+ * }
221
+ * }
222
+ *
131
223
  * // 错误码:
132
224
  * // - INVALID_CONTRACTADDRESS_ERROR 11037 无效合约地址
133
225
  * // - CONTRACTADDRESS_NOT_CONTRACTACCOUNT_ERROR 11038 非合约账户地址
226
+ * // - CONTRACT_NOT_EXIST 11039 合约不存在
134
227
  * // - SYSTEM_ERROR 20000 系统错误
135
228
  */
136
229
  getInfo(contractAddress: string): Promise<{ errorCode: number; result: ContractInfoResult }>;
@@ -142,10 +235,19 @@ declare class OpenChainSDK {
142
235
  * @example
143
236
  * sdk.contract.getAddress('cc4c...').then(console.log);
144
237
  *
238
+ * // 返回示例:
239
+ * {
240
+ * errorCode: 0,
241
+ * result: [{
242
+ * contract_address: 'adx...',
243
+ * operation_index: 0
244
+ * }]
245
+ * }
246
+ *
145
247
  * // 错误码:
146
248
  * // - INVALID_HASH_ERROR 11025 无效交易哈希
147
249
  * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
148
- * // 参见test/contractCreateTransaction.test.js示例
250
+ * // - INVALID_CONTRACT_HASH 11040 无效的合约哈希
149
251
  */
150
252
  getAddress(hash: string): Promise<{ errorCode: number; result: ContractAddressInfo[] }>;
151
253
 
@@ -158,12 +260,25 @@ declare class OpenChainSDK {
158
260
  * sourceAddress: 'adx...',
159
261
  * initBalance: '10',
160
262
  * type: 0,
161
- * payload: 'contract code'
263
+ * payload: 'contract code',
264
+ * initInput: 'constructor(param)',
265
+ * metadata: 'create contract'
162
266
  * }).then(console.log);
267
+ *
268
+ * // 返回示例:
269
+ * {
270
+ * errorCode: 0,
271
+ * result: {
272
+ * contract_address: 'adx...',
273
+ * operation_index: 0
274
+ * }
275
+ * }
163
276
  *
164
277
  * // 错误码:
165
278
  * // - INVALID_SOURCEADDRESS_ERROR 11002 无效源地址
166
279
  * // - PAYLOAD_EMPTY_ERROR 11044 合约代码为空
280
+ * // - INVALID_CONTRACT_TYPE 11041 无效的合约类型
281
+ * // - INVALID_INIT_BALANCE 11042 无效的初始化余额
167
282
  */
168
283
  createContract(params: ContractCreateParams): Promise<{ errorCode: number; result: ContractAddressInfo }>;
169
284
 
@@ -175,11 +290,24 @@ declare class OpenChainSDK {
175
290
  * sdk.contract.invokeContract({
176
291
  * sourceAddress: 'adx...',
177
292
  * contractAddress: 'adx...',
178
- * input: 'methodName(param)'
293
+ * input: 'methodName(param)',
294
+ * metadata: 'invoke contract'
179
295
  * }).then(console.log);
296
+ *
297
+ * // 返回示例:
298
+ * {
299
+ * errorCode: 0,
300
+ * result: {
301
+ * result: 'execution result',
302
+ * logs: 'execution logs'
303
+ * }
304
+ * }
180
305
  *
181
306
  * // 错误码:
182
307
  * // - CONTRACT_EXECUTE_FAILED 12003 合约执行失败
308
+ * // - INVALID_CONTRACTADDRESS_ERROR 11037 无效合约地址
309
+ * // - CONTRACT_NOT_EXIST 11039 合约不存在
310
+ * // - INVALID_INPUT_ERROR 11043 无效的输入参数
183
311
  */
184
312
  invokeContract(params: ContractInvokeParams): Promise<{ errorCode: number; result: ContractInvokeResult }>;
185
313
  };
@@ -219,6 +347,102 @@ declare class OpenChainSDK {
219
347
  * // - BLOCK_NOT_EXIST 11008 区块不存在
220
348
  */
221
349
  getTransactions(blockNumber: string): Promise<{ errorCode: number; result: TransactionListResult }>;
350
+
351
+ /**
352
+ * 获取指定区块信息
353
+ * @param {string} blockNumber 区块高度
354
+ * @returns {Promise<{errorCode:number, result:BlockInfoResult}>} 返回区块信息
355
+ * @example
356
+ * sdk.block.getInfo('100').then(console.log);
357
+ *
358
+ * // 错误码:
359
+ * // - INVALID_BLOCKNUMBER_ERROR 11007 无效区块高度
360
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
361
+ */
362
+ getInfo(blockNumber: string): Promise<{ errorCode: number; result: BlockInfoResult }>;
363
+
364
+ /**
365
+ * 获取最新区块信息
366
+ * @returns {Promise<{errorCode:number, result:BlockInfoResult}>} 返回最新区块信息
367
+ * @example
368
+ * sdk.block.getLatestInfo().then(console.log);
369
+ *
370
+ * // 错误码:
371
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
372
+ */
373
+ getLatestInfo(): Promise<{ errorCode: number; result: BlockInfoResult }>;
374
+
375
+ /**
376
+ * 获取指定区块的验证者信息
377
+ * @param {string} blockNumber 区块高度
378
+ * @returns {Promise<{errorCode:number, result:ValidatorsResult}>} 返回验证者信息
379
+ * @example
380
+ * sdk.block.getValidators('100').then(console.log);
381
+ *
382
+ * // 错误码:
383
+ * // - INVALID_BLOCKNUMBER_ERROR 11007 无效区块高度
384
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
385
+ */
386
+ getValidators(blockNumber: string): Promise<{ errorCode: number; result: ValidatorsResult }>;
387
+
388
+ /**
389
+ * 获取最新区块的验证者信息
390
+ * @returns {Promise<{errorCode:number, result:ValidatorsResult}>} 返回最新验证者信息
391
+ * @example
392
+ * sdk.block.getLatestValidators().then(console.log);
393
+ *
394
+ * // 错误码:
395
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
396
+ */
397
+ getLatestValidators(): Promise<{ errorCode: number; result: ValidatorsResult }>;
398
+
399
+ /**
400
+ * 获取指定区块的奖励信息
401
+ * @param {string} blockNumber 区块高度
402
+ * @returns {Promise<{errorCode:number, result:BlockRewardResult}>} 返回区块奖励信息
403
+ * @example
404
+ * sdk.block.getReward('100').then(console.log);
405
+ *
406
+ * // 错误码:
407
+ * // - INVALID_BLOCKNUMBER_ERROR 11007 无效区块高度
408
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
409
+ */
410
+ getReward(blockNumber: string): Promise<{ errorCode: number; result: BlockRewardResult }>;
411
+
412
+ /**
413
+ * 获取最新区块的奖励信息
414
+ * @returns {Promise<{errorCode:number, result:BlockRewardResult}>} 返回最新区块奖励信息
415
+ * @example
416
+ * sdk.block.getLatestReward().then(console.log);
417
+ *
418
+ * // 错误码:
419
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
420
+ */
421
+ getLatestReward(): Promise<{ errorCode: number; result: BlockRewardResult }>;
422
+
423
+ /**
424
+ * 获取指定区块的手续费信息
425
+ * @param {string} blockNumber 区块高度
426
+ * @returns {Promise<{errorCode:number, result:BlockFeesResult}>} 返回区块手续费信息
427
+ * @example
428
+ * sdk.block.getFees('100').then(console.log);
429
+ *
430
+ * // 错误码:
431
+ * // - INVALID_BLOCKNUMBER_ERROR 11007 无效区块高度
432
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
433
+ */
434
+ getFees(blockNumber: string): Promise<{ errorCode: number; result: BlockFeesResult }>;
435
+
436
+ /**
437
+ * 获取最新区块的手续费信息
438
+ * @returns {Promise<{errorCode:number, result:BlockFeesResult}>} 返回最新区块手续费信息
439
+ * @example
440
+ * sdk.block.getLatestFees().then(console.log);
441
+ *
442
+ * // 错误码:
443
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
444
+ */
445
+ getLatestFees(): Promise<{ errorCode: number; result: BlockFeesResult }>;
222
446
  };
223
447
 
224
448
  operation: {
@@ -242,12 +466,369 @@ declare class OpenChainSDK {
242
466
  * @returns {OperationResult} 返回操作结果
243
467
  */
244
468
  accountSetMetadataOperation(params: MetadataParams): { errorCode: number; result: OperationResult };
469
+
470
+ /**
471
+ * 创建合约操作
472
+ * @param {ContractCreateOperationParams} params 合约创建参数
473
+ * @returns {OperationResult} 返回操作结果
474
+ * @example
475
+ * sdk.operation.contractCreateOperation({
476
+ * sourceAddress: 'adx...',
477
+ * initBalance: '10000',
478
+ * type: 0,
479
+ * payload: 'contract code'
480
+ * });
481
+ */
482
+ contractCreateOperation(params: ContractCreateOperationParams): { errorCode: number; result: OperationResult };
483
+
484
+ /**
485
+ * 调用合约操作
486
+ * @param {ContractInvokeOperationParams} params 合约调用参数
487
+ * @returns {OperationResult} 返回操作结果
488
+ * @example
489
+ * sdk.operation.contractInvokeOperation({
490
+ * sourceAddress: 'adx...',
491
+ * contractAddress: 'adx...',
492
+ * input: 'method(param)'
493
+ * });
494
+ */
495
+ contractInvokeOperation(params: ContractInvokeOperationParams): { errorCode: number; result: OperationResult };
496
+
497
+ /**
498
+ * 发送Gas操作
499
+ * @param {GasSendOperationParams} params Gas发送参数
500
+ * @returns {OperationResult} 返回操作结果
501
+ * @example
502
+ * sdk.operation.gasSendOperation({
503
+ * sourceAddress: 'adx...',
504
+ * destAddress: 'adx...',
505
+ * amount: '1000'
506
+ * });
507
+ */
508
+ gasSendOperation(params: GasSendOperationParams): { errorCode: number; result: OperationResult };
509
+
510
+ /**
511
+ * 创建日志操作
512
+ * @param {LogCreateOperationParams} params 日志创建参数
513
+ * @returns {OperationResult} 返回操作结果
514
+ * @example
515
+ * sdk.operation.logCreateOperation({
516
+ * sourceAddress: 'adx...',
517
+ * topic: 'mytopic',
518
+ * data: 'log content'
519
+ * });
520
+ */
521
+ logCreateOperation(params: LogCreateOperationParams): { errorCode: number; result: OperationResult };
522
+ };
523
+
524
+ token: {
525
+ /**
526
+ * 发行代币
527
+ * @param {TokenIssueParams} params 代币发行参数
528
+ * @returns {Promise<{errorCode:number, result:TokenIssueResult}>}
529
+ * @example
530
+ * sdk.token.issue({
531
+ * sourceAddress: 'adx...',
532
+ * name: 'MyToken',
533
+ * code: 'MTK',
534
+ * totalSupply: '1000000',
535
+ * decimals: 8,
536
+ * description: 'My test token'
537
+ * }).then(console.log);
538
+ *
539
+ * // 返回示例:
540
+ * {
541
+ * errorCode: 0,
542
+ * result: {
543
+ * hash: '0x...',
544
+ * token: {
545
+ * code: 'MTK',
546
+ * issuer: 'adx...'
547
+ * }
548
+ * }
549
+ * }
550
+ *
551
+ * // 错误码:
552
+ * // - INVALID_SOURCEADDRESS_ERROR 11002 无效源地址
553
+ * // - TOKEN_CODE_INVALID 11101 无效的代币代码
554
+ * // - TOKEN_ALREADY_EXISTS 11102 代币已存在
555
+ * // - TOKEN_SUPPLY_LIMIT_ERROR 11103 代币发行量超出限制
556
+ */
557
+ issue(params: TokenIssueParams): Promise<{ errorCode: number; result: TokenIssueResult }>;
558
+
559
+ /**
560
+ * 转移代币
561
+ * @param {TokenTransferParams} params 代币转移参数
562
+ * @returns {Promise<{errorCode:number, result:TokenTransferResult}>}
563
+ * @example
564
+ * sdk.token.transfer({
565
+ * sourceAddress: 'adx...',
566
+ * destAddress: 'adx...',
567
+ * code: 'MTK',
568
+ * amount: '100',
569
+ * metadata: 'transfer token'
570
+ * }).then(console.log);
571
+ *
572
+ * // 返回示例:
573
+ * {
574
+ * errorCode: 0,
575
+ * result: {
576
+ * hash: '0x...'
577
+ * }
578
+ * }
579
+ *
580
+ * // 错误码:
581
+ * // - INVALID_SOURCEADDRESS_ERROR 11002 无效源地址
582
+ * // - INVALID_DESTADDRESS_ERROR 11003 无效目标地址
583
+ * // - TOKEN_NOT_FOUND 11104 代币不存在
584
+ * // - INSUFFICIENT_TOKEN_BALANCE 11105 代币余额不足
585
+ */
586
+ transfer(params: TokenTransferParams): Promise<{ errorCode: number; result: TokenTransferResult }>;
587
+
588
+ /**
589
+ * 查询代币信息
590
+ * @param {string} code 代币代码
591
+ * @returns {Promise<{errorCode:number, result:TokenInfoResult}>}
592
+ * @example
593
+ * sdk.token.getInfo('MTK').then(console.log);
594
+ *
595
+ * // 返回示例:
596
+ * {
597
+ * errorCode: 0,
598
+ * result: {
599
+ * token: {
600
+ * code: 'MTK',
601
+ * name: 'MyToken',
602
+ * description: 'My test token',
603
+ * decimals: 8,
604
+ * totalSupply: '1000000',
605
+ * issuer: 'adx...',
606
+ * createTime: '1632047037000'
607
+ * }
608
+ * }
609
+ * }
610
+ *
611
+ * // 错误码:
612
+ * // - TOKEN_NOT_FOUND 11104 代币不存在
613
+ */
614
+ getInfo(code: string): Promise<{ errorCode: number; result: TokenInfoResult }>;
615
+
616
+ /**
617
+ * 查询代币余额
618
+ * @param {TokenBalanceParams} params 余额查询参数
619
+ * @returns {Promise<{errorCode:number, result:TokenBalanceResult}>}
620
+ * @example
621
+ * sdk.token.getBalance({
622
+ * address: 'adx...',
623
+ * code: 'MTK'
624
+ * }).then(console.log);
625
+ *
626
+ * // 返回示例:
627
+ * {
628
+ * errorCode: 0,
629
+ * result: {
630
+ * balance: '100',
631
+ * frozen: '0'
632
+ * }
633
+ * }
634
+ *
635
+ * // 错误码:
636
+ * // - INVALID_ADDRESS_ERROR 11002 无效地址
637
+ * // - TOKEN_NOT_FOUND 11104 代币不存在
638
+ */
639
+ getBalance(params: TokenBalanceParams): Promise<{ errorCode: number; result: TokenBalanceResult }>;
640
+
641
+ /**
642
+ * 查询代币持有者列表
643
+ * @param {TokenHoldersParams} params 持有者查询参数
644
+ * @returns {Promise<{errorCode:number, result:TokenHoldersResult}>}
645
+ * @example
646
+ * sdk.token.getHolders({
647
+ * code: 'MTK',
648
+ * limit: 10,
649
+ * offset: 0
650
+ * }).then(console.log);
651
+ *
652
+ * // 返回示例:
653
+ * {
654
+ * errorCode: 0,
655
+ * result: {
656
+ * total: 100,
657
+ * holders: [{
658
+ * address: 'adx...',
659
+ * balance: '1000',
660
+ * percentage: '0.001'
661
+ * }]
662
+ * }
663
+ * }
664
+ *
665
+ * // 错误码:
666
+ * // - TOKEN_NOT_FOUND 11104 代币不存在
667
+ * // - INVALID_PARAMETER 11001 无效参数
668
+ */
669
+ getHolders(params: TokenHoldersParams): Promise<{ errorCode: number; result: TokenHoldersResult }>;
670
+ };
671
+
672
+ util: {
673
+ /**
674
+ * 检查对象是否为 BigNumber 类型
675
+ * @param {any} object 要检查的对象
676
+ * @returns {boolean} 如果对象是 BigNumber 类型返回 true,否则返回 false
677
+ * @example
678
+ * const isBig = sdk.util.isBigNumber(new BigNumber('100'));
679
+ * console.log(isBig); // true
680
+ */
681
+ isBigNumber(object: any): boolean;
682
+
683
+ /**
684
+ * 将输入数据转换为 BigNumber 对象
685
+ * @param {string | number} data 要转换的数据
686
+ * @returns {BigNumber} 转换后的 BigNumber 对象
687
+ * @example
688
+ * const big = sdk.util.toBigNumber('100');
689
+ * console.log(big.toString()); // '100'
690
+ */
691
+ toBigNumber(data: string | number): any; // 返回 BigNumber 类型
692
+
693
+ /**
694
+ * 将 UTF-8 字符串转换为十六进制字符串
695
+ * @param {string} str UTF-8 字符串
696
+ * @returns {string} 转换后的十六进制字符串
697
+ * @example
698
+ * const hex = sdk.util.utfToHex('Hello');
699
+ * console.log(hex); // '48656c6c6f'
700
+ */
701
+ utfToHex(str: string): string;
702
+
703
+ /**
704
+ * 将十六进制字符串转换为 UTF-8 字符串
705
+ * @param {string} str 十六进制字符串
706
+ * @returns {string} 转换后的 UTF-8 字符串
707
+ * @example
708
+ * const text = sdk.util.hexToUtf('48656c6c6f');
709
+ * console.log(text); // 'Hello'
710
+ */
711
+ hexToUtf(str: string): string;
712
+
713
+ /**
714
+ * 将 BU 单位的数值转换为 MO 单位
715
+ * @param {string} bu BU 单位的数值
716
+ * @returns {string} MO 单位的数值字符串
717
+ * @example
718
+ * const mo = sdk.util.buToMo('1');
719
+ * console.log(mo); // '100000000'
720
+ */
721
+ buToMo(bu: string): string;
722
+
723
+ /**
724
+ * 将 MO 单位的数值转换为 BU 单位
725
+ * @param {string} mo MO 单位的数值
726
+ * @returns {string} BU 单位的数值字符串
727
+ * @example
728
+ * const bu = sdk.util.moToBu('100000000');
729
+ * console.log(bu); // '1'
730
+ */
731
+ moToBu(mo: string): string;
732
+
733
+ /**
734
+ * 根据指定的小数位数计算代币数量
735
+ * @param {string} amount 代币数量
736
+ * @param {string} decimals 小数位数
737
+ * @returns {string | false} 计算后的数值字符串,如果计算结果无效则返回 false
738
+ * @example
739
+ * const amount = sdk.util.unitWithDecimals('100', '8');
740
+ * console.log(amount); // '10000000000'
741
+ */
742
+ unitWithDecimals(amount: string, decimals: string): string | false;
245
743
  };
246
744
 
247
745
  transaction: {
248
- buildBlob(params: TransactionParams): Promise<{ errorCode: number; result: TransactionBuildBlobResult }>;
746
+ /**
747
+ * 构建交易
748
+ * @param {TransactionBuildBlobParams} params 交易构建参数
749
+ * @returns {Promise<{errorCode:number, result:TransactionBuildBlobResult}>} 返回交易blob
750
+ * @example
751
+ * sdk.transaction.buildBlob({
752
+ * sourceAddress: 'adx...',
753
+ * gasPrice: '100',
754
+ * feeLimit: '1000000',
755
+ * nonce: '1',
756
+ * operations: [{...}]
757
+ * }).then(console.log);
758
+ *
759
+ * // 错误码:
760
+ * // - INVALID_ARGUMENTS 11001 无效参数
761
+ * // - INVALID_SOURCEADDRESS_ERROR 11002 无效源地址
762
+ */
763
+ buildBlob(params: TransactionBuildBlobParams): Promise<{ errorCode: number; result: TransactionBuildBlobResult }>;
764
+
765
+ /**
766
+ * 签名交易
767
+ * @param {TransactionSignParams} params 签名参数
768
+ * @returns {Promise<{errorCode:number, result:TransactionSignResult}>} 返回签名结果
769
+ * @example
770
+ * sdk.transaction.sign({
771
+ * privateKeys: ['priv...'],
772
+ * blob: '0x...'
773
+ * }).then(console.log);
774
+ *
775
+ * // 错误码:
776
+ * // - INVALID_ARGUMENTS 11001 无效参数
777
+ * // - PRIVATEKEY_NULL_ERROR 11057 私钥不能为空
778
+ * // - INVALID_BLOB_ERROR 11056 无效的blob数据
779
+ */
249
780
  sign(params: TransactionSignParams): Promise<{ errorCode: number; result: TransactionSignResult }>;
781
+
782
+ /**
783
+ * 提交交易
784
+ * @param {TransactionSubmitParams} params 提交参数
785
+ * @returns {Promise<{errorCode:number, result:TransactionSubmitResult}>} 返回提交结果
786
+ * @example
787
+ * sdk.transaction.submit({
788
+ * blob: '0x...',
789
+ * signatures: [{
790
+ * signData: '0x...',
791
+ * publicKey: '0x...'
792
+ * }]
793
+ * }).then(console.log);
794
+ *
795
+ * // 错误码:
796
+ * // - INVALID_ARGUMENTS 11001 无效参数
797
+ * // - INVALID_BLOB_ERROR 11056 无效的blob数据
798
+ * // - SIGNATURE_EMPTY_ERROR 11067 签名数据不能为空
799
+ */
250
800
  submit(params: TransactionSubmitParams): Promise<{ errorCode: number; result: TransactionSubmitResult }>;
801
+
802
+ /**
803
+ * 评估交易费用
804
+ * @param {TransactionEvaluateFeeParams} params 评估参数
805
+ * @returns {Promise<{errorCode:number, result:TransactionEvaluateFeeResult}>} 返回费用评估结果
806
+ * @example
807
+ * sdk.transaction.evaluateFee({
808
+ * sourceAddress: 'adx...',
809
+ * nonce: '1',
810
+ * operations: [{...}],
811
+ * signtureNumber: '1'
812
+ * }).then(console.log);
813
+ *
814
+ * // 错误码:
815
+ * // - INVALID_ARGUMENTS 11001 无效参数
816
+ * // - INVALID_SOURCEADDRESS_ERROR 11002 无效源地址
817
+ * // - INVALID_NONCE_ERROR 11048 无效nonce值
818
+ */
819
+ evaluateFee(params: TransactionEvaluateFeeParams): Promise<{ errorCode: number; result: TransactionEvaluateFeeResult }>;
820
+
821
+ /**
822
+ * 获取交易信息
823
+ * @param {string} hash 交易哈希
824
+ * @returns {Promise<{errorCode:number, result:TransactionResult}>} 返回交易详情
825
+ * @example
826
+ * sdk.transaction.getInfo('0x...').then(console.log);
827
+ *
828
+ * // 错误码:
829
+ * // - INVALID_HASH_ERROR 11025 无效的交易哈希
830
+ * // - QUERY_RESULT_NOT_EXIST 12002 查询结果不存在
831
+ */
251
832
  getInfo(hash: string): Promise<{ errorCode: number; result: TransactionResult }>;
252
833
  };
253
834
  }
@@ -418,6 +999,70 @@ export interface AccountActivateParams {
418
999
  metadata?: string;
419
1000
  }
420
1001
 
1002
+ /**
1003
+ * 合约创建操作参数
1004
+ * @interface
1005
+ * @property {string} sourceAddress 操作源账户地址
1006
+ * @property {string} initBalance 合约初始化余额
1007
+ * @property {number} type 合约类型(0-JavaScript, 1-EVM)
1008
+ * @property {string} payload 合约代码
1009
+ * @property {string} [initInput] 合约初始化参数
1010
+ * @property {string} [metadata] 操作备注
1011
+ */
1012
+ export interface ContractCreateOperationParams {
1013
+ sourceAddress: string;
1014
+ initBalance: string;
1015
+ type: number;
1016
+ payload: string;
1017
+ initInput?: string;
1018
+ metadata?: string;
1019
+ }
1020
+
1021
+ /**
1022
+ * 合约调用操作参数
1023
+ * @interface
1024
+ * @property {string} sourceAddress 调用者账户地址
1025
+ * @property {string} contractAddress 合约账户地址
1026
+ * @property {string} input 合约调用输入数据
1027
+ * @property {string} [metadata] 操作备注
1028
+ */
1029
+ export interface ContractInvokeOperationParams {
1030
+ sourceAddress: string;
1031
+ contractAddress: string;
1032
+ input: string;
1033
+ metadata?: string;
1034
+ }
1035
+
1036
+ /**
1037
+ * Gas发送操作参数
1038
+ * @interface
1039
+ * @property {string} sourceAddress 发送方账户地址
1040
+ * @property {string} destAddress 接收方账户地址
1041
+ * @property {string} amount 发送金额(单位MO)
1042
+ * @property {string} [metadata] 操作备注
1043
+ */
1044
+ export interface GasSendOperationParams {
1045
+ sourceAddress: string;
1046
+ destAddress: string;
1047
+ amount: string;
1048
+ metadata?: string;
1049
+ }
1050
+
1051
+ /**
1052
+ * 日志创建操作参数
1053
+ * @interface
1054
+ * @property {string} sourceAddress 操作源账户地址
1055
+ * @property {string} topic 日志主题
1056
+ * @property {string} data 日志内容
1057
+ * @property {string} [metadata] 操作备注
1058
+ */
1059
+ export interface LogCreateOperationParams {
1060
+ sourceAddress: string;
1061
+ topic: string;
1062
+ data: string;
1063
+ metadata?: string;
1064
+ }
1065
+
421
1066
  /**
422
1067
  * 交易参数结构定义
423
1068
  * @interface
@@ -532,4 +1177,251 @@ export interface TransactionResult {
532
1177
  txSize: number;
533
1178
  }>;
534
1179
  }
1180
+
1181
+
1182
+ /**
1183
+ * 区块信息查询结果
1184
+ * @interface
1185
+ */
1186
+ export interface BlockInfoResult {
1187
+ closeTime: string;
1188
+ number: string;
1189
+ txCount: string;
1190
+ version: string;
1191
+ }
1192
+
1193
+ /**
1194
+ * 验证者信息查询结果
1195
+ * @interface
1196
+ */
1197
+ export interface ValidatorsResult {
1198
+ validators: Array<{
1199
+ address: string;
1200
+ pledge_coin_amount: string;
1201
+ [key: string]: any;
1202
+ }>;
1203
+ }
1204
+
1205
+ /**
1206
+ * 区块奖励信息查询结果
1207
+ * @interface
1208
+ */
1209
+ export interface BlockRewardResult {
1210
+ blockReward: string;
1211
+ validatorsReward: Array<{
1212
+ validator: string;
1213
+ reward: string;
1214
+ }>;
1215
+ }
1216
+
1217
+ /**
1218
+ * 区块手续费信息查询结果
1219
+ * @interface
1220
+ */
1221
+ export interface BlockFeesResult {
1222
+ fees: {
1223
+ base_reserve: string;
1224
+ gas_price: string;
1225
+ [key: string]: any;
1226
+ };
1227
+ }
1228
+
1229
+ /**
1230
+ * 代币发行参数
1231
+ * @interface
1232
+ * @property {string} sourceAddress 发行者账户地址
1233
+ * @property {string} name 代币名称
1234
+ * @property {string} code 代币代码(唯一标识)
1235
+ * @property {string} totalSupply 发行总量
1236
+ * @property {number} decimals 小数位数(0-8)
1237
+ * @property {string} [description] 代币描述
1238
+ * @property {string} [icon] 代币图标URL
1239
+ * @property {string} [metadata] 操作备注
1240
+ */
1241
+ export interface TokenIssueParams {
1242
+ sourceAddress: string;
1243
+ name: string;
1244
+ code: string;
1245
+ totalSupply: string;
1246
+ decimals: number;
1247
+ description?: string;
1248
+ icon?: string;
1249
+ metadata?: string;
1250
+ }
1251
+
1252
+ /**
1253
+ * 代币发行结果
1254
+ * @interface
1255
+ * @property {string} hash 交易哈希
1256
+ * @property {Object} token 代币信息
1257
+ */
1258
+ export interface TokenIssueResult {
1259
+ hash: string;
1260
+ token: {
1261
+ code: string;
1262
+ issuer: string;
1263
+ };
1264
+ }
1265
+
1266
+ /**
1267
+ * 代币转移参数
1268
+ * @interface
1269
+ * @property {string} sourceAddress 转出账户地址
1270
+ * @property {string} destAddress 转入账户地址
1271
+ * @property {string} code 代币代码
1272
+ * @property {string} amount 转移数量
1273
+ * @property {string} [metadata] 操作备注
1274
+ */
1275
+ export interface TokenTransferParams {
1276
+ sourceAddress: string;
1277
+ destAddress: string;
1278
+ code: string;
1279
+ amount: string;
1280
+ metadata?: string;
1281
+ }
1282
+
1283
+ /**
1284
+ * 代币转移结果
1285
+ * @interface
1286
+ * @property {string} hash 交易哈希
1287
+ */
1288
+ export interface TokenTransferResult {
1289
+ hash: string;
1290
+ }
1291
+
1292
+ /**
1293
+ * 代币信息查询结果
1294
+ * @interface
1295
+ * @property {Object} token 代币详情
1296
+ */
1297
+ export interface TokenInfoResult {
1298
+ token: {
1299
+ code: string;
1300
+ name: string;
1301
+ description?: string;
1302
+ decimals: number;
1303
+ totalSupply: string;
1304
+ issuer: string;
1305
+ createTime: string;
1306
+ icon?: string;
1307
+ };
1308
+ }
1309
+
1310
+ /**
1311
+ * 代币余额查询参数
1312
+ * @interface
1313
+ * @property {string} address 账户地址
1314
+ * @property {string} code 代币代码
1315
+ */
1316
+ export interface TokenBalanceParams {
1317
+ address: string;
1318
+ code: string;
1319
+ }
1320
+
1321
+ /**
1322
+ * 代币余额查询结果
1323
+ * @interface
1324
+ * @property {string} balance 可用余额
1325
+ * @property {string} frozen 冻结金额
1326
+ */
1327
+ export interface TokenBalanceResult {
1328
+ balance: string;
1329
+ frozen: string;
1330
+ }
1331
+
1332
+ /**
1333
+ * 代币持有者查询参数
1334
+ * @interface
1335
+ * @property {string} code 代币代码
1336
+ * @property {number} [limit] 返回记录数量限制
1337
+ * @property {number} [offset] 起始位置偏移量
1338
+ */
1339
+ export interface TokenHoldersParams {
1340
+ code: string;
1341
+ limit?: number;
1342
+ offset?: number;
1343
+ }
1344
+
1345
+ /**
1346
+ * 代币持有者查询结果
1347
+ * @interface
1348
+ * @property {number} total 总持有者数量
1349
+ * @property {Array} holders 持有者列表
1350
+ */
1351
+ export interface TokenHoldersResult {
1352
+ total: number;
1353
+ holders: Array<{
1354
+ address: string;
1355
+ balance: string;
1356
+ percentage: string;
1357
+ }>;
1358
+ }
1359
+
1360
+ /**
1361
+ * 交易构建参数
1362
+ * @interface
1363
+ * @property {string} sourceAddress 交易发起账户地址
1364
+ * @property {string} nonce 交易序列号
1365
+ * @property {OperationResult[]} operations 操作列表
1366
+ * @property {string} [gasPrice] Gas单价(单位MO)
1367
+ * @property {string} [feeLimit] 交易费用上限
1368
+ * @property {string} [metadata] 交易备注
1369
+ * @example
1370
+ * {
1371
+ * sourceAddress: 'adx...',
1372
+ * gasPrice: '100',
1373
+ * feeLimit: '1000000',
1374
+ * nonce: '1',
1375
+ * operations: [{...}]
1376
+ * }
1377
+ */
1378
+ export interface TransactionBuildBlobParams {
1379
+ sourceAddress: string;
1380
+ nonce: string;
1381
+ operations: OperationResult[];
1382
+ gasPrice?: string;
1383
+ feeLimit?: string;
1384
+ metadata?: string;
1385
+ }
1386
+
1387
+ /**
1388
+ * 交易费用评估参数
1389
+ * @interface
1390
+ * @property {string} sourceAddress 交易发起账户地址
1391
+ * @property {string} nonce 交易序列号
1392
+ * @property {OperationResult[]} operations 操作列表
1393
+ * @property {string} signtureNumber 签名数量
1394
+ * @property {string} [metadata] 交易备注
1395
+ * @example
1396
+ * {
1397
+ * sourceAddress: 'adx...',
1398
+ * nonce: '1',
1399
+ * operations: [{...}],
1400
+ * signtureNumber: '1'
1401
+ * }
1402
+ */
1403
+ export interface TransactionEvaluateFeeParams {
1404
+ sourceAddress: string;
1405
+ nonce: string;
1406
+ operations: OperationResult[];
1407
+ signtureNumber: string;
1408
+ metadata?: string;
1409
+ }
1410
+
1411
+ /**
1412
+ * 交易费用评估结果
1413
+ * @interface
1414
+ * @property {string} gasPrice 建议的Gas单价(单位MO)
1415
+ * @property {string} feeLimit 建议的费用上限
1416
+ * @example
1417
+ * {
1418
+ * gasPrice: '100',
1419
+ * feeLimit: '1000000'
1420
+ * }
1421
+ */
1422
+ export interface TransactionEvaluateFeeResult {
1423
+ gasPrice: string;
1424
+ feeLimit: string;
1425
+ }
1426
+
535
1427
  export default OpenChainSDK;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openchain-nodejs-ts-yxl",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "openchain sdk",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",