Skip to content

Commit b1d22f9

Browse files
committed
fix(api): Manabar.CurrentMana use json.RawMessage for string/number ambiguity
current_mana is a share_type that the chain serializes inconsistently: sometimes as a JSON string ("5640467421072"), sometimes as a number (0). Using string caused unmarshal failures for accounts with numeric manabar values. Switch to json.RawMessage (same pattern as reputation/withdrawn).
1 parent a2cad55 commit b1d22f9

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

protocol/api/accounts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ type Authority struct {
105105
// current_mana is a share_type (int64) and serializes as a JSON string because
106106
// it can be large; last_update_time is a unix-epoch uint32 emitted as a number.
107107
type Manabar struct {
108-
CurrentMana string `json:"current_mana"`
109-
LastUpdateTime uint32 `json:"last_update_time"`
108+
CurrentMana json.RawMessage `json:"current_mana"`
109+
LastUpdateTime uint32 `json:"last_update_time"`
110110
}
111111

112112
// ExtendedAccount models a full condenser_api.get_accounts response entry,

protocol/api/accounts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ func TestUnmarshal_ExtendedAccount_FullFixture(t *testing.T) {
238238
t.Errorf("savings_withdraw_requests: got %d", acct.SavingsWithdrawRequests)
239239
}
240240

241-
// --- typed Manabar: current_mana is a string, last_update_time a number ---
242-
if acct.VotingManabar.CurrentMana != "5640467421072" {
243-
t.Errorf("voting_manabar.current_mana: got %q", acct.VotingManabar.CurrentMana)
241+
// --- Manabar: current_mana is json.RawMessage (string or number on chain) ---
242+
if string(acct.VotingManabar.CurrentMana) != `"5640467421072"` {
243+
t.Errorf("voting_manabar.current_mana: got %s", acct.VotingManabar.CurrentMana)
244244
}
245245
if acct.VotingManabar.LastUpdateTime != 1699768485 {
246246
t.Errorf("voting_manabar.last_update_time: got %d", acct.VotingManabar.LastUpdateTime)

0 commit comments

Comments
 (0)