-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.go
39 lines (35 loc) · 999 Bytes
/
convert.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
package types
import (
proto "github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
abci "github.com/tendermint/tendermint/abci/types"
)
// Converts an ABCI snapshot to a snapshot. Mainly to decode the SDK metadata.
func SnapshotFromABCI(in *abci.Snapshot) (Snapshot, error) {
snapshot := Snapshot{
Height: in.Height,
Format: in.Format,
Chunks: in.Chunks,
Hash: in.Hash,
}
err := proto.Unmarshal(in.Metadata, &snapshot.Metadata)
if err != nil {
return Snapshot{}, errors.Wrap(err, "failed to unmarshal snapshot metadata")
}
return snapshot, nil
}
// Converts a Snapshot to its ABCI representation. Mainly to encode the SDK metadata.
func (s Snapshot) ToABCI() (abci.Snapshot, error) {
out := abci.Snapshot{
Height: s.Height,
Format: s.Format,
Chunks: s.Chunks,
Hash: s.Hash,
}
var err error
out.Metadata, err = proto.Marshal(&s.Metadata)
if err != nil {
return abci.Snapshot{}, errors.Wrap(err, "failed to marshal snapshot metadata")
}
return out, nil
}