@@ -2,6 +2,7 @@ package blob
2
2
3
3
import (
4
4
"bytes"
5
+ "encoding/json"
5
6
"errors"
6
7
"fmt"
7
8
@@ -11,6 +12,7 @@ import (
11
12
libshare "github.com/celestiaorg/go-square/v2/share"
12
13
"github.com/celestiaorg/nmt"
13
14
"github.com/celestiaorg/nmt/namespace"
15
+ tmjson "github.com/tendermint/tendermint/libs/json"
14
16
)
15
17
16
18
// Commitment is a Merkle Root of the subtree built from shares of the Blob.
@@ -153,3 +155,41 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold
153
155
// verify row roots to data root proof
154
156
return commitmentProof .RowProof .VerifyProof (root ), nil
155
157
}
158
+
159
+ // MarshalJSON marshals an CommitmentProof to JSON. Uses tendermint encoder for row proof for compatibility.
160
+ func (commitmentProof * CommitmentProof ) MarshalJSON () ([]byte , error ) {
161
+ type Alias CommitmentProof
162
+ rowProof , err := tmjson .Marshal (commitmentProof .RowProof )
163
+ if err != nil {
164
+ return nil , err
165
+ }
166
+ return json .Marshal (& struct {
167
+ RowProof json.RawMessage `json:"row_proof"`
168
+ * Alias
169
+ }{
170
+ RowProof : rowProof ,
171
+ Alias : (* Alias )(commitmentProof ),
172
+ })
173
+ }
174
+
175
+ // UnmarshalJSON unmarshals an CommitmentProof from JSON. Uses tendermint decoder for row proof for compatibility.
176
+ func (commitmentProof * CommitmentProof ) UnmarshalJSON (data []byte ) error {
177
+ type Alias CommitmentProof
178
+ aux := & struct {
179
+ RowProof json.RawMessage `json:"row_proof"`
180
+ * Alias
181
+ }{
182
+ Alias : (* Alias )(commitmentProof ),
183
+ }
184
+ if err := json .Unmarshal (data , & aux ); err != nil {
185
+ return err
186
+ }
187
+ rowProof := proof.RowProof {}
188
+ if err := tmjson .Unmarshal (aux .RowProof , rowProof ); err != nil {
189
+ return err
190
+ }
191
+
192
+ commitmentProof .RowProof = rowProof
193
+
194
+ return nil
195
+ }
0 commit comments