-
Notifications
You must be signed in to change notification settings - Fork 182
/
execution_dds_payload.go
82 lines (69 loc) · 1.71 KB
/
execution_dds_payload.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
80
81
82
package state
import (
"fmt"
"github.com/okex/exchain/libs/iavl"
"github.com/okex/exchain/libs/tendermint/types"
)
func unmarshalTreeDeltaMap(input []byte) (interface{}, error) {
if len(input) == 0 {
return nil, fmt.Errorf("failed unmarshal TreeDeltaMap: empty data")
}
treeDeltaMap := iavl.TreeDeltaMap{}
err := treeDeltaMap.UnmarshalFromAmino(nil, input)
return treeDeltaMap, err
}
func marshalTreeDeltaMap(deltaMap interface{}) ([]byte, error) {
dm, ok := deltaMap.(iavl.TreeDeltaMap)
if !ok {
return nil, fmt.Errorf("failed marshal TreeDeltaMap")
}
return dm.MarshalToAmino(nil)
}
type DeltaInfo struct {
from string
deltaLen int
deltaHeight int64
abciResponses *ABCIResponses
treeDeltaMap interface{}
watchData interface{}
marshalWatchData func() ([]byte, error)
}
// for upload
func (info *DeltaInfo) dataInfo2Bytes() (types.DeltaPayload, error) {
var err error
pl := types.DeltaPayload{}
pl.ABCIRsp, err = info.abciResponses.MarshalToAmino(cdc)
if err != nil {
return pl, err
}
pl.DeltasBytes, err = marshalTreeDeltaMap(info.treeDeltaMap)
if err != nil {
return pl, err
}
pl.WatchBytes, err = info.marshalWatchData()
if err != nil {
return pl, err
}
return pl, err
}
func (info *DeltaInfo) bytes2DeltaInfo(pl *types.DeltaPayload) error {
if pl == nil {
return fmt.Errorf("Failed bytes to delta info: empty delta payload. ")
}
var err error
ar := &ABCIResponses{}
err = ar.UnmarshalFromAmino(nil, pl.ABCIRsp)
if err != nil {
return err
}
info.abciResponses = ar
info.treeDeltaMap, err = unmarshalTreeDeltaMap(pl.DeltasBytes)
if err != nil {
return err
}
info.watchData, err = unmarshalWatchData(pl.WatchBytes)
if err != nil {
return err
}
return err
}