github.com/Finschia/finschia-sdk@v0.48.1/x/foundation/authz.go (about)

     1  package foundation
     2  
     3  import (
     4  	"github.com/gogo/protobuf/proto"
     5  
     6  	sdk "github.com/Finschia/finschia-sdk/types"
     7  	sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
     8  )
     9  
    10  // Authorization represents the interface of various Authorization types implemented
    11  // by other modules.
    12  // Caution: It's not for x/authz exec.
    13  type Authorization interface {
    14  	proto.Message
    15  
    16  	// MsgTypeURL returns the fully-qualified Msg service method URL (as described in ADR 031),
    17  	// which will process and accept or reject a request.
    18  	MsgTypeURL() string
    19  
    20  	// Accept determines whether this grant permits the provided sdk.Msg to be performed,
    21  	// and if so provides an updated authorization instance.
    22  	Accept(ctx sdk.Context, msg sdk.Msg) (AcceptResponse, error)
    23  
    24  	// ValidateBasic does a simple validation check that
    25  	// doesn't require access to any other information.
    26  	ValidateBasic() error
    27  }
    28  
    29  // AcceptResponse instruments the controller of an authz message if the request is accepted
    30  // and if it should be updated or deleted.
    31  type AcceptResponse struct {
    32  	// If Accept=true, the controller can accept and authorization and handle the update.
    33  	Accept bool
    34  	// If Delete=true, the controller must delete the authorization object and release
    35  	// storage resources.
    36  	Delete bool
    37  	// Controller, who is calling Authorization.Accept must check if `Updated != nil`. If yes,
    38  	// it must use the updated version and handle the update on the storage level.
    39  	Updated Authorization
    40  }
    41  
    42  var _ Authorization = (*ReceiveFromTreasuryAuthorization)(nil)
    43  
    44  func (a ReceiveFromTreasuryAuthorization) MsgTypeURL() string {
    45  	return sdk.MsgTypeURL(&MsgWithdrawFromTreasury{})
    46  }
    47  
    48  func (a ReceiveFromTreasuryAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (AcceptResponse, error) {
    49  	_, ok := msg.(*MsgWithdrawFromTreasury)
    50  	if !ok {
    51  		return AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
    52  	}
    53  
    54  	return AcceptResponse{Accept: true}, nil
    55  }
    56  
    57  func (a ReceiveFromTreasuryAuthorization) ValidateBasic() error {
    58  	return nil
    59  }