-
Notifications
You must be signed in to change notification settings - Fork 48
/
utils.go
63 lines (49 loc) · 1.3 KB
/
utils.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
package utils
// DONTCOVER
import (
"os"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/desmos-labs/desmos/v6/x/profiles/types"
"github.com/cosmos/cosmos-sdk/codec"
)
// NewChainLinkJSON allows to build a new ChainLinkJSON instance
//
//nolint:interfacer
func NewChainLinkJSON(data types.AddressData, proof types.Proof, chainConfig types.ChainConfig) ChainLinkJSON {
any, err := codectypes.NewAnyWithValue(data)
if err != nil {
panic(err)
}
return ChainLinkJSON{
Address: any,
Proof: proof,
ChainConfig: chainConfig,
}
}
// UnpackInterfaces implements codectypes.UnpackInterfacesMessage
func (link *ChainLinkJSON) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if link.Address != nil {
var address types.AddressData
err := unpacker.UnpackAny(link.Address, &address)
if err != nil {
return err
}
}
err := link.Proof.UnpackInterfaces(unpacker)
if err != nil {
return err
}
return nil
}
// ParseChainLinkJSON reads and parses a ChainLinkJSON from file.
func ParseChainLinkJSON(cdc codec.Codec, dataFile string) (ChainLinkJSON, error) {
var data ChainLinkJSON
contents, err := os.ReadFile(dataFile)
if err != nil {
return data, err
}
if err := cdc.UnmarshalJSON(contents, &data); err != nil {
return data, err
}
return data, nil
}