-
Notifications
You must be signed in to change notification settings - Fork 34
/
wrapper.go
45 lines (37 loc) · 1011 Bytes
/
wrapper.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
package txs
import (
"github.com/spf13/pflag"
"github.com/CyberMiles/travis/sdk"
)
var (
// Middleware must be set in main.go to defined the wrappers we should apply
Middleware Wrapper
)
// Wrapper defines the information needed for each middleware package that
// wraps the data. They should read all configuration out of bounds via viper.
type Wrapper interface {
Wrap(sdk.Tx) (sdk.Tx, error)
Register(*pflag.FlagSet)
}
// Wrappers combines a list of wrapper middlewares.
// The first one is the inner-most layer, eg. Fee, Nonce, Chain, Auth
type Wrappers []Wrapper
var _ Wrapper = Wrappers{}
// Wrap applies the wrappers to the passed in tx in order,
// aborting on the first error
func (ws Wrappers) Wrap(tx sdk.Tx) (sdk.Tx, error) {
var err error
for _, w := range ws {
tx, err = w.Wrap(tx)
if err != nil {
break
}
}
return tx, err
}
// Register adds any needed flags to the command
func (ws Wrappers) Register(fs *pflag.FlagSet) {
for _, w := range ws {
w.Register(fs)
}
}