@@ -151,8 +151,8 @@ export class Transaction extends BaseTransaction {
151151 tip : decodedTx . tip ? Number ( decodedTx . tip ) : 0 ,
152152 } ;
153153
154+ const txMethod = decodedTx . method . args ;
154155 if ( this . type === TransactionType . Send ) {
155- const txMethod = decodedTx . method . args ;
156156 if ( utils . isTransfer ( txMethod ) ) {
157157 const keypairDest = new KeyPair ( {
158158 pub : Buffer . from ( decodeAddress ( txMethod . dest . id ) ) . toString ( 'hex' ) ,
@@ -168,6 +168,26 @@ export class Transaction extends BaseTransaction {
168168 } else {
169169 throw new ParseTransactionError ( `Serializing unknown Transfer type parameters` ) ;
170170 }
171+ } else if ( this . type === TransactionType . StakingActivate ) {
172+ if ( utils . isAddStake ( txMethod ) ) {
173+ const keypairDest = new KeyPair ( {
174+ pub : Buffer . from ( decodeAddress ( txMethod . hotkey ) ) . toString ( 'hex' ) ,
175+ } ) ;
176+ // hotkey address of validator
177+ result . to = keypairDest . getAddress ( this . getAddressFormat ( ) ) ;
178+ result . amount = txMethod . amountStaked . toString ( ) ;
179+ result . netuid = txMethod . netuid ;
180+ }
181+ } else if ( this . type === TransactionType . StakingDeactivate ) {
182+ if ( utils . isRemoveStake ( txMethod ) ) {
183+ const keypairDest = new KeyPair ( {
184+ pub : Buffer . from ( decodeAddress ( txMethod . hotkey ) ) . toString ( 'hex' ) ,
185+ } ) ;
186+ // hotkey address of validator
187+ result . to = keypairDest . getAddress ( this . getAddressFormat ( ) ) ;
188+ result . amount = txMethod . amountUnstaked . toString ( ) ;
189+ result . netuid = txMethod . netuid ;
190+ }
171191 }
172192
173193 return result ;
@@ -185,6 +205,30 @@ export class Transaction extends BaseTransaction {
185205 } ;
186206 }
187207
208+ explainStakeTransaction ( json : TxData , explanationResult : TransactionExplanation ) : TransactionExplanation {
209+ return {
210+ ...explanationResult ,
211+ outputs : [
212+ {
213+ address : json . to ?. toString ( ) || '' ,
214+ amount : json . amount ?. toString ( ) || '' ,
215+ } ,
216+ ] ,
217+ } ;
218+ }
219+
220+ explainUnstakeTransaction ( json : TxData , explanationResult : TransactionExplanation ) : TransactionExplanation {
221+ return {
222+ ...explanationResult ,
223+ outputs : [
224+ {
225+ address : json . sender . toString ( ) || '' ,
226+ amount : json . amount ?. toString ( ) || '' ,
227+ } ,
228+ ] ,
229+ } ;
230+ }
231+
188232 /** @inheritdoc */
189233 explainTransaction ( ) : TransactionExplanation {
190234 const result = this . toJson ( ) ;
@@ -205,6 +249,10 @@ export class Transaction extends BaseTransaction {
205249 switch ( this . type ) {
206250 case TransactionType . Send :
207251 return this . explainTransferTransaction ( result , explanationResult ) ;
252+ case TransactionType . StakingActivate :
253+ return this . explainStakeTransaction ( result , explanationResult ) ;
254+ case TransactionType . StakingDeactivate :
255+ return this . explainUnstakeTransaction ( result , explanationResult ) ;
208256 default :
209257 throw new InvalidTransactionError ( 'Transaction type not supported' ) ;
210258 }
@@ -225,6 +273,10 @@ export class Transaction extends BaseTransaction {
225273
226274 if ( this . type === TransactionType . Send ) {
227275 this . decodeInputsAndOutputsForSend ( decodedTx ) ;
276+ } else if ( this . type === TransactionType . StakingActivate ) {
277+ this . decodeInputsAndOutputsForStakingActivate ( decodedTx ) ;
278+ } else if ( this . type === TransactionType . StakingDeactivate ) {
279+ this . decodeInputsAndOutputsForStakingDeactivate ( decodedTx ) ;
228280 }
229281 }
230282
@@ -267,6 +319,70 @@ export class Transaction extends BaseTransaction {
267319 ] ;
268320 }
269321
322+ private decodeInputsAndOutputsForStakingActivate ( decodedTx : DecodedTx ) {
323+ const txMethod = decodedTx . method . args ;
324+ let to : string ;
325+ let value : string ;
326+ let from : string ;
327+ if ( utils . isAddStake ( txMethod ) ) {
328+ const keypairDest = new KeyPair ( {
329+ pub : Buffer . from ( decodeAddress ( txMethod . hotkey ) ) . toString ( 'hex' ) ,
330+ } ) ;
331+ to = keypairDest . getAddress ( this . getAddressFormat ( ) ) ;
332+ value = txMethod . amountStaked . toString ( ) ;
333+ from = decodedTx . address ;
334+ } else {
335+ throw new ParseTransactionError ( `Loading inputs of unknown StakingActivate type parameters` ) ;
336+ }
337+ this . _outputs = [
338+ {
339+ address : to ,
340+ value,
341+ coin : this . _coinConfig . name ,
342+ } ,
343+ ] ;
344+
345+ this . _inputs = [
346+ {
347+ address : from ,
348+ value,
349+ coin : this . _coinConfig . name ,
350+ } ,
351+ ] ;
352+ }
353+
354+ private decodeInputsAndOutputsForStakingDeactivate ( decodedTx : DecodedTx ) {
355+ const txMethod = decodedTx . method . args ;
356+ let to : string ;
357+ let value : string ;
358+ let from : string ;
359+ if ( utils . isRemoveStake ( txMethod ) ) {
360+ const keypairDest = new KeyPair ( {
361+ pub : Buffer . from ( decodeAddress ( txMethod . hotkey ) ) . toString ( 'hex' ) ,
362+ } ) ;
363+ to = keypairDest . getAddress ( this . getAddressFormat ( ) ) ;
364+ value = txMethod . amountUnstaked . toString ( ) ;
365+ from = decodedTx . address ;
366+ } else {
367+ throw new ParseTransactionError ( `Loading inputs of unknown StakingDeactivate type parameters` ) ;
368+ }
369+ this . _outputs = [
370+ {
371+ address : from ,
372+ value,
373+ coin : this . _coinConfig . name ,
374+ } ,
375+ ] ;
376+
377+ this . _inputs = [
378+ {
379+ address : to ,
380+ value,
381+ coin : this . _coinConfig . name ,
382+ } ,
383+ ] ;
384+ }
385+
270386 /**
271387 * Constructs a signed payload using construct.signTx
272388 * This method will be called during the build step if a TSS signature
0 commit comments