-
Notifications
You must be signed in to change notification settings - Fork 29
/
events.go
40 lines (32 loc) · 919 Bytes
/
events.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
package foundation
import (
"github.com/gogo/protobuf/proto"
codectypes "github.com/Finschia/finschia-sdk/codec/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
)
func (m EventUpdateDecisionPolicy) GetDecisionPolicy() DecisionPolicy {
if m.DecisionPolicy == nil {
return nil
}
policy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy)
if !ok {
return nil
}
return policy
}
func (m *EventUpdateDecisionPolicy) SetDecisionPolicy(policy DecisionPolicy) error {
event, ok := policy.(proto.Message)
if !ok {
return sdkerrors.ErrInvalidType.Wrapf("can't proto marshal %T", event)
}
any, err := codectypes.NewAnyWithValue(event)
if err != nil {
return err
}
m.DecisionPolicy = any
return nil
}
func (m EventUpdateDecisionPolicy) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var policy DecisionPolicy
return unpacker.UnpackAny(m.DecisionPolicy, &policy)
}