Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replacing jsonProof with pb.Proof #233

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,28 @@ type Proof struct {
isMaxNamespaceIDIgnored bool
}

type jsonProof struct {
Start int `json:"start"`
End int `json:"end"`
Nodes [][]byte `json:"nodes"`
LeafHash []byte `json:"leaf_hash"`
IsMaxNamespaceIDIgnored bool `json:"is_max_namespace_id_ignored"`
}

func (proof Proof) MarshalJSON() ([]byte, error) {
rootulp marked this conversation as resolved.
Show resolved Hide resolved
jsonProofObj := jsonProof{
Start: proof.start,
End: proof.end,
Nodes: proof.nodes,
LeafHash: proof.leafHash,
IsMaxNamespaceIDIgnored: proof.isMaxNamespaceIDIgnored,
pbProofObj := pb.Proof{
Start: int64(proof.start),
End: int64(proof.end),
Nodes: proof.nodes,
LeafHash: proof.leafHash,
IsMaxNamespaceIgnored: proof.isMaxNamespaceIDIgnored,
}
return json.Marshal(jsonProofObj)
return json.Marshal(pbProofObj)
}

func (proof *Proof) UnmarshalJSON(data []byte) error {
var jsonProofObj jsonProof
err := json.Unmarshal(data, &jsonProofObj)
var pbProof pb.Proof
err := json.Unmarshal(data, &pbProof)
if err != nil {
return err
}
proof.start = jsonProofObj.Start
proof.end = jsonProofObj.End
proof.nodes = jsonProofObj.Nodes
proof.leafHash = jsonProofObj.LeafHash
proof.isMaxNamespaceIDIgnored = jsonProofObj.IsMaxNamespaceIDIgnored
proof.start = int(pbProof.Start)
staheri14 marked this conversation as resolved.
Show resolved Hide resolved
proof.end = int(pbProof.End)
proof.nodes = pbProof.Nodes
proof.leafHash = pbProof.LeafHash
proof.isMaxNamespaceIDIgnored = pbProof.IsMaxNamespaceIgnored
return nil
}

Expand Down
Loading