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: fix handling of null stake when parsing account info #8

Merged
merged 1 commit into from
Oct 11, 2024
Merged
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
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),
};
Comment on lines +36 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than zeroing these, I prefer to keep this code consistent with the web3.js v2 version which only looks at the discriminant. Unfortunately, the discriminant is incorrect in the web3.js v1 version, so we can go with this for now


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
}
}