Skip to content

Commit

Permalink
fix: get balance for new accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch18 authored and jairajdev committed May 10, 2024
1 parent 3d06c61 commit 8b883fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,9 +1063,8 @@ export const methods = {
countSuccessResponse(api_name, 'success', 'validator')
} else {
if (verbose) console.log('Shardeum balance', typeof account.balance, account.balance)
const SHD = intStringToHex(account.balance)
if (verbose) console.log('SHD', typeof SHD, SHD)
balance = intStringToHex(account.balance)
const balance = intStringToHex(account.balance)
if (verbose) console.log('SHD', typeof balance, balance)
logEventEmitter.emit('fn_end', ticket, { nodeUrl, success: true }, performance.now())
callback(null, balance)
countSuccessResponse(api_name, 'success', 'validator')
Expand Down Expand Up @@ -3632,7 +3631,7 @@ export const methods = {
countFailedResponse(api_name, 'Invalid address')
return
}

if (!isValidAddress(callObj.from)) {
if (verbose) console.log('Invalid params: `from` is not valid address', callObj.from)
callback({ code: -32000, message: 'Invalid params: `from` is not valid address' }, null)
Expand Down
14 changes: 11 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ export async function requestWithRetry(
if (retry <= maxRetry) {
if (verbose) console.log(`(Attempt ${retry}) Node is unable to respond. Trying a new node.`)
await waitRandomSecond()
} else if (route.includes('/account/')) {
// Not able to find account after all retries
// This can happen in the case of accounts that have not been used yet
// or are uninitialized. Return null account to be handled by the caller
return { data: { account: null } }
} else {
if (verbose) console.log('Request was unsuccessful after all retries.')
}
Expand Down Expand Up @@ -1038,9 +1043,12 @@ export async function getTransactionReceipt(hash: string) {
*/

export function getFilterId(): string {
return '0x' + createHash('sha256')
.update(randomBytes(16).toString('hex') + Date.now())
.digest('hex')
return (
'0x' +
createHash('sha256')
.update(randomBytes(16).toString('hex') + Date.now())
.digest('hex')
)
}

export function parseFilterDetails(filter: Filter): { address: string; topics: string[] } {
Expand Down

0 comments on commit 8b883fe

Please sign in to comment.