Skip to content

Commit

Permalink
switch to marshalling whole type
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolin committed Nov 13, 2024
1 parent 5ead38d commit 90741ea
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions blob/commitment_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blob

import (
"bytes"
"encoding/json"
"errors"
"fmt"

Expand Down Expand Up @@ -157,39 +156,17 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold
}

// MarshalJSON marshals an CommitmentProof to JSON. Uses tendermint encoder for row proof for compatibility.
func (commitmentProof *CommitmentProof) MarshalJSON() ([]byte, error) {
func (c *CommitmentProof) MarshalJSON() ([]byte, error) {
// alias the type to avoid going into recursion loop
// because tmjson.Marshal invokes custom json Marshalling
type Alias CommitmentProof
rowProof, err := tmjson.Marshal(commitmentProof.RowProof)
if err != nil {
return nil, err
}
return json.Marshal(&struct {
RowProof json.RawMessage `json:"row_proof"`
*Alias
}{
RowProof: rowProof,
Alias: (*Alias)(commitmentProof),
})
return tmjson.Marshal((*Alias)(c))
}

// UnmarshalJSON unmarshals an CommitmentProof from JSON. Uses tendermint decoder for row proof for compatibility.
func (commitmentProof *CommitmentProof) UnmarshalJSON(data []byte) error {
func (c *CommitmentProof) UnmarshalJSON(data []byte) error {
// alias the type to avoid going into recursion loop
// because tmjson.Unmarshal invokes custom json Unmarshalling
type Alias CommitmentProof
aux := &struct {
RowProof json.RawMessage `json:"row_proof"`
*Alias
}{
Alias: (*Alias)(commitmentProof),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
rowProof := proof.RowProof{}
if err := tmjson.Unmarshal(aux.RowProof, &rowProof); err != nil {
return err
}

commitmentProof.RowProof = rowProof

return nil
return tmjson.Unmarshal(data, (*Alias)(c))
}

0 comments on commit 90741ea

Please sign in to comment.