cosmos-sdk/x/auth/baseaccount.go

99 lines
2.1 KiB
Go
Raw Normal View History

2018-01-10 20:11:44 -08:00
package auth
2018-01-06 14:22:21 -08:00
import (
2018-01-12 14:30:02 -08:00
"errors"
2018-01-06 14:22:21 -08:00
"github.com/tendermint/go-crypto"
2018-03-02 01:24:07 -08:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
2018-01-06 14:22:21 -08:00
)
//-----------------------------------------------------------
// BaseAccount
2018-01-20 11:19:44 -08:00
var _ sdk.Account = (*BaseAccount)(nil)
2018-01-20 19:00:56 -08:00
// BaseAccount - base account structure.
// Extend this by embedding this in your AppAccount.
// See the examples/basecoin/types/account.go for an example.
2018-01-06 14:22:21 -08:00
type BaseAccount struct {
2018-03-02 01:24:07 -08:00
Address sdk.Address `json:"address"`
Coins sdk.Coins `json:"coins"`
PubKey crypto.PubKey `json:"public_key"`
Sequence int64 `json:"sequence"`
2018-01-06 14:22:21 -08:00
}
2018-03-01 23:49:07 -08:00
func NewBaseAccountWithAddress(addr sdk.Address) BaseAccount {
return BaseAccount{
Address: addr,
2018-01-06 14:22:21 -08:00
}
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
func (acc BaseAccount) Get(key interface{}) (value interface{}, err error) {
panic("not implemented yet")
2018-01-06 14:22:21 -08:00
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-01-06 14:22:21 -08:00
func (acc *BaseAccount) Set(key interface{}, value interface{}) error {
panic("not implemented yet")
2018-01-06 14:22:21 -08:00
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-03-01 23:49:07 -08:00
func (acc BaseAccount) GetAddress() sdk.Address {
2018-01-12 14:30:02 -08:00
return acc.Address
2018-01-06 14:22:21 -08:00
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-03-01 23:49:07 -08:00
func (acc *BaseAccount) SetAddress(addr sdk.Address) error {
2018-01-12 14:30:02 -08:00
if len(acc.Address) != 0 {
return errors.New("cannot override BaseAccount address")
}
2018-01-12 14:30:02 -08:00
acc.Address = addr
return nil
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
func (acc BaseAccount) GetPubKey() crypto.PubKey {
2018-01-12 14:30:02 -08:00
return acc.PubKey
2018-01-06 14:22:21 -08:00
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-01-06 14:22:21 -08:00
func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
2018-04-06 17:25:08 -07:00
if acc.PubKey != nil {
return errors.New("cannot override BaseAccount pubkey")
}
2018-01-12 14:30:02 -08:00
acc.PubKey = pubKey
2018-01-06 14:22:21 -08:00
return nil
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-01-12 12:03:23 -08:00
func (acc *BaseAccount) GetCoins() sdk.Coins {
2018-01-12 14:30:02 -08:00
return acc.Coins
2018-01-06 14:22:21 -08:00
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-01-12 12:03:23 -08:00
func (acc *BaseAccount) SetCoins(coins sdk.Coins) error {
2018-01-12 14:30:02 -08:00
acc.Coins = coins
2018-01-06 14:22:21 -08:00
return nil
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-01-06 14:22:21 -08:00
func (acc *BaseAccount) GetSequence() int64 {
2018-01-12 14:30:02 -08:00
return acc.Sequence
2018-01-06 14:22:21 -08:00
}
2018-01-20 19:00:56 -08:00
// Implements sdk.Account.
2018-01-06 14:22:21 -08:00
func (acc *BaseAccount) SetSequence(seq int64) error {
2018-01-12 14:30:02 -08:00
acc.Sequence = seq
2018-01-06 14:22:21 -08:00
return nil
}
//----------------------------------------
// Wire
func RegisterWireBaseAccount(cdc *wire.Codec) {
2018-03-02 01:24:07 -08:00
wire.RegisterCrypto(cdc)
}