@@ -90,21 +90,21 @@ export function getHexAddressFromBase58Address(base58: string): string {
90
90
// pulled from: https://github.com/TRON-US/tronweb/blob/dcb8efa36a5ebb65c4dab3626e90256a453f3b0d/src/utils/help.js#L17
91
91
// but they don't surface this call in index.js
92
92
const bytes = tronweb . utils . crypto . decodeBase58Address ( base58 ) ;
93
- return getHexAddressFromByteArray ( bytes ) ;
93
+ return getHexAddressFromByteArray ( bytes as any ) ;
94
94
}
95
95
96
96
/**
97
97
* @param privateKey
98
98
*/
99
99
export function getPubKeyFromPriKey ( privateKey : TronBinaryLike ) : ByteArray {
100
- return tronweb . utils . crypto . getPubKeyFromPriKey ( privateKey ) ;
100
+ return tronweb . utils . crypto . getPubKeyFromPriKey ( privateKey as any ) ;
101
101
}
102
102
103
103
/**
104
104
* @param privateKey
105
105
*/
106
106
export function getAddressFromPriKey ( privateKey : TronBinaryLike ) : ByteArray {
107
- return tronweb . utils . crypto . getAddressFromPriKey ( privateKey ) ;
107
+ return tronweb . utils . crypto . getAddressFromPriKey ( privateKey as any ) ;
108
108
}
109
109
110
110
/**
@@ -127,7 +127,7 @@ export function getBase58AddressFromHex(hex: string): string {
127
127
* @param transaction
128
128
*/
129
129
export function signTransaction ( privateKey : string | ByteArray , transaction : TransactionReceipt ) : TransactionReceipt {
130
- return tronweb . utils . crypto . signTransaction ( privateKey , transaction ) ;
130
+ return tronweb . utils . crypto . signTransaction ( privateKey , transaction ) as unknown as TransactionReceipt ;
131
131
}
132
132
133
133
/**
@@ -136,14 +136,14 @@ export function signTransaction(privateKey: string | ByteArray, transaction: Tra
136
136
* @param useTronHeader
137
137
*/
138
138
export function signString ( message : string , privateKey : string | ByteArray , useTronHeader = true ) : string {
139
- return tronweb . Trx . signString ( message , privateKey , useTronHeader ) ;
139
+ return tronweb . Trx . signString ( message , privateKey as any , useTronHeader ) ;
140
140
}
141
141
142
142
/**
143
143
* @param pubBytes
144
144
*/
145
145
export function getRawAddressFromPubKey ( pubBytes : TronBinaryLike ) : ByteArray {
146
- return tronweb . utils . crypto . computeAddress ( pubBytes ) ;
146
+ return tronweb . utils . crypto . computeAddress ( pubBytes as any ) ;
147
147
}
148
148
149
149
/**
@@ -175,6 +175,14 @@ export function decodeTransaction(hexString: string): RawData {
175
175
contractType = ContractType . TriggerSmartContract ;
176
176
contract = exports . decodeTriggerSmartContract ( rawTransaction . contracts [ 0 ] . parameter . value ) ;
177
177
break ;
178
+ case 'type.googleapis.com/protocol.WithdrawExpireUnfreezeContract' :
179
+ contract = decodeWithdrawExpireUnfreezeContract ( rawTransaction . contracts [ 0 ] . parameter . value ) ;
180
+ contractType = ContractType . WithdrawExpireUnfreeze ;
181
+ break ;
182
+ case 'type.googleapis.com/protocol.UnfreezeBalanceV2Contract' :
183
+ contract = decodeUnfreezeBalanceV2Contract ( rawTransaction . contracts [ 0 ] . parameter . value ) ;
184
+ contractType = ContractType . UnfreezeBalanceV2 ;
185
+ break ;
178
186
default :
179
187
throw new UtilsError ( 'Unsupported contract type' ) ;
180
188
}
@@ -360,6 +368,97 @@ export function decodeAccountPermissionUpdateContract(base64: string): AccountPe
360
368
} ;
361
369
}
362
370
371
+ /**
372
+ * Deserialize the segment of the txHex corresponding with unfreeze balance contract
373
+ *
374
+ * @param {string } base64 - The base64 encoded contract data
375
+ * @returns {Array } - Array containing the decoded unfreeze contract
376
+ */
377
+ export function decodeUnfreezeBalanceV2Contract ( base64 : string ) : any [ ] {
378
+ let unfreezeContract ;
379
+ try {
380
+ unfreezeContract = protocol . UnfreezeBalanceContract . decode ( Buffer . from ( base64 , 'base64' ) ) . toJSON ( ) ;
381
+ } catch ( e ) {
382
+ throw new UtilsError ( 'There was an error decoding the unfreeze contract in the transaction.' ) ;
383
+ }
384
+
385
+ if ( ! unfreezeContract . ownerAddress ) {
386
+ throw new UtilsError ( 'Owner address does not exist in this unfreeze contract.' ) ;
387
+ }
388
+
389
+ if ( ! unfreezeContract . resource ) {
390
+ throw new UtilsError ( 'Resource type does not exist in this unfreeze contract.' ) ;
391
+ }
392
+
393
+ if ( ! unfreezeContract . hasOwnProperty ( 'unfrozenBalance' ) ) {
394
+ throw new UtilsError ( 'Unfreeze balance does not exist in this unfreeze contract.' ) ;
395
+ }
396
+
397
+ // deserialize attributes
398
+ const owner_address = getBase58AddressFromByteArray (
399
+ getByteArrayFromHexAddress ( Buffer . from ( unfreezeContract . ownerAddress , 'base64' ) . toString ( 'hex' ) )
400
+ ) ;
401
+
402
+ // Convert ResourceCode enum value to string resource name
403
+ const resourceValue = unfreezeContract . resource ;
404
+ let resource : string ;
405
+ if ( resourceValue === protocol . ResourceCode . BANDWIDTH ) {
406
+ resource = 'BANDWIDTH' ;
407
+ } else if ( resourceValue === protocol . ResourceCode . ENERGY ) {
408
+ resource = 'ENERGY' ;
409
+ } else {
410
+ throw new UtilsError ( `Unknown resource type: ${ resourceValue } ` ) ;
411
+ }
412
+
413
+ const unfreeze_balance = unfreezeContract . unfrozenBalance ;
414
+
415
+ return [
416
+ {
417
+ parameter : {
418
+ value : {
419
+ resource,
420
+ unfreeze_balance : Number ( unfreeze_balance ) ,
421
+ owner_address,
422
+ } ,
423
+ } ,
424
+ } ,
425
+ ] ;
426
+ }
427
+
428
+ /**
429
+ * Deserialize the segment of the txHex corresponding with withdraw expire unfreeze contract
430
+ *
431
+ * @param {string } base64 - The base64 encoded contract data
432
+ * @returns {Array } - Array containing the decoded withdraw contract
433
+ */
434
+ export function decodeWithdrawExpireUnfreezeContract ( base64 : string ) : any [ ] {
435
+ let withdrawContract ;
436
+ try {
437
+ withdrawContract = protocol . WithdrawBalanceContract . decode ( Buffer . from ( base64 , 'base64' ) ) . toJSON ( ) ;
438
+ } catch ( e ) {
439
+ throw new UtilsError ( 'There was an error decoding the withdraw contract in the transaction.' ) ;
440
+ }
441
+
442
+ if ( ! withdrawContract . ownerAddress ) {
443
+ throw new UtilsError ( 'Owner address does not exist in this withdraw contract.' ) ;
444
+ }
445
+
446
+ // deserialize attributes
447
+ const owner_address = getBase58AddressFromByteArray (
448
+ getByteArrayFromHexAddress ( Buffer . from ( withdrawContract . ownerAddress , 'base64' ) . toString ( 'hex' ) )
449
+ ) ;
450
+
451
+ return [
452
+ {
453
+ parameter : {
454
+ value : {
455
+ owner_address,
456
+ } ,
457
+ } ,
458
+ } ,
459
+ ] ;
460
+ }
461
+
363
462
/**
364
463
* @param raw
365
464
*/
0 commit comments