Skip to content

fix: 🐛 resolve RewardDestination from its camel-cased toJSON key - #350

Merged
polymesh-bot merged 1 commit into
redesign/04-polyx-ledgerfrom
fix/staking-reward-destination-casing
Sep 9, 2026
Merged

fix: 🐛 resolve RewardDestination from its camel-cased toJSON key#350
polymesh-bot merged 1 commit into
redesign/04-polyx-ledgerfrom
fix/staking-reward-destination-casing

Conversation

@F-OBrien

@F-OBrien F-OBrien commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Found while reviewing #349.

Enum#toJSON() camel-cases the variant name (stringCamelCase(this.type) in @polkadot/types-codec), but getRewardDestinationDetails compared the key against 'Account'. So an 8.x Rewarded with an explicit Account payee arrived as { account: "5..." }, the branch never fired, and the row was stored as rewardDestination: 'account' with rewardDestinationAccount undefined. Every object form was affected — { staked: null } stored 'staked' and resolved no account either.

The parse now lives once in utils/staking.ts, shared with the pre-v8 staking.payee read that had it right. Along the way:

  • takes AnyJson and narrows, instead of casting toJSON() to string | Record<string, unknown> | null
  • rewardDestination is a union of the variant names, not string
  • .toJSON() stays in place of the generated Option<PalletStakingRewardDestination> accessors, and the reason is recorded at the helper: the generated types describe the current metadata only, while both callers read older runtimes, so .unwrap() would throw into a catch on a block where the entry decodes as a bare RewardDestination

Tests cover { account }, { staked: null } and the bare-string form on the 8.x path; the object-form cases fail without the fix.

@F-OBrien
F-OBrien requested a review from a team as a code owner September 9, 2026 17:05
@F-OBrien
F-OBrien force-pushed the fix/staking-reward-destination-casing branch from 9c9ba22 to 828a7d1 Compare September 9, 2026 17:11
@F-OBrien F-OBrien changed the title fix: 🐛 match the camel-cased RewardDestination key toJSON emits fix: 🐛 resolve RewardDestination from its camel-cased toJSON key Sep 9, 2026
@F-OBrien
F-OBrien changed the base branch from redesign/03-infrastructure to redesign/04-polyx-ledger September 9, 2026 17:11
`Enum#toJSON()` camel-cases the variant name, so an 8.x `Rewarded` with an
`Account` payee arrives as `{ account: "5..." }` and never matched the
`'Account'` comparison: the row stored `rewardDestination: 'account'` with no
destination account. Every object form was affected, `{ staked: null }`
included, so no destination account was resolved for any of them.

The parse now lives once in `utils/staking.ts`, shared with the pre-v8
`staking.payee` read. It takes `AnyJson` and narrows rather than casting
`toJSON()` to a hand-written shape, and `rewardDestination` is a union of the
variant names instead of `string`.

`.toJSON()` stays in place of the generated `Option<PalletStakingRewardDestination>`
accessors: those describe the current metadata only, while both callers read
older runtimes, and the reason is now recorded at the helper.
@prashantasdeveloper
prashantasdeveloper force-pushed the fix/staking-reward-destination-casing branch from 828a7d1 to e27ebd8 Compare September 9, 2026 19:21
@sonarqubecloud

sonarqubecloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

@prashantasdeveloper

Copy link
Copy Markdown
Contributor

/fast-forward

@polymesh-bot
polymesh-bot merged commit e27ebd8 into redesign/04-polyx-ledger Sep 9, 2026
8 checks passed
@polymesh-bot
polymesh-bot deleted the fix/staking-reward-destination-casing branch September 9, 2026 19:23
prashantasdeveloper added a commit that referenced this pull request Sep 10, 2026
…was right

CHANGES.md, entity-review.md and 02-polyx-ledger.md each asserted [V] that
get8xStakingEventDetails resolved the RewardDestination correctly. PR #350 showed
it did not - the object form never matched. Corrected in the repo's usual style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants