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
|
|
|
|
|
|
|
crypto "github.com/tendermint/go-crypto"
|
|
|
|
|
2018-01-12 12:03:23 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-01-06 14:22:21 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
// BaseAccount
|
|
|
|
|
|
|
|
// BaseAccount - coin account structure
|
|
|
|
type BaseAccount struct {
|
|
|
|
Address crypto.Address `json:"address"`
|
2018-01-12 12:03:23 -08:00
|
|
|
Coins sdk.Coins `json:"coins"`
|
2018-01-12 11:49:53 -08:00
|
|
|
PubKey crypto.PubKey `json:"public_key"`
|
2018-01-06 14:22:21 -08:00
|
|
|
Sequence int64 `json:"sequence"`
|
|
|
|
}
|
|
|
|
|
2018-01-12 11:49:53 -08:00
|
|
|
func NewBaseAccountWithAddress(addr crypto.Address) BaseAccount {
|
|
|
|
return BaseAccount{
|
|
|
|
Address: addr,
|
2018-01-06 14:22:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements Account
|
2018-01-12 11:49:53 -08:00
|
|
|
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 {
|
2018-01-12 11:49:53 -08:00
|
|
|
panic("not implemented yet")
|
2018-01-06 14:22:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements Account
|
2018-01-12 11:49:53 -08:00
|
|
|
func (acc BaseAccount) GetAddress() crypto.Address {
|
2018-01-12 14:30:02 -08:00
|
|
|
return acc.Address
|
2018-01-06 14:22:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements Account
|
2018-01-12 11:49:53 -08:00
|
|
|
func (acc *BaseAccount) SetAddress(addr crypto.Address) error {
|
2018-01-12 14:30:02 -08:00
|
|
|
if len(acc.Address) != 0 {
|
2018-01-12 11:49:53 -08:00
|
|
|
return errors.New("cannot override BaseAccount address")
|
|
|
|
}
|
2018-01-12 14:30:02 -08:00
|
|
|
acc.Address = addr
|
2018-01-12 11:49:53 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements 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-12 11:49:53 -08:00
|
|
|
// Implements Account
|
2018-01-06 14:22:21 -08:00
|
|
|
func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
|
2018-01-12 14:30:02 -08:00
|
|
|
if !acc.PubKey.Empty() {
|
2018-01-12 11:49:53 -08:00
|
|
|
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-12 12:03:23 -08:00
|
|
|
// Implements Account
|
|
|
|
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-12 12:03:23 -08:00
|
|
|
// Implements Account
|
|
|
|
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-12 12:03:23 -08:00
|
|
|
// Implements 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-12 12:03:23 -08:00
|
|
|
// Implements 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
|
|
|
|
}
|