-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.go
71 lines (60 loc) · 1.68 KB
/
factory.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
package mcms
import (
"fmt"
cselectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/mcms/sdk"
"github.com/smartcontractkit/mcms/sdk/evm"
"github.com/smartcontractkit/mcms/sdk/solana"
"github.com/smartcontractkit/mcms/types"
)
// newEncoder returns a new Encoder that can encode operations and metadata for the given chain.
// Additional arguments are used to configure the encoder.
func newEncoder(
csel types.ChainSelector, txCount uint64, overridePreviousRoot bool, isSim bool,
) (sdk.Encoder, error) {
family, err := types.GetChainSelectorFamily(csel)
if err != nil {
return nil, err
}
var encoder sdk.Encoder
switch family {
case cselectors.FamilyEVM:
encoder = evm.NewEncoder(
csel,
txCount,
overridePreviousRoot,
isSim,
)
case cselectors.FamilySolana:
encoder = solana.NewEncoder(
csel,
txCount,
overridePreviousRoot,
// isSim,
)
}
return encoder, nil
}
// newTimelockConverterFromExecutor returns a new TimelockConverter that can convert timelock proposals
// for the given chain.
func newTimelockConverterFromExecutor(
csel types.ChainSelector,
executor sdk.TimelockExecutor,
) (sdk.TimelockConverter, error) {
family, err := types.GetChainSelectorFamily(csel)
if err != nil {
return nil, err
}
switch family {
case cselectors.FamilyEVM:
return &evm.TimelockConverter{}, nil
case cselectors.FamilySolana:
solanaExecutor, ok := executor.(*solana.TimelockExecutor)
if !ok {
return nil, fmt.Errorf("unable to cast sdk executor to solana TimelockExecutor")
}
return solana.NewTimelockConverter(solanaExecutor.Client()), nil
default:
return nil, fmt.Errorf("unsupported executor type: %T", executor)
}
}