-
Notifications
You must be signed in to change notification settings - Fork 31
/
authz.go
59 lines (47 loc) · 1.95 KB
/
authz.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
package foundation
import (
"github.com/gogo/protobuf/proto"
sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
)
// Authorization represents the interface of various Authorization types implemented
// by other modules.
// Caution: It's not for x/authz exec.
type Authorization interface {
proto.Message
// MsgTypeURL returns the fully-qualified Msg service method URL (as described in ADR 031),
// which will process and accept or reject a request.
MsgTypeURL() string
// Accept determines whether this grant permits the provided sdk.Msg to be performed,
// and if so provides an updated authorization instance.
Accept(ctx sdk.Context, msg sdk.Msg) (AcceptResponse, error)
// ValidateBasic does a simple validation check that
// doesn't require access to any other information.
ValidateBasic() error
}
// AcceptResponse instruments the controller of an authz message if the request is accepted
// and if it should be updated or deleted.
type AcceptResponse struct {
// If Accept=true, the controller can accept and authorization and handle the update.
Accept bool
// If Delete=true, the controller must delete the authorization object and release
// storage resources.
Delete bool
// Controller, who is calling Authorization.Accept must check if `Updated != nil`. If yes,
// it must use the updated version and handle the update on the storage level.
Updated Authorization
}
var _ Authorization = (*ReceiveFromTreasuryAuthorization)(nil)
func (a ReceiveFromTreasuryAuthorization) MsgTypeURL() string {
return sdk.MsgTypeURL(&MsgWithdrawFromTreasury{})
}
func (a ReceiveFromTreasuryAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (AcceptResponse, error) {
_, ok := msg.(*MsgWithdrawFromTreasury)
if !ok {
return AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
}
return AcceptResponse{Accept: true}, nil
}
func (a ReceiveFromTreasuryAuthorization) ValidateBasic() error {
return nil
}