Skip to content

Commit

Permalink
js-v1: fix handling of null stake when parsing account info (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 authored Oct 11, 2024
1 parent 001387d commit 669ed92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions web3js-1.0/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ export async function getStakeActivation(
})(),
]);

const { effective, activating, deactivating } =
const { effective, activating, deactivating } = stakeAccount.stake ?
getStakeActivatingAndDeactivating(
stakeAccount.stake.delegation,
BigInt(epochInfo.epoch),
stakeHistory
);
) : {
effective: BigInt(0),
activating: BigInt(0),
deactivating: BigInt(0),
};

let status;
if (deactivating > 0) {
Expand Down
6 changes: 3 additions & 3 deletions web3js-1.0/src/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type StakeAccount = {
stake: {
delegation: Delegation,
creditsObserved: bigint
}
} | null
}

export const getStakeHistory = function (parsedData: RpcResponseAndContext<AccountInfo<ParsedAccountData | Buffer> | null>): StakeHistoryEntry[] {
Expand Down Expand Up @@ -77,14 +77,14 @@ export const getStakeAccount = function (parsedData: RpcResponseAndContext<Accou
custodian: parsedData.value.data.parsed.info.meta.lockup.custodian
}
},
stake: {
stake: parsedData.value.data.parsed.info.stake ? {
delegation: {
voterPubkey: parsedData.value.data.parsed.info.stake.delegation.voterPubkey,
stake: BigInt(parsedData.value.data.parsed.info.stake.delegation.stake),
activationEpoch: BigInt(parsedData.value.data.parsed.info.stake.delegation.activationEpoch),
deactivationEpoch: BigInt(parsedData.value.data.parsed.info.stake.delegation.deactivationEpoch),
},
creditsObserved: BigInt(parsedData.value.data.parsed.info.stake.creditsObserved)
}
} : null
}
}

0 comments on commit 669ed92

Please sign in to comment.