/
msg.go
42 lines (34 loc) · 1.01 KB
/
msg.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
package validators
import (
fmt "fmt"
"github.com/iov-one/weave"
"github.com/iov-one/weave/errors"
"github.com/iov-one/weave/migration"
abci "github.com/tendermint/tendermint/abci/types"
)
func init() {
migration.MustRegister(1, &ApplyDiffMsg{}, migration.NoModification)
}
var _ weave.Msg = (*ApplyDiffMsg)(nil)
// Path implements weave.Msg interface.
func (*ApplyDiffMsg) Path() string {
return "validators/apply_diff"
}
func (m *ApplyDiffMsg) Validate() error {
var errs error
errs = errors.AppendField(errs, "Metadata", m.Metadata.Validate())
if len(m.ValidatorUpdates) == 0 {
errs = errors.AppendField(errs, "ValidatorUpdates", errors.ErrEmpty)
}
for i, v := range m.ValidatorUpdates {
errs = errors.AppendField(errs, fmt.Sprintf("ValidatorUpdates.%d", i), v.Validate())
}
return errs
}
func (m *ApplyDiffMsg) AsABCI() []abci.ValidatorUpdate {
validators := make([]abci.ValidatorUpdate, len(m.ValidatorUpdates))
for k, v := range m.ValidatorUpdates {
validators[k] = v.AsABCI()
}
return validators
}