Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type of nonce in account #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/auto-consensus/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { Api } from '@autonomys/auto-utils'
import type { AccountData, RawAccountData } from './types/account'
import { parseBalance } from './utils'
import { parseBalance, parseBN } from './utils'

export const account = async (api: Api, address: string): Promise<AccountData> => {
try {
Expand All @@ -11,7 +11,7 @@ export const account = async (api: Api, address: string): Promise<AccountData> =
const { nonce, data } = rawAccount.toPrimitive() as unknown as RawAccountData

return {
nonce,
nonce: parseBN(nonce),
data: parseBalance(data),
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/auto-consensus/src/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export type RawAccountData = {
}

export type AccountData = {
nonce: BN
nonce: bigint
data: BalanceData
}
12 changes: 7 additions & 5 deletions packages/auto-consensus/src/utils/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnyTuple, Codec, StorageKey } from '@autonomys/auto-utils'
import type { AnyTuple, BN, Codec, StorageKey } from '@autonomys/auto-utils'
import type { BalanceData, RawBalanceData } from '../types/balance'
import { DomainRegistry } from '../types/domain'
import {
Expand All @@ -15,13 +15,15 @@ import {
Withdrawal,
} from '../types/staking'

export const parseBN = (value: BN): bigint => BigInt(value.toString())

export const parseBalance = (data: RawBalanceData): BalanceData => {
try {
return {
free: BigInt(data.free.toString()),
reserved: BigInt(data.reserved.toString()),
frozen: BigInt(data.frozen.toString()),
flags: BigInt(data.flags.toString()),
free: parseBN(data.free),
reserved: parseBN(data.reserved),
frozen: parseBN(data.frozen),
flags: parseBN(data.flags),
}
} catch (error) {
console.error('Error parsing balance:', error)
Expand Down
Loading