move coins and accounts out of types
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
)
|
||||
|
||||
// AppAccount - coin account structure
|
||||
type AppAccount struct {
|
||||
Address_ crypto.Address `json:"address"`
|
||||
Coins types.Coins `json:"coins"`
|
||||
PubKey_ crypto.PubKey `json:"public_key"` // can't conflict with PubKey()
|
||||
Sequence int64 `json:"sequence"`
|
||||
}
|
||||
|
||||
// Implements auth.Account
|
||||
func (a *AppAccount) Get(key interface{}) (value interface{}, err error) {
|
||||
switch key.(type) {
|
||||
case string:
|
||||
//
|
||||
default:
|
||||
panic("HURAH!")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Implements auth.Account
|
||||
func (a *AppAccount) Set(key interface{}, value interface{}) error {
|
||||
switch key.(type) {
|
||||
case string:
|
||||
//
|
||||
default:
|
||||
panic("HURAH!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Implements auth.Account
|
||||
func (a *AppAccount) Address() types.Address {
|
||||
return a.PubKey_.Address()
|
||||
}
|
||||
|
||||
// Implements auth.Account
|
||||
func (a *AppAccount) PubKey() crypto.PubKey {
|
||||
return a.PubKey_
|
||||
}
|
||||
|
||||
func (a *AppAccount) SetPubKey(pubKey crypto.PubKey) error {
|
||||
a.PubKey_ = pubKey
|
||||
return nil
|
||||
}
|
||||
|
||||
// Implements coinstore.Coinser
|
||||
func (a *AppAccount) GetCoins() types.Coins {
|
||||
return a.Coins
|
||||
}
|
||||
|
||||
// Implements coinstore.Coinser
|
||||
func (a *AppAccount) SetCoins(coins types.Coins) error {
|
||||
a.Coins = coins
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AppAccount) GetSequence() int64 {
|
||||
return a.Sequence
|
||||
}
|
||||
|
||||
func (a *AppAccount) SetSequence(seq int64) error {
|
||||
a.Sequence = seq
|
||||
return nil
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
type AppAccountStore struct {
|
||||
kvStore types.KVStore
|
||||
}
|
||||
|
||||
func newAccountStore(kvStore types.KVStore) types.AccountStore {
|
||||
return AppAccountStore{kvStore}
|
||||
}
|
||||
|
||||
func (accStore AppAccountStore) NewAccountWithAddress(addr types.Address) types.Account {
|
||||
return &AppAccount{
|
||||
Address_: addr,
|
||||
}
|
||||
}
|
||||
|
||||
func (accStore AppAccountStore) GetAccount(addr types.Address) types.Account {
|
||||
v := accStore.kvStore.Get(keyAccount(addr))
|
||||
|
||||
if len(v) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
acc := new(AppAccount)
|
||||
if err := json.Unmarshal(v, acc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return acc
|
||||
}
|
||||
|
||||
func (accStore AppAccountStore) SetAccount(acc types.Account) {
|
||||
b, err := json.Marshal(acc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
appAcc, ok := acc.(*AppAccount)
|
||||
if !ok {
|
||||
panic("acc is not *AppAccount") // XXX
|
||||
}
|
||||
|
||||
accStore.kvStore.Set(keyAccount(appAcc.Address_), b)
|
||||
}
|
||||
|
||||
func keyAccount(addr types.Address) []byte {
|
||||
return []byte(path.Join("account", string(addr)))
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path"
|
||||
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
acm "github.com/cosmos/cosmos-sdk/x/account"
|
||||
"github.com/cosmos/cosmos-sdk/x/sendtx"
|
||||
"github.com/cosmos/cosmos-sdk/x/store"
|
||||
)
|
||||
|
||||
func txParser(txBytes []byte) (types.Tx, error) {
|
||||
var tx sendtx.SendTx
|
||||
err := json.Unmarshal(txBytes, &tx)
|
||||
return tx, err
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type AccountStore struct {
|
||||
kvStore types.KVStore
|
||||
}
|
||||
|
||||
func newAccountStore(kvStore types.KVStore) store.AccountStore {
|
||||
return AccountStore{kvStore}
|
||||
}
|
||||
|
||||
func (accStore AccountStore) NewAccountWithAddress(addr crypto.Address) store.Account {
|
||||
return acm.NewBaseAccountWithAddress(addr)
|
||||
}
|
||||
|
||||
func (accStore AccountStore) GetAccount(addr crypto.Address) store.Account {
|
||||
v := accStore.kvStore.Get(keyAccount(addr))
|
||||
|
||||
if len(v) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
acc := new(acm.BaseAccount)
|
||||
if err := json.Unmarshal(v, acc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return acc
|
||||
}
|
||||
|
||||
func (accStore AccountStore) SetAccount(acc store.Account) {
|
||||
b, err := json.Marshal(acc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
appAcc, ok := acc.(*acm.BaseAccount)
|
||||
if !ok {
|
||||
panic("acc is not *acm.BaseAccount") // XXX
|
||||
}
|
||||
|
||||
accStore.kvStore.Set(keyAccount(appAcc.Address()), b)
|
||||
}
|
||||
|
||||
func keyAccount(addr crypto.Address) []byte {
|
||||
return []byte(path.Join("account", string(addr)))
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@@ -73,11 +72,3 @@ func main() {
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// create ctx in begin block to be used as background for txs ...
|
||||
|
||||
func txParser(txBytes []byte) (types.Tx, error) {
|
||||
var tx sendtx.SendTx
|
||||
err := json.Unmarshal(txBytes, &tx)
|
||||
return tx, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/tendermint/abci/server"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
|
||||
@@ -89,7 +90,7 @@ func (tx dummyTx) ValidateBasic() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx dummyTx) Signers() []types.Address {
|
||||
func (tx dummyTx) Signers() []crypto.Address {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user