-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.go
52 lines (41 loc) · 1.13 KB
/
strategy.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
package cmd
import (
"fmt"
"strconv"
"github.com/ilgooz/relayer/relayer"
"github.com/spf13/cobra"
)
// GetStrategyWithOptions sets strategy specific fields.
func GetStrategyWithOptions(cmd *cobra.Command, strategy relayer.Strategy) (relayer.Strategy, error) {
switch strategy.GetType() {
case (&relayer.NaiveStrategy{}).GetType():
ns, ok := strategy.(*relayer.NaiveStrategy)
if !ok {
return strategy,
fmt.Errorf("strategy.GetType() returns naive, but strategy type (%T) is not type NaiveStrategy", strategy)
}
maxTxSize, err := cmd.Flags().GetString(flagMaxTxSize)
if err != nil {
return ns, err
}
txSize, err := strconv.ParseUint(maxTxSize, 10, 64)
if err != nil {
return ns, err
}
// set max size of messages in a relay transaction
ns.MaxTxSize = txSize * MB // in MB
maxMsgLength, err := cmd.Flags().GetString(flagMaxMsgLength)
if err != nil {
return ns, err
}
msgLen, err := strconv.ParseUint(maxMsgLength, 10, 64)
if err != nil {
return ns, err
}
// set max length messages in relay transaction
ns.MaxMsgLength = msgLen
return ns, nil
default:
return strategy, nil
}
}