-
Notifications
You must be signed in to change notification settings - Fork 2
/
header.go
74 lines (60 loc) · 1.61 KB
/
header.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
package header
import (
avail "github.com/availproject/avail-go-sdk/src/sdk/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)
type DataLookupIndexItem struct {
AppId avail.UCompact `json:"appId"`
Start avail.UCompact `json:"start"`
}
type DataLookup struct {
Size avail.UCompact `json:"size"`
Index []DataLookupIndexItem `json:"index"`
}
type KateCommitment struct {
Rows avail.UCompact `json:"rows"`
Cols avail.UCompact `json:"cols"`
Commitment []types.U8 `json:"commitment"`
DataRoot types.Hash `json:"dataRoot"`
}
type V3HeaderExtension struct {
AppLookup DataLookup `json:"appLookup"`
Commitment KateCommitment `json:"commitment"`
}
type HeaderExtensionEnum struct {
V3 V3HeaderExtension `json:"V3"`
}
type Header struct {
ParentHash types.Hash `json:"parentHash"`
Number types.BlockNumber `json:"number"`
StateRoot types.Hash `json:"stateRoot"`
ExtrinsicsRoot types.Hash `json:"extrinsicsRoot"`
Digest types.Digest `json:"digest"`
Extension HeaderExtensionEnum `json:"extension"`
}
func (m HeaderExtensionEnum) Encode(encoder scale.Encoder) error {
var err, err1 error
err = encoder.PushByte(2)
if err != nil {
return err
}
err1 = encoder.Encode(m.V3)
if err1 != nil {
return err1
}
return nil
}
func (m *HeaderExtensionEnum) Decode(decoder scale.Decoder) error {
b, err := decoder.ReadOneByte()
if err != nil {
return err
}
if b == 2 {
err = decoder.Decode(&m.V3)
}
if err != nil {
return err
}
return nil
}