github.com/cosmos/cosmos-sdk@v0.50.10/client/account_retriever.go (about)

     1  package client
     2  
     3  import (
     4  	cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
     5  	sdk "github.com/cosmos/cosmos-sdk/types"
     6  )
     7  
     8  // Account defines a read-only version of the auth module's AccountI.
     9  type Account interface {
    10  	GetAddress() sdk.AccAddress
    11  	GetPubKey() cryptotypes.PubKey // can return nil.
    12  	GetAccountNumber() uint64
    13  	GetSequence() uint64
    14  }
    15  
    16  // AccountRetriever defines the interfaces required by transactions to
    17  // ensure an account exists and to be able to query for account fields necessary
    18  // for signing.
    19  type AccountRetriever interface {
    20  	GetAccount(clientCtx Context, addr sdk.AccAddress) (Account, error)
    21  	GetAccountWithHeight(clientCtx Context, addr sdk.AccAddress) (Account, int64, error)
    22  	EnsureExists(clientCtx Context, addr sdk.AccAddress) error
    23  	GetAccountNumberSequence(clientCtx Context, addr sdk.AccAddress) (accNum, accSeq uint64, err error)
    24  }
    25  
    26  var _ AccountRetriever = (*MockAccountRetriever)(nil)
    27  
    28  // MockAccountRetriever defines a no-op basic AccountRetriever that can be used
    29  // in mocked contexts. Tests or context that need more sophisticated testing
    30  // state should implement their own mock AccountRetriever.
    31  type MockAccountRetriever struct {
    32  	ReturnAccNum, ReturnAccSeq uint64
    33  }
    34  
    35  func (mar MockAccountRetriever) GetAccount(_ Context, _ sdk.AccAddress) (Account, error) {
    36  	return nil, nil
    37  }
    38  
    39  func (mar MockAccountRetriever) GetAccountWithHeight(_ Context, _ sdk.AccAddress) (Account, int64, error) {
    40  	return nil, 0, nil
    41  }
    42  
    43  func (mar MockAccountRetriever) EnsureExists(_ Context, _ sdk.AccAddress) error {
    44  	return nil
    45  }
    46  
    47  func (mar MockAccountRetriever) GetAccountNumberSequence(_ Context, _ sdk.AccAddress) (uint64, uint64, error) {
    48  	return mar.ReturnAccNum, mar.ReturnAccSeq, nil
    49  }