2019-12-17 03:44:44 -08:00
|
|
|
<!--
|
2019-12-11 09:35:27 -08:00
|
|
|
order: 2
|
2019-12-17 03:44:44 -08:00
|
|
|
-->
|
2019-12-11 09:35:27 -08:00
|
|
|
|
2019-02-20 10:21:57 -08:00
|
|
|
# State
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2019-02-20 10:21:57 -08:00
|
|
|
## Accounts
|
2018-12-05 16:48:08 -08:00
|
|
|
|
|
|
|
Accounts contain authentication information for a uniquely identified external user of an SDK blockchain,
|
|
|
|
including public key, address, and account number / sequence number for replay protection. For efficiency,
|
|
|
|
since account balances must also be fetched to pay fees, account structs also store the balance of a user
|
|
|
|
as `sdk.Coins`.
|
|
|
|
|
|
|
|
Accounts are exposed externally as an interface, and stored internally as
|
|
|
|
either a base account or vesting account. Module clients wishing to add more
|
|
|
|
account types may do so.
|
|
|
|
|
2020-10-16 05:42:48 -07:00
|
|
|
- `0x01 | Address -> ProtocolBuffer(account)`
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2019-02-20 10:21:57 -08:00
|
|
|
### Account Interface
|
2018-12-05 16:48:08 -08:00
|
|
|
|
|
|
|
The account interface exposes methods to read and write standard account information.
|
2020-10-16 05:42:48 -07:00
|
|
|
Note that all of these methods operate on an account struct confirming to the
|
|
|
|
interface - in order to write the account to the store, the account keeper will
|
|
|
|
need to be used.
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2019-08-26 06:09:18 -07:00
|
|
|
```go
|
2020-10-16 05:42:48 -07:00
|
|
|
// AccountI is an interface used to store coins at a given address within state.
|
|
|
|
// It presumes a notion of sequence numbers for replay protection,
|
|
|
|
// a notion of account numbers for replay protection for previously pruned accounts,
|
|
|
|
// and a pubkey for authentication purposes.
|
|
|
|
//
|
|
|
|
// Many complex conditions can be used in the concrete struct which implements AccountI.
|
|
|
|
type AccountI interface {
|
|
|
|
proto.Message
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2020-10-16 05:42:48 -07:00
|
|
|
GetAddress() sdk.AccAddress
|
|
|
|
SetAddress(sdk.AccAddress) error // errors if already set.
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2020-10-16 05:42:48 -07:00
|
|
|
GetPubKey() crypto.PubKey // can return nil.
|
|
|
|
SetPubKey(crypto.PubKey) error
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2020-10-16 05:42:48 -07:00
|
|
|
GetAccountNumber() uint64
|
|
|
|
SetAccountNumber(uint64) error
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2020-10-16 05:42:48 -07:00
|
|
|
GetSequence() uint64
|
|
|
|
SetSequence(uint64) error
|
|
|
|
|
|
|
|
// Ensure that account implements stringer
|
|
|
|
String() string
|
2018-12-05 16:48:08 -08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Base Account
|
|
|
|
|
|
|
|
A base account is the simplest and most common account type, which just stores all requisite
|
|
|
|
fields directly in a struct.
|
|
|
|
|
2020-10-16 05:42:48 -07:00
|
|
|
```protobuf
|
|
|
|
// BaseAccount defines a base account type. It contains all the necessary fields
|
|
|
|
// for basic account functionality. Any custom account type should extend this
|
|
|
|
// type for additional functionality (e.g. vesting).
|
|
|
|
message BaseAccount {
|
|
|
|
string address = 1;
|
|
|
|
google.protobuf.Any pub_key = 2;
|
|
|
|
uint64 account_number = 3;
|
|
|
|
uint64 sequence = 4;
|
2018-12-05 16:48:08 -08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-02-20 10:21:57 -08:00
|
|
|
### Vesting Account
|
2018-12-05 16:48:08 -08:00
|
|
|
|
2020-09-02 09:18:29 -07:00
|
|
|
See [Vesting](05_vesting.md).
|