Skip to content

Commit e36727b

Browse files
committed
Fix roundtrip of SystemStartResult with custom marshallers
1 parent 2706a03 commit e36727b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

protocol/localstatequery/queries.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package localstatequery
1616

1717
import (
18+
"encoding/json"
1819
"fmt"
1920
"math/big"
2021

@@ -426,6 +427,33 @@ func (s SystemStartResult) String() string {
426427
return fmt.Sprintf("SystemStart %s %d %s", s.Year.String(), s.Day, s.Picoseconds.String())
427428
}
428429

430+
func (s SystemStartResult) MarshalJSON() ([]byte, error) {
431+
return json.Marshal(struct {
432+
Year string
433+
Day int
434+
Picoseconds string
435+
}{
436+
Year: s.Year.String(),
437+
Day: s.Day,
438+
Picoseconds: s.Picoseconds.String(),
439+
})
440+
}
441+
442+
func (s *SystemStartResult) UnmarshalJSON(data []byte) error {
443+
var tmp struct {
444+
Year string
445+
Day int
446+
Picoseconds string
447+
}
448+
if err := json.Unmarshal(data, &tmp); err != nil {
449+
return err
450+
}
451+
s.Year.SetString(tmp.Year, 10)
452+
s.Day = tmp.Day
453+
s.Picoseconds.SetString(tmp.Picoseconds, 10)
454+
return nil
455+
}
456+
429457
type ChainBlockNoQuery struct {
430458
simpleQueryBase
431459
}

0 commit comments

Comments
 (0)