cosmos-sdk/x/auth/account.go

85 lines
1.8 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 (
"encoding/json"
crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/x/coin"
)
//-----------------------------------------------------------
// BaseAccount
// BaseAccount - coin account structure
type BaseAccount struct {
Address crypto.Address `json:"address"`
Coins coin.Coins `json:"coins"`
PubKey crypto.PubKey `json:"public_key"`
2018-01-06 14:22:21 -08:00
Sequence int64 `json:"sequence"`
}
func NewBaseAccountWithAddress(addr crypto.Address) BaseAccount {
return BaseAccount{
Address: addr,
2018-01-06 14:22:21 -08:00
}
}
// Implements Account
func (acc BaseAccount) Get(key interface{}) (value interface{}, err error) {
panic("not implemented yet")
2018-01-06 14:22:21 -08:00
}
// Implements Account
func (acc *BaseAccount) Set(key interface{}, value interface{}) error {
panic("not implemented yet")
2018-01-06 14:22:21 -08:00
}
// Implements Account
func (acc BaseAccount) GetAddress() crypto.Address {
return acc.address
2018-01-06 14:22:21 -08:00
}
// Implements Account
func (acc *BaseAccount) SetAddress(addr crypto.Address) error {
if acc.address != "" {
return errors.New("cannot override BaseAccount address")
}
acc.address = addr
return nil
}
// Implements Account
func (acc BaseAccount) GetPubKey() crypto.PubKey {
2018-01-06 14:22:21 -08:00
return acc.pubKey
}
// Implements Account
2018-01-06 14:22:21 -08:00
func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
if acc.pubKey != "" {
return errors.New("cannot override BaseAccount pubkey")
}
2018-01-06 14:22:21 -08:00
acc.pubKey = pubKey
return nil
}
// Implements coinstore.Coinser
func (acc *BaseAccount) GetCoins() coin.Coins {
return acc.coins
}
// Implements coinstore.Coinser
func (acc *BaseAccount) SetCoins(coins coin.Coins) error {
acc.coins = coins
return nil
}
func (acc *BaseAccount) GetSequence() int64 {
return acc.sequence
}
func (acc *BaseAccount) SetSequence(seq int64) error {
acc.sequence = seq
return nil
}