Skip to content

Commit

Permalink
Enhance getDelegationChainLength method with safe integer check and i…
Browse files Browse the repository at this point in the history
…mproved error handling
  • Loading branch information
piotrwitek committed Feb 5, 2025
1 parent 5eefe17 commit e200d27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export interface IArmadaManagerGovernance {
*
* @param user The user
*
* @returns The transaction information
* @returns The length of the delegation chain
*/
getDelegationChainLength: (params: { user: IUser }) => Promise<number>
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ export class ArmadaManagerGovernance implements IArmadaManagerGovernance {
functionName: 'getDelegationChainLength',
args: [params.user.wallet.address.value],
})
return Number(length.toString())
const num = Number(length.toString())
if (!Number.isSafeInteger(num)) {
throw new Error('Delegation chain length exceeds safe integer limits')
}
return num
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ export const getDelegationChainLength = publicProcedure
}),
)
.query(async (opts) => {
return await opts.ctx.armadaManager.governance.getDelegationChainLength(opts.input)
try {
return await opts.ctx.armadaManager.governance.getDelegationChainLength(opts.input)
} catch (error) {
console.error(`Failed to get delegation chain length: ${error}`)
throw new Error(`Failed to get delegation chain length: ${error}`)
}
})

0 comments on commit e200d27

Please sign in to comment.