/
account_retriever.go
49 lines (40 loc) · 1.69 KB
/
account_retriever.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
package client
import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Account defines a read-only version of the auth module's AccountI.
type Account interface {
GetAddress() sdk.AccAddress
GetPubKey() cryptotypes.PubKey // can return nil.
GetAccountNumber() uint64
GetSequence() uint64
}
// AccountRetriever defines the interfaces required by transactions to
// ensure an account exists and to be able to query for account fields necessary
// for signing.
type AccountRetriever interface {
GetAccount(clientCtx Context, addr sdk.AccAddress) (Account, error)
GetAccountWithHeight(clientCtx Context, addr sdk.AccAddress) (Account, int64, error)
EnsureExists(clientCtx Context, addr sdk.AccAddress) error
GetAccountNumberSequence(clientCtx Context, addr sdk.AccAddress) (accNum uint64, accSeq uint64, err error)
}
var _ AccountRetriever = (*MockAccountRetriever)(nil)
// MockAccountRetriever defines a no-op basic AccountRetriever that can be used
// in mocked contexts. Tests or context that need more sophisticated testing
// state should implement their own mock AccountRetriever.
type MockAccountRetriever struct {
ReturnAccNum, ReturnAccSeq uint64
}
func (mar MockAccountRetriever) GetAccount(_ Context, _ sdk.AccAddress) (Account, error) {
return nil, nil
}
func (mar MockAccountRetriever) GetAccountWithHeight(_ Context, _ sdk.AccAddress) (Account, int64, error) {
return nil, 0, nil
}
func (mar MockAccountRetriever) EnsureExists(_ Context, _ sdk.AccAddress) error {
return nil
}
func (mar MockAccountRetriever) GetAccountNumberSequence(_ Context, _ sdk.AccAddress) (uint64, uint64, error) {
return mar.ReturnAccNum, mar.ReturnAccSeq, nil
}