@@ -6,19 +6,27 @@ import { VetTransactionData } from '../iface';
66import EthereumAbi from 'ethereumjs-abi' ;
77import utils from '../utils' ;
88import BigNumber from 'bignumber.js' ;
9- import { addHexPrefix } from 'ethereumjs-util' ;
9+ import { addHexPrefix , BN } from 'ethereumjs-util' ;
1010import { ZERO_VALUE_AMOUNT } from '../constants' ;
1111
1212export class DelegateClauseTransaction extends Transaction {
1313 private _stakingContractAddress : string ;
14- private _tokenId : number ;
15- private _delegateForever = true ;
14+ private _tokenId : string ;
15+ private _validator : string ;
1616
1717 constructor ( _coinConfig : Readonly < CoinConfig > ) {
1818 super ( _coinConfig ) ;
1919 this . _type = TransactionType . StakingDelegate ;
2020 }
2121
22+ get validator ( ) : string {
23+ return this . _validator ;
24+ }
25+
26+ set validator ( address : string ) {
27+ this . _validator = address ;
28+ }
29+
2230 get stakingContractAddress ( ) : string {
2331 return this . _stakingContractAddress ;
2432 }
@@ -27,22 +35,14 @@ export class DelegateClauseTransaction extends Transaction {
2735 this . _stakingContractAddress = address ;
2836 }
2937
30- get tokenId ( ) : number {
38+ get tokenId ( ) : string {
3139 return this . _tokenId ;
3240 }
3341
34- set tokenId ( tokenId : number ) {
42+ set tokenId ( tokenId : string ) {
3543 this . _tokenId = tokenId ;
3644 }
3745
38- get delegateForever ( ) : boolean {
39- return this . _delegateForever ;
40- }
41-
42- set delegateForever ( delegateForever : boolean ) {
43- this . _delegateForever = delegateForever ;
44- }
45-
4646 buildClauses ( ) : void {
4747 if ( ! this . stakingContractAddress ) {
4848 throw new Error ( 'Staking contract address is not set' ) ;
@@ -54,7 +54,11 @@ export class DelegateClauseTransaction extends Transaction {
5454 throw new Error ( 'Token ID is not set' ) ;
5555 }
5656
57- const data = this . getDelegateData ( this . tokenId , this . delegateForever ) ;
57+ if ( this . validator === undefined || this . validator === null ) {
58+ throw new Error ( 'Validator address is not set' ) ;
59+ }
60+
61+ const data = this . getDelegateData ( this . tokenId , this . validator ) ;
5862 this . _transactionData = data ;
5963
6064 // Create the clause for delegation
@@ -80,10 +84,10 @@ export class DelegateClauseTransaction extends Transaction {
8084 * @param {number } tokenId - The Token ID for delegation
8185 * @returns {string } - The encoded transaction data
8286 */
83- getDelegateData ( levelId : number , delegateForever = true ) : string {
87+ getDelegateData ( tokenId : string , validatorAddress : string ) : string {
8488 const methodName = 'delegate' ;
85- const types = [ 'uint256' , 'bool ' ] ;
86- const params = [ levelId , delegateForever ] ;
89+ const types = [ 'uint256' , 'address ' ] ;
90+ const params = [ new BN ( tokenId ) , validatorAddress ] ;
8791
8892 const method = EthereumAbi . methodID ( methodName , types ) ;
8993 const args = EthereumAbi . rawEncode ( types , params ) ;
@@ -107,8 +111,8 @@ export class DelegateClauseTransaction extends Transaction {
107111 to : this . stakingContractAddress ,
108112 stakingContractAddress : this . stakingContractAddress ,
109113 amountToStake : ZERO_VALUE_AMOUNT ,
110- nftTokenId : this . tokenId ,
111- autorenew : this . delegateForever ,
114+ tokenId : this . tokenId ,
115+ validatorAddress : this . validator ,
112116 } ;
113117
114118 return json ;
@@ -144,7 +148,7 @@ export class DelegateClauseTransaction extends Transaction {
144148 this . transactionData = clause . data ;
145149 const decoded = utils . decodeDelegateClauseData ( clause . data ) ;
146150 this . tokenId = decoded . tokenId ;
147- this . delegateForever = decoded . delegateForever ;
151+ this . validator = decoded . validator ;
148152 }
149153 }
150154
0 commit comments