-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.go
60 lines (51 loc) · 1.41 KB
/
config.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
package relay
import (
"encoding/hex"
"fmt"
"strings"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
lcptypes "github.com/datachainlab/lcp/go/light-clients/lcp/types"
"github.com/hyperledger-labs/yui-relayer/core"
)
var _ core.ProverConfigI = (*ProverConfig)(nil)
var _ codectypes.UnpackInterfacesMessage = (*ProverConfig)(nil)
func (cfg *ProverConfig) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if cfg == nil {
return nil
}
if err := unpacker.UnpackAny(cfg.OriginProver, new(core.ProverConfigI)); err != nil {
return err
}
return nil
}
func (pc ProverConfig) Build(chain core.ChainI) (core.ProverI, error) {
if err := pc.Validate(); err != nil {
return nil, err
}
prover, err := pc.OriginProver.GetCachedValue().(core.ProverConfigI).Build(chain)
if err != nil {
return nil, err
}
return NewProver(pc, chain, prover)
}
func (pc ProverConfig) GetMrenclave() []byte {
mrenclave, err := decodeMrenclaveHex(pc.Mrenclave)
if err != nil {
panic(err)
}
return mrenclave
}
func (pc ProverConfig) Validate() error {
mrenclave, err := decodeMrenclaveHex(pc.Mrenclave)
if err != nil {
return err
}
if l := len(mrenclave); l != lcptypes.MrenclaveSize {
return fmt.Errorf("MRENCLAVE length must be %v, but got %v", lcptypes.MrenclaveSize, l)
}
return nil
}
func decodeMrenclaveHex(s string) ([]byte, error) {
s = strings.ToLower(strings.TrimPrefix(s, "0x"))
return hex.DecodeString(s)
}