Fix x/coin imports

This commit is contained in:
Jae Kwon 2018-01-12 12:03:23 -08:00
parent ba2b4f0f21
commit fcd8e88e65
5 changed files with 39 additions and 43 deletions

View File

@ -16,7 +16,7 @@ import:
subpackages:
- keys
- package: github.com/tendermint/go-wire
version: develop
version: sdk2
subpackages:
- data
- package: github.com/tendermint/light-client
@ -40,7 +40,7 @@ import:
- rpc/lib/types
- types
- package: github.com/tendermint/tmlibs
version: develop
version: sdk2
subpackages:
- cli
- cli/flags

View File

@ -5,7 +5,7 @@ import (
crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/x/coin"
sdk "github.com/cosmos/cosmos-sdk/types"
)
//-----------------------------------------------------------
@ -14,7 +14,7 @@ import (
// BaseAccount - coin account structure
type BaseAccount struct {
Address crypto.Address `json:"address"`
Coins coin.Coins `json:"coins"`
Coins sdk.Coins `json:"coins"`
PubKey crypto.PubKey `json:"public_key"`
Sequence int64 `json:"sequence"`
}
@ -63,21 +63,23 @@ func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
return nil
}
// Implements coinstore.Coinser
func (acc *BaseAccount) GetCoins() coin.Coins {
// Implements Account
func (acc *BaseAccount) GetCoins() sdk.Coins {
return acc.coins
}
// Implements coinstore.Coinser
func (acc *BaseAccount) SetCoins(coins coin.Coins) error {
// Implements Account
func (acc *BaseAccount) SetCoins(coins sdk.Coins) error {
acc.coins = coins
return nil
}
// Implements Account
func (acc *BaseAccount) GetSequence() int64 {
return acc.sequence
}
// Implements Account
func (acc *BaseAccount) SetSequence(seq int64) error {
acc.sequence = seq
return nil

View File

@ -3,7 +3,7 @@ package auth
import (
"testing"
"github.com/cosmos/cosmos-sdk/x/coin"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
crypto "github.com/tendermint/go-crypto"
)
@ -12,7 +12,7 @@ func TestBaseAccount(t *testing.T) {
key := crypto.GenPrivKeyEd25519()
pub := key.PubKey()
addr := pub.Address()
someCoins := coin.Coins{{"atom", 123}, {"eth", 246}}
someCoins := sdk.Coins{{"atom", 123}, {"eth", 246}}
seq := int64(7)
acc := NewBaseAccountWithAddress(addr)
@ -21,7 +21,7 @@ func TestBaseAccount(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, pub, acc.GetPubKey())
assert.Equal(t, addr, acc.Address())
assert.Equal(t, addr, acc.GetAddress())
err = acc.SetCoins(someCoins)
assert.Nil(t, err)
@ -31,11 +31,6 @@ func TestBaseAccount(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, seq, acc.GetSequence())
_, err = acc.Get("hello") // NOP
assert.Nil(t, err)
err = acc.Set("hello", "goodbyte") // NOP
assert.Nil(t, err)
b, err := acc.MarshalJSON()
assert.Nil(t, err)

View File

@ -3,18 +3,17 @@ package bank
import (
"fmt"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/coin"
sdk "github.com/cosmos/cosmos-sdk/types"
crypto "github.com/tendermint/go-crypto"
)
// CoinStore manages transfers between accounts
type CoinStore struct {
store types.AccountStore
store sdk.AccountStore
}
// SubtractCoins subtracts amt from the coins at the addr.
func (cs CoinStore) SubtractCoins(ctx types.Context, addr crypto.Address, amt types.Coins) (types.Coins, error) {
func (cs CoinStore) SubtractCoins(ctx sdk.Context, addr crypto.Address, amt sdk.Coins) (sdk.Coins, error) {
acc, err := cs.store.GetAccount(ctx, addr)
if err != nil {
return amt, err
@ -34,7 +33,7 @@ func (cs CoinStore) SubtractCoins(ctx types.Context, addr crypto.Address, amt ty
}
// AddCoins adds amt to the coins at the addr.
func (cs CoinStore) AddCoins(ctx types.Context, addr crypto.Address, amt types.Coins) (types.Coins, error) {
func (cs CoinStore) AddCoins(ctx sdk.Context, addr crypto.Address, amt sdk.Coins) (sdk.Coins, error) {
acc, err := cs.store.GetAccount(ctx, addr)
if err != nil {
return amt, err

View File

@ -7,22 +7,22 @@ import (
crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/x/coin"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func TestTxInputValidation(t *testing.T) {
addr1 := crypto.Address([]byte{1, 2})
addr2 := crypto.Address([]byte{7, 8})
someCoins := coin.Coins{{"atom", 123}}
multiCoins := coin.Coins{{"atom", 123}, {"eth", 20}}
someCoins := sdk.Coins{{"atom", 123}}
multiCoins := sdk.Coins{{"atom", 123}, {"eth", 20}}
var emptyAddr crypto.Address
emptyCoins := coin.Coins{}
emptyCoins2 := coin.Coins{{"eth", 0}}
someEmptyCoins := coin.Coins{{"eth", 10}, {"atom", 0}}
minusCoins := coin.Coins{{"eth", -34}}
someMinusCoins := coin.Coins{{"atom", 20}, {"eth", -34}}
unsortedCoins := coin.Coins{{"eth", 1}, {"atom", 1}}
emptyCoins := sdk.Coins{}
emptyCoins2 := sdk.Coins{{"eth", 0}}
someEmptyCoins := sdk.Coins{{"eth", 10}, {"atom", 0}}
minusCoins := sdk.Coins{{"eth", -34}}
someMinusCoins := sdk.Coins{{"atom", 20}, {"eth", -34}}
unsortedCoins := sdk.Coins{{"eth", 1}, {"atom", 1}}
cases := []struct {
valid bool
@ -57,16 +57,16 @@ func TestTxInputValidation(t *testing.T) {
func TestTxOutputValidation(t *testing.T) {
addr1 := crypto.Address([]byte{1, 2})
addr2 := crypto.Address([]byte{7, 8})
someCoins := coin.Coins{{"atom", 123}}
multiCoins := coin.Coins{{"atom", 123}, {"eth", 20}}
someCoins := sdk.Coins{{"atom", 123}}
multiCoins := sdk.Coins{{"atom", 123}, {"eth", 20}}
var emptyAddr crypto.Address
emptyCoins := coin.Coins{}
emptyCoins2 := coin.Coins{{"eth", 0}}
someEmptyCoins := coin.Coins{{"eth", 10}, {"atom", 0}}
minusCoins := coin.Coins{{"eth", -34}}
someMinusCoins := coin.Coins{{"atom", 20}, {"eth", -34}}
unsortedCoins := coin.Coins{{"eth", 1}, {"atom", 1}}
emptyCoins := sdk.Coins{}
emptyCoins2 := sdk.Coins{{"eth", 0}}
someEmptyCoins := sdk.Coins{{"eth", 10}, {"atom", 0}}
minusCoins := sdk.Coins{{"eth", -34}}
someMinusCoins := sdk.Coins{{"atom", 20}, {"eth", -34}}
unsortedCoins := sdk.Coins{{"eth", 1}, {"atom", 1}}
cases := []struct {
valid bool
@ -100,10 +100,10 @@ func TestSendTxValidation(t *testing.T) {
addr1 := crypto.Address([]byte{1, 2})
addr2 := crypto.Address([]byte{7, 8})
atom123 := coin.Coins{{"atom", 123}}
atom124 := coin.Coins{{"atom", 124}}
eth123 := coin.Coins{{"eth", 123}}
atom123eth123 := coin.Coins{{"atom", 123}, {"eth", 123}}
atom123 := sdk.Coins{{"atom", 123}}
atom124 := sdk.Coins{{"atom", 124}}
eth123 := sdk.Coins{{"eth", 123}}
atom123eth123 := sdk.Coins{{"atom", 123}, {"eth", 123}}
input1 := NewTxInput(addr1, atom123)
input2 := NewTxInput(addr1, eth123)
@ -172,7 +172,7 @@ func TestSendTxSigners(t *testing.T) {
{7, 8, 9},
}
someCoins := coin.Coins{{"atom", 123}}
someCoins := sdk.Coins{{"atom", 123}}
inputs := make([]TxInput, len(signers))
for i, signer := range signers {
inputs[i] = NewTxInput(signer, someCoins)