/
proof.go
49 lines (42 loc) · 995 Bytes
/
proof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package merkle
import (
"encoding/json"
"github.com/SouthbankSoftware/provendb-sdk-go/anchor"
)
type Proof interface {
// Metadata provides information about the anchoring.
Metadata() map[string]interface{}
// Data is the actual receipt.
Data() interface{}
}
type proof struct {
Meta map[string]interface{} `json:"metadata"`
Raw interface{} `json:"data"`
}
func (p *proof) Metadata() map[string]interface{} {
return p.Meta
}
func (p *proof) Data() interface{} {
return p.Data
}
func FromAnchorProof(p *anchor.Proof) Proof {
x := &proof{}
if p.Batch != nil {
if p.Batch.Data != "" {
// This data is JSON string. Unmarshall to json.
var meta map[string]interface{}
if err := json.Unmarshal([]byte(p.Batch.Data), &meta); err != nil {
panic("failed to unmarshal anchor proof batch data")
}
x.Meta = meta
}
}
if p.Data != "" {
raw, err := anchor.DecodeProof(p.Data)
if err != nil {
panic("invalid data")
}
x.Raw = raw
}
return x
}