-
Notifications
You must be signed in to change notification settings - Fork 170
/
mmr.go
79 lines (69 loc) · 1.71 KB
/
mmr.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package types
import (
"encoding/json"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
)
// GenerateMMRProofResponse contains the generate proof rpc response
type GenerateMMRProofResponse struct {
BlockHash H256
Leaf MMRLeaf
Proof MMRProof
}
// UnmarshalJSON fills u with the JSON encoded byte array given by b
func (d *GenerateMMRProofResponse) UnmarshalJSON(bz []byte) error {
var tmp struct {
BlockHash string `json:"blockHash"`
Leaf string `json:"leaf"`
Proof string `json:"proof"`
}
if err := json.Unmarshal(bz, &tmp); err != nil {
return err
}
err := codec.DecodeFromHex(tmp.BlockHash, &d.BlockHash)
if err != nil {
return err
}
var encodedLeaf MMREncodableOpaqueLeaf
err = codec.DecodeFromHex(tmp.Leaf, &encodedLeaf)
if err != nil {
return err
}
err = codec.Decode(encodedLeaf, &d.Leaf)
if err != nil {
return err
}
err = codec.DecodeFromHex(tmp.Proof, &d.Proof)
if err != nil {
return err
}
return nil
}
type MMREncodableOpaqueLeaf Bytes
// MMRProof is a MMR proof
type MMRProof struct {
// The index of the leaf the proof is for.
LeafIndex U64
// Number of leaves in MMR, when the proof was generated.
LeafCount U64
// Proof elements (hashes of siblings of inner nodes on the path to the leaf).
Items []H256
}
type MMRLeaf struct {
Version MMRLeafVersion
ParentNumberAndHash ParentNumberAndHash
BeefyNextAuthoritySet BeefyNextAuthoritySet
ParachainHeads H256
}
type MMRLeafVersion U8
type ParentNumberAndHash struct {
ParentNumber U32
Hash Hash
}
type BeefyNextAuthoritySet struct {
// ID
ID U64
// Number of validators in the set.
Len U32
// Merkle Root Hash build from BEEFY uncompressed AuthorityIds.
Root H256
}