Skip to content

Commit

Permalink
fix(header): use tmjson encoding for Commit field as well
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Nov 7, 2024
1 parent 353141f commit 5ebb191
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/docgen/exampledata/extendedHeader.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
},
"commit": {
"height": 67374,
"height": "67374",
"round": 0,
"block_id": {
"hash": "A7F6B1CF33313121539206754A73FDC22ADA48C4AA8C4BB4F707ED2E089E59D3",
Expand Down
12 changes: 12 additions & 0 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,19 @@ func (eh *ExtendedHeader) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
commit, err := tmjson.Marshal(eh.Commit)
if err != nil {
return nil, err
}
return json.Marshal(&struct {
RawHeader json.RawMessage `json:"header"`
ValidatorSet json.RawMessage `json:"validator_set"`
Commit json.RawMessage `json:"commit"`
*Alias
}{
ValidatorSet: validatorSet,
RawHeader: rawHeader,
Commit: commit,
Alias: (*Alias)(eh),
})
}
Expand All @@ -257,6 +263,7 @@ func (eh *ExtendedHeader) UnmarshalJSON(data []byte) error {
aux := &struct {
RawHeader json.RawMessage `json:"header"`
ValidatorSet json.RawMessage `json:"validator_set"`
Commit json.RawMessage `json:"commit"`
*Alias
}{
Alias: (*Alias)(eh),
Expand All @@ -273,9 +280,14 @@ func (eh *ExtendedHeader) UnmarshalJSON(data []byte) error {
if err := tmjson.Unmarshal(aux.RawHeader, rawHeader); err != nil {
return err
}
commit := new(core.Commit)
if err := tmjson.Unmarshal(aux.Commit, commit); err != nil {
return err
}

eh.ValidatorSet = valSet
eh.RawHeader = *rawHeader
eh.Commit = commit
return nil
}

Expand Down

0 comments on commit 5ebb191

Please sign in to comment.