@@ -271,7 +271,7 @@ export class StakingWallet implements IStakingWallet {
271271 // default to verifying a transaction unless explicitly skipped
272272 const skipVerification = signOptions . transactionVerificationOptions ?. skipTransactionVerification ?? false ;
273273 if ( ! isStakingTxRequestPrebuildResult ( builtTx . result ) && ! skipVerification ) {
274- await this . validateBuiltStakingTransaction ( transaction , builtTx ) ;
274+ await this . validateBuiltStakingTransaction ( builtTx . transaction , builtTx ) ;
275275 }
276276 return await this . sign ( signOptions , builtTx ) ;
277277 }
@@ -372,7 +372,7 @@ export class StakingWallet implements IStakingWallet {
372372
373373 const explainedTransaction = await coin . explainTransaction ( result ) ;
374374
375- if ( buildParams ?. recipients ) {
375+ if ( buildParams ?. recipients && buildParams . recipients . length > 0 ) {
376376 const userRecipientMap = new Map (
377377 buildParams . recipients . map ( ( recipient ) => [ recipient . address . toLowerCase ( ) , recipient ] )
378378 ) ;
@@ -382,41 +382,38 @@ export class StakingWallet implements IStakingWallet {
382382
383383 const mismatchErrors : string [ ] = [ ] ;
384384
385- for ( const [ recipientAddress , recipientInfo ] of platformRecipientMap ) {
386- if ( userRecipientMap . has ( recipientAddress ) ) {
387- const userRecipient = userRecipientMap . get ( recipientAddress ) ;
388- if ( ! userRecipient ) {
389- console . error ( 'Unable to determine recipient address' ) ;
390- return ;
391- }
392- const matchResult = transactionRecipientsMatch ( userRecipient , recipientInfo ) ;
393- if ( ! matchResult . exactMatch ) {
394- if ( ! matchResult . tokenMatch ) {
395- mismatchErrors . push (
396- `Invalid token ${ recipientInfo . tokenName } transfer with amount ${ recipientInfo . amount } to ${ recipientInfo . address } found in built transaction, specified ${ userRecipient . tokenName } `
397- ) ;
398- }
399- if ( ! matchResult . amountMatch ) {
400- mismatchErrors . push (
401- `Invalid recipient amount for ${ recipientInfo . address } , specified ${ userRecipient . amount } got ${ recipientInfo . amount } `
402- ) ;
403- }
404- }
405- } else {
406- mismatchErrors . push ( `Invalid recipient address: ${ recipientAddress } ` ) ;
385+ for ( const [ address ] of platformRecipientMap ) {
386+ if ( ! userRecipientMap . has ( address ) ) {
387+ mismatchErrors . push ( `Unexpected recipient address found in built transaction: ${ address } ` ) ;
407388 }
408389 }
409390
410- const missingRecipientAddresses = Array . from ( userRecipientMap . keys ( ) ) . filter (
411- ( address ) => ! platformRecipientMap . has ( address )
412- ) ;
391+ for ( const [ address , userRecipient ] of userRecipientMap ) {
392+ const platformRecipient = platformRecipientMap . get ( address ) ;
393+ if ( ! platformRecipient ) {
394+ mismatchErrors . push ( `Expected recipient address not found in built transaction: ${ address } ` ) ;
395+ continue ;
396+ }
397+
398+ const matchResult = transactionRecipientsMatch ( userRecipient , platformRecipient ) ;
413399
414- if ( missingRecipientAddresses . length > 0 ) {
415- mismatchErrors . push ( `Missing recipient address(es): ${ missingRecipientAddresses . join ( ', ' ) } ` ) ;
400+ if ( ! matchResult . amountMatch ) {
401+ mismatchErrors . push (
402+ `Recipient ${ address } amount mismatch. Expected: ${ userRecipient . amount } , Got: ${ platformRecipient . amount } `
403+ ) ;
404+ }
405+ if ( ! matchResult . tokenMatch ) {
406+ mismatchErrors . push (
407+ `Recipient ${ address } token mismatch. Expected: ${ userRecipient . tokenName ?? 'native coin' } , Got: ${
408+ platformRecipient . tokenName ?? 'native coin'
409+ } `
410+ ) ;
411+ }
416412 }
417413 if ( mismatchErrors . length > 0 ) {
418- console . error ( mismatchErrors . join ( ', ' ) ) ;
419- return ;
414+ const errorMessage = `Staking transaction validation failed before signing: ${ mismatchErrors . join ( '; ' ) } ` ;
415+ debug ( errorMessage ) ;
416+ throw new Error ( errorMessage ) ;
420417 }
421418 } else {
422419 debug ( `Cannot validate staking transaction ${ transaction . stakingRequestId } without specified build params` ) ;
0 commit comments