Merge pull request #880 from cosmos/rigel/cleanup

Add Golint to CircleCI // Lint compliant // cleanup
This commit is contained in:
Christopher Goes
2018-04-19 19:54:47 +02:00
committed by GitHub
101 changed files with 841 additions and 963 deletions
+1
View File
@@ -17,6 +17,7 @@ func GetAccountCmdDefault(storeName string, cdc *wire.Codec) *cobra.Command {
return GetAccountCmd(storeName, cdc, GetAccountDecoder(cdc))
}
// Get account decoder for auth.DefaultAccount
func GetAccountDecoder(cdc *wire.Codec) sdk.AccountDecoder {
return func(accBytes []byte) (acct sdk.Account, err error) {
// acct := new(auth.BaseAccount)
+2
View File
@@ -33,10 +33,12 @@ const (
contextKeySigners contextKey = iota
)
// add the signers to the context
func WithSigners(ctx types.Context, accounts []types.Account) types.Context {
return ctx.WithValue(contextKeySigners, accounts)
}
// get the signers from the context
func GetSigners(ctx types.Context) []types.Account {
v := ctx.Value(contextKeySigners)
if v == nil {
+8 -7
View File
@@ -28,6 +28,7 @@ type accountMapper struct {
// NewAccountMapper returns a new sdk.AccountMapper that
// uses go-amino to (binary) encode and decode concrete sdk.Accounts.
// nolint
func NewAccountMapper(cdc *wire.Codec, key sdk.StoreKey, proto sdk.Account) accountMapper {
return accountMapper{
key: key,
@@ -107,14 +108,14 @@ func (am accountMapper) clonePrototype() sdk.Account {
panic(fmt.Sprintf("accountMapper requires a proto sdk.Account, but %v doesn't implement sdk.Account", protoRt))
}
return clone
} else {
protoRv := reflect.New(protoRt).Elem()
clone, ok := protoRv.Interface().(sdk.Account)
if !ok {
panic(fmt.Sprintf("accountMapper requires a proto sdk.Account, but %v doesn't implement sdk.Account", protoRt))
}
return clone
}
protoRv := reflect.New(protoRt).Elem()
clone, ok := protoRv.Interface().(sdk.Account)
if !ok {
panic(fmt.Sprintf("accountMapper requires a proto sdk.Account, but %v doesn't implement sdk.Account", protoRt))
}
return clone
}
func (am accountMapper) encodeAccount(acc sdk.Account) []byte {
+10 -7
View File
@@ -10,16 +10,19 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
auth "github.com/cosmos/cosmos-sdk/x/auth/commands"
)
type commander struct {
storeName string
cdc *wire.Codec
decoder sdk.AccountDecoder
// register REST routes
func RegisterRoutes(r *mux.Router, cdc *wire.Codec, storeName string) {
r.HandleFunc(
"/accounts/{address}",
QueryAccountRequestHandler(storeName, cdc, auth.GetAccountDecoder(cdc)),
).Methods("GET")
}
// query accountREST Handler
func QueryAccountRequestHandler(storeName string, cdc *wire.Codec, decoder sdk.AccountDecoder) func(http.ResponseWriter, *http.Request) {
c := commander{storeName, cdc, decoder}
ctx := context.NewCoreContextFromViper()
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -33,7 +36,7 @@ func QueryAccountRequestHandler(storeName string, cdc *wire.Codec, decoder sdk.A
}
key := sdk.Address(bz)
res, err := ctx.Query(key, c.storeName)
res, err := ctx.Query(key, storeName)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Could't query account. Error: %s", err.Error())))
@@ -47,7 +50,7 @@ func QueryAccountRequestHandler(storeName string, cdc *wire.Codec, decoder sdk.A
}
// decode the value
account, err := c.decoder(res)
account, err := decoder(res)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Could't parse query result. Result: %s. Error: %s", res, err.Error())))
-11
View File
@@ -1,11 +0,0 @@
package rest
import (
"github.com/cosmos/cosmos-sdk/wire"
auth "github.com/cosmos/cosmos-sdk/x/auth/commands"
"github.com/gorilla/mux"
)
func RegisterRoutes(r *mux.Router, cdc *wire.Codec, storeName string) {
r.HandleFunc("/accounts/{address}", QueryAccountRequestHandler(storeName, cdc, auth.GetAccountDecoder(cdc))).Methods("GET")
}
+36 -51
View File
@@ -20,68 +20,53 @@ const (
)
// SendTxCommand will create a send tx and sign it with the given key
func SendTxCmd(Cdc *wire.Codec) *cobra.Command {
cmdr := Commander{Cdc}
func SendTxCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "send",
Short: "Create and sign a send tx",
RunE: cmdr.sendTxCmd,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// get the from/to address
from, err := ctx.GetFromAddress()
if err != nil {
return err
}
toStr := viper.GetString(flagTo)
bz, err := hex.DecodeString(toStr)
if err != nil {
return err
}
to := sdk.Address(bz)
// parse coins
amount := viper.GetString(flagAmount)
coins, err := sdk.ParseCoins(amount)
if err != nil {
return err
}
// build and sign the transaction, then broadcast to Tendermint
msg := BuildMsg(from, to, coins)
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
fmt.Printf("Committed at block %d. Hash: %s\n", res.Height, res.Hash.String())
return nil
},
}
cmd.Flags().String(flagTo, "", "Address to send coins")
cmd.Flags().String(flagAmount, "", "Amount of coins to send")
return cmd
}
type Commander struct {
Cdc *wire.Codec
}
func (c Commander) sendTxCmd(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(c.Cdc))
// get the from address
from, err := ctx.GetFromAddress()
if err != nil {
return err
}
// parse coins
amount := viper.GetString(flagAmount)
coins, err := sdk.ParseCoins(amount)
if err != nil {
return err
}
// parse destination address
dest := viper.GetString(flagTo)
bz, err := hex.DecodeString(dest)
if err != nil {
return err
}
to := sdk.Address(bz)
// build message
msg := BuildMsg(from, to, coins)
// default to next sequence number if none provided
ctx, err = context.EnsureSequence(ctx)
if err != nil {
return err
}
// build and sign the transaction, then broadcast to Tendermint
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, c.Cdc)
if err != nil {
return err
}
fmt.Printf("Committed at block %d. Hash: %s\n", res.Height, res.Hash.String())
return nil
}
// build the sendTx msg
func BuildMsg(from sdk.Address, to sdk.Address, coins sdk.Coins) sdk.Msg {
input := bank.NewInput(from, coins)
output := bank.NewOutput(to, coins)
msg := bank.NewSendMsg([]bank.Input{input}, []bank.Output{output})
msg := bank.NewMsgSend([]bank.Input{input}, []bank.Output{output})
return msg
}
+1 -1
View File
@@ -5,7 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Coin errors reserve 100 ~ 199.
// Bank errors reserve 100 ~ 199.
const (
DefaultCodespace sdk.CodespaceType = 2
+10 -10
View File
@@ -7,13 +7,13 @@ import (
)
// NewHandler returns a handler for "bank" type messages.
func NewHandler(ck CoinKeeper) sdk.Handler {
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case SendMsg:
return handleSendMsg(ctx, ck, msg)
case IssueMsg:
return handleIssueMsg(ctx, ck, msg)
case MsgSend:
return handleMsgSend(ctx, k, msg)
case MsgIssue:
return handleMsgIssue(ctx, k, msg)
default:
errMsg := "Unrecognized bank Msg type: " + reflect.TypeOf(msg).Name()
return sdk.ErrUnknownRequest(errMsg).Result()
@@ -21,11 +21,11 @@ func NewHandler(ck CoinKeeper) sdk.Handler {
}
}
// Handle SendMsg.
func handleSendMsg(ctx sdk.Context, ck CoinKeeper, msg SendMsg) sdk.Result {
// Handle MsgSend.
func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend) sdk.Result {
// NOTE: totalIn == totalOut should already have been checked
err := ck.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
if err != nil {
return err.Result()
}
@@ -34,7 +34,7 @@ func handleSendMsg(ctx sdk.Context, ck CoinKeeper, msg SendMsg) sdk.Result {
return sdk.Result{} // TODO
}
// Handle IssueMsg.
func handleIssueMsg(ctx sdk.Context, ck CoinKeeper, msg IssueMsg) sdk.Result {
// Handle MsgIssue.
func handleMsgIssue(ctx sdk.Context, k Keeper, msg MsgIssue) sdk.Result {
panic("not implemented yet")
}
+100 -100
View File
@@ -6,7 +6,106 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const moduleName = "bank"
// Keeper manages transfers between accounts
type Keeper struct {
am sdk.AccountMapper
}
// NewKeeper returns a new Keeper
func NewKeeper(am sdk.AccountMapper) Keeper {
return Keeper{am: am}
}
// GetCoins returns the coins at the addr.
func (keeper Keeper) GetCoins(ctx sdk.Context, addr sdk.Address) sdk.Coins {
return getCoins(ctx, keeper.am, addr)
}
// SetCoins sets the coins at the addr.
func (keeper Keeper) SetCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) sdk.Error {
return setCoins(ctx, keeper.am, addr, amt)
}
// HasCoins returns whether or not an account has at least amt coins.
func (keeper Keeper) HasCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) bool {
return hasCoins(ctx, keeper.am, addr, amt)
}
// SubtractCoins subtracts amt from the coins at the addr.
func (keeper Keeper) SubtractCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) (sdk.Coins, sdk.Error) {
return subtractCoins(ctx, keeper.am, addr, amt)
}
// AddCoins adds amt to the coins at the addr.
func (keeper Keeper) AddCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) (sdk.Coins, sdk.Error) {
return addCoins(ctx, keeper.am, addr, amt)
}
// SendCoins moves coins from one account to another
func (keeper Keeper) SendCoins(ctx sdk.Context, fromAddr sdk.Address, toAddr sdk.Address, amt sdk.Coins) sdk.Error {
return sendCoins(ctx, keeper.am, fromAddr, toAddr, amt)
}
// InputOutputCoins handles a list of inputs and outputs
func (keeper Keeper) InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) sdk.Error {
return inputOutputCoins(ctx, keeper.am, inputs, outputs)
}
//______________________________________________________________________________________________
// SendKeeper only allows transfers between accounts, without the possibility of creating coins
type SendKeeper struct {
am sdk.AccountMapper
}
// NewSendKeeper returns a new Keeper
func NewSendKeeper(am sdk.AccountMapper) SendKeeper {
return SendKeeper{am: am}
}
// GetCoins returns the coins at the addr.
func (keeper SendKeeper) GetCoins(ctx sdk.Context, addr sdk.Address) sdk.Coins {
return getCoins(ctx, keeper.am, addr)
}
// HasCoins returns whether or not an account has at least amt coins.
func (keeper SendKeeper) HasCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) bool {
return hasCoins(ctx, keeper.am, addr, amt)
}
// SendCoins moves coins from one account to another
func (keeper SendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.Address, toAddr sdk.Address, amt sdk.Coins) sdk.Error {
return sendCoins(ctx, keeper.am, fromAddr, toAddr, amt)
}
// InputOutputCoins handles a list of inputs and outputs
func (keeper SendKeeper) InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) sdk.Error {
return inputOutputCoins(ctx, keeper.am, inputs, outputs)
}
//______________________________________________________________________________________________
// ViewKeeper only allows reading of balances
type ViewKeeper struct {
am sdk.AccountMapper
}
// NewViewKeeper returns a new Keeper
func NewViewKeeper(am sdk.AccountMapper) ViewKeeper {
return ViewKeeper{am: am}
}
// GetCoins returns the coins at the addr.
func (keeper ViewKeeper) GetCoins(ctx sdk.Context, addr sdk.Address) sdk.Coins {
return getCoins(ctx, keeper.am, addr)
}
// HasCoins returns whether or not an account has at least amt coins.
func (keeper ViewKeeper) HasCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) bool {
return hasCoins(ctx, keeper.am, addr, amt)
}
//______________________________________________________________________________________________
func getCoins(ctx sdk.Context, am sdk.AccountMapper, addr sdk.Address) sdk.Coins {
acc := am.GetAccount(ctx, addr)
@@ -88,102 +187,3 @@ func inputOutputCoins(ctx sdk.Context, am sdk.AccountMapper, inputs []Input, out
return nil
}
// CoinKeeper manages transfers between accounts
type CoinKeeper struct {
am sdk.AccountMapper
}
// NewCoinKeeper returns a new CoinKeeper
func NewCoinKeeper(am sdk.AccountMapper) CoinKeeper {
return CoinKeeper{am: am}
}
// GetCoins returns the coins at the addr.
func (keeper CoinKeeper) GetCoins(ctx sdk.Context, addr sdk.Address) sdk.Coins {
return getCoins(ctx, keeper.am, addr)
}
// SetCoins sets the coins at the addr.
func (keeper CoinKeeper) SetCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) sdk.Error {
return setCoins(ctx, keeper.am, addr, amt)
}
// HasCoins returns whether or not an account has at least amt coins.
func (keeper CoinKeeper) HasCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) bool {
return hasCoins(ctx, keeper.am, addr, amt)
}
// SubtractCoins subtracts amt from the coins at the addr.
func (keeper CoinKeeper) SubtractCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) (sdk.Coins, sdk.Error) {
return subtractCoins(ctx, keeper.am, addr, amt)
}
// AddCoins adds amt to the coins at the addr.
func (keeper CoinKeeper) AddCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) (sdk.Coins, sdk.Error) {
return addCoins(ctx, keeper.am, addr, amt)
}
// SendCoins moves coins from one account to another
func (keeper CoinKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.Address, toAddr sdk.Address, amt sdk.Coins) sdk.Error {
return sendCoins(ctx, keeper.am, fromAddr, toAddr, amt)
}
// InputOutputCoins handles a list of inputs and outputs
func (keeper CoinKeeper) InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) sdk.Error {
return inputOutputCoins(ctx, keeper.am, inputs, outputs)
}
// --------------------------------------------------
// SendKeeper only allows transfers between accounts, without the possibility of creating coins
type SendKeeper struct {
am sdk.AccountMapper
}
// NewSendKeeper returns a new CoinKeeper
func NewSendKeeper(am sdk.AccountMapper) SendKeeper {
return SendKeeper{am: am}
}
// GetCoins returns the coins at the addr.
func (keeper SendKeeper) GetCoins(ctx sdk.Context, addr sdk.Address) sdk.Coins {
return getCoins(ctx, keeper.am, addr)
}
// HasCoins returns whether or not an account has at least amt coins.
func (keeper SendKeeper) HasCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) bool {
return hasCoins(ctx, keeper.am, addr, amt)
}
// SendCoins moves coins from one account to another
func (keeper SendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.Address, toAddr sdk.Address, amt sdk.Coins) sdk.Error {
return sendCoins(ctx, keeper.am, fromAddr, toAddr, amt)
}
// InputOutputCoins handles a list of inputs and outputs
func (keeper SendKeeper) InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) sdk.Error {
return inputOutputCoins(ctx, keeper.am, inputs, outputs)
}
// --------------------------------------------------
// ViewKeeper only allows reading of balances
type ViewKeeper struct {
am sdk.AccountMapper
}
// NewViewKeeper returns a new CoinKeeper
func NewViewKeeper(am sdk.AccountMapper) ViewKeeper {
return ViewKeeper{am: am}
}
// GetCoins returns the coins at the addr.
func (keeper ViewKeeper) GetCoins(ctx sdk.Context, addr sdk.Address) sdk.Coins {
return getCoins(ctx, keeper.am, addr)
}
// HasCoins returns whether or not an account has at least amt coins.
func (keeper ViewKeeper) HasCoins(ctx sdk.Context, addr sdk.Address, amt sdk.Coins) bool {
return hasCoins(ctx, keeper.am, addr, amt)
}
+4 -4
View File
@@ -24,7 +24,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
return ms, authKey
}
func TestCoinKeeper(t *testing.T) {
func TestKeeper(t *testing.T) {
ms, authKey := setupMultiStore()
cdc := wire.NewCodec()
@@ -32,7 +32,7 @@ func TestCoinKeeper(t *testing.T) {
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
accountMapper := auth.NewAccountMapper(cdc, authKey, &auth.BaseAccount{})
coinKeeper := NewCoinKeeper(accountMapper)
coinKeeper := NewKeeper(accountMapper)
addr := sdk.Address([]byte("addr1"))
addr2 := sdk.Address([]byte("addr2"))
@@ -118,7 +118,7 @@ func TestSendKeeper(t *testing.T) {
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
accountMapper := auth.NewAccountMapper(cdc, authKey, &auth.BaseAccount{})
coinKeeper := NewCoinKeeper(accountMapper)
coinKeeper := NewKeeper(accountMapper)
sendKeeper := NewSendKeeper(accountMapper)
addr := sdk.Address([]byte("addr1"))
@@ -187,7 +187,7 @@ func TestViewKeeper(t *testing.T) {
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
accountMapper := auth.NewAccountMapper(cdc, authKey, &auth.BaseAccount{})
coinKeeper := NewCoinKeeper(accountMapper)
coinKeeper := NewKeeper(accountMapper)
viewKeeper := NewViewKeeper(accountMapper)
addr := sdk.Address([]byte("addr1"))
+24 -41
View File
@@ -2,29 +2,28 @@ package bank
import (
"encoding/json"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// SendMsg - high level transaction of the coin module
type SendMsg struct {
// MsgSend - high level transaction of the coin module
type MsgSend struct {
Inputs []Input `json:"inputs"`
Outputs []Output `json:"outputs"`
}
var _ sdk.Msg = SendMsg{}
var _ sdk.Msg = MsgSend{}
// NewSendMsg - construct arbitrary multi-in, multi-out send msg.
func NewSendMsg(in []Input, out []Output) SendMsg {
return SendMsg{Inputs: in, Outputs: out}
// NewMsgSend - construct arbitrary multi-in, multi-out send msg.
func NewMsgSend(in []Input, out []Output) MsgSend {
return MsgSend{Inputs: in, Outputs: out}
}
// Implements Msg.
func (msg SendMsg) Type() string { return "bank" } // TODO: "bank/send"
func (msg MsgSend) Type() string { return "bank" } // TODO: "bank/send"
// Implements Msg.
func (msg SendMsg) ValidateBasic() sdk.Error {
func (msg MsgSend) ValidateBasic() sdk.Error {
// this just makes sure all the inputs and outputs are properly formatted,
// not that they actually have the money inside
if len(msg.Inputs) == 0 {
@@ -54,17 +53,13 @@ func (msg SendMsg) ValidateBasic() sdk.Error {
return nil
}
func (msg SendMsg) String() string {
return fmt.Sprintf("SendMsg{%v->%v}", msg.Inputs, msg.Outputs)
}
// Implements Msg.
func (msg SendMsg) Get(key interface{}) (value interface{}) {
func (msg MsgSend) Get(key interface{}) (value interface{}) {
return nil
}
// Implements Msg.
func (msg SendMsg) GetSignBytes() []byte {
func (msg MsgSend) GetSignBytes() []byte {
b, err := json.Marshal(msg) // XXX: ensure some canonical form
if err != nil {
panic(err)
@@ -73,7 +68,7 @@ func (msg SendMsg) GetSignBytes() []byte {
}
// Implements Msg.
func (msg SendMsg) GetSigners() []sdk.Address {
func (msg MsgSend) GetSigners() []sdk.Address {
addrs := make([]sdk.Address, len(msg.Inputs))
for i, in := range msg.Inputs {
addrs[i] = in.Address
@@ -82,24 +77,24 @@ func (msg SendMsg) GetSigners() []sdk.Address {
}
//----------------------------------------
// IssueMsg
// MsgIssue
// IssueMsg - high level transaction of the coin module
type IssueMsg struct {
// MsgIssue - high level transaction of the coin module
type MsgIssue struct {
Banker sdk.Address `json:"banker"`
Outputs []Output `json:"outputs"`
}
// NewIssueMsg - construct arbitrary multi-in, multi-out send msg.
func NewIssueMsg(banker sdk.Address, out []Output) IssueMsg {
return IssueMsg{Banker: banker, Outputs: out}
// NewMsgIssue - construct arbitrary multi-in, multi-out send msg.
func NewMsgIssue(banker sdk.Address, out []Output) MsgIssue {
return MsgIssue{Banker: banker, Outputs: out}
}
// Implements Msg.
func (msg IssueMsg) Type() string { return "bank" } // TODO: "bank/issue"
func (msg MsgIssue) Type() string { return "bank" } // TODO: "bank/issue"
// Implements Msg.
func (msg IssueMsg) ValidateBasic() sdk.Error {
func (msg MsgIssue) ValidateBasic() sdk.Error {
// XXX
if len(msg.Outputs) == 0 {
return ErrNoOutputs(DefaultCodespace).Trace("")
@@ -112,17 +107,13 @@ func (msg IssueMsg) ValidateBasic() sdk.Error {
return nil
}
func (msg IssueMsg) String() string {
return fmt.Sprintf("IssueMsg{%v#%v}", msg.Banker, msg.Outputs)
}
// Implements Msg.
func (msg IssueMsg) Get(key interface{}) (value interface{}) {
func (msg MsgIssue) Get(key interface{}) (value interface{}) {
return nil
}
// Implements Msg.
func (msg IssueMsg) GetSignBytes() []byte {
func (msg MsgIssue) GetSignBytes() []byte {
b, err := json.Marshal(msg) // XXX: ensure some canonical form
if err != nil {
panic(err)
@@ -131,7 +122,7 @@ func (msg IssueMsg) GetSignBytes() []byte {
}
// Implements Msg.
func (msg IssueMsg) GetSigners() []sdk.Address {
func (msg MsgIssue) GetSigners() []sdk.Address {
return []sdk.Address{msg.Banker}
}
@@ -158,11 +149,7 @@ func (in Input) ValidateBasic() sdk.Error {
return nil
}
func (in Input) String() string {
return fmt.Sprintf("Input{%v,%v}", in.Address, in.Coins)
}
// NewInput - create a transaction input, used with SendMsg
// NewInput - create a transaction input, used with MsgSend
func NewInput(addr sdk.Address, coins sdk.Coins) Input {
input := Input{
Address: addr,
@@ -194,11 +181,7 @@ func (out Output) ValidateBasic() sdk.Error {
return nil
}
func (out Output) String() string {
return fmt.Sprintf("Output{%v,%v}", out.Address, out.Coins)
}
// NewOutput - create a transaction output, used with SendMsg
// NewOutput - create a transaction output, used with MsgSend
func NewOutput(addr sdk.Address, coins sdk.Coins) Output {
output := Output{
Address: addr,
+37 -70
View File
@@ -9,14 +9,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
func TestNewSendMsg(t *testing.T) {}
func TestNewMsgSend(t *testing.T) {}
func TestSendMsgType(t *testing.T) {
// Construct a SendMsg
func TestMsgSendType(t *testing.T) {
// Construct a MsgSend
addr1 := sdk.Address([]byte("input"))
addr2 := sdk.Address([]byte("output"))
coins := sdk.Coins{{"atom", 10}}
var msg = SendMsg{
var msg = MsgSend{
Inputs: []Input{NewInput(addr1, coins)},
Outputs: []Output{NewOutput(addr2, coins)},
}
@@ -109,7 +109,7 @@ func TestOutputValidation(t *testing.T) {
}
}
func TestSendMsgValidation(t *testing.T) {
func TestMsgSendValidation(t *testing.T) {
addr1 := sdk.Address([]byte{1, 2})
addr2 := sdk.Address([]byte{7, 8})
atom123 := sdk.Coins{{"atom", 123}}
@@ -128,40 +128,40 @@ func TestSendMsgValidation(t *testing.T) {
cases := []struct {
valid bool
tx SendMsg
tx MsgSend
}{
{false, SendMsg{}}, // no input or output
{false, SendMsg{Inputs: []Input{input1}}}, // just input
{false, SendMsg{Outputs: []Output{output1}}}, // just ouput
{false, SendMsg{
{false, MsgSend{}}, // no input or output
{false, MsgSend{Inputs: []Input{input1}}}, // just input
{false, MsgSend{Outputs: []Output{output1}}}, // just ouput
{false, MsgSend{
Inputs: []Input{NewInput(emptyAddr, atom123)}, // invalid input
Outputs: []Output{output1}}},
{false, SendMsg{
{false, MsgSend{
Inputs: []Input{input1},
Outputs: []Output{{emptyAddr, atom123}}}, // invalid ouput
},
{false, SendMsg{
{false, MsgSend{
Inputs: []Input{input1},
Outputs: []Output{output2}}, // amounts dont match
},
{false, SendMsg{
{false, MsgSend{
Inputs: []Input{input1},
Outputs: []Output{output3}}, // amounts dont match
},
{false, SendMsg{
{false, MsgSend{
Inputs: []Input{input1},
Outputs: []Output{outputMulti}}, // amounts dont match
},
{false, SendMsg{
{false, MsgSend{
Inputs: []Input{input2},
Outputs: []Output{output1}}, // amounts dont match
},
{true, SendMsg{
{true, MsgSend{
Inputs: []Input{input1},
Outputs: []Output{output1}},
},
{true, SendMsg{
{true, MsgSend{
Inputs: []Input{input1, input2},
Outputs: []Output{outputMulti}},
},
@@ -177,29 +177,11 @@ func TestSendMsgValidation(t *testing.T) {
}
}
func TestSendMsgString(t *testing.T) {
// Construct a SendMsg
addr1String := "input"
addr2String := "output"
addr1 := sdk.Address([]byte(addr1String))
addr2 := sdk.Address([]byte(addr2String))
coins := sdk.Coins{{"atom", 10}}
var msg = SendMsg{
Inputs: []Input{NewInput(addr1, coins)},
Outputs: []Output{NewOutput(addr2, coins)},
}
res := msg.String()
expected := fmt.Sprintf("SendMsg{[Input{%X,10atom}]->[Output{%X,10atom}]}", addr1String, addr2String)
// TODO some failures for bad results
assert.Equal(t, expected, res)
}
func TestSendMsgGet(t *testing.T) {
func TestMsgSendGet(t *testing.T) {
addr1 := sdk.Address([]byte("input"))
addr2 := sdk.Address([]byte("output"))
coins := sdk.Coins{{"atom", 10}}
var msg = SendMsg{
var msg = MsgSend{
Inputs: []Input{NewInput(addr1, coins)},
Outputs: []Output{NewOutput(addr2, coins)},
}
@@ -207,11 +189,11 @@ func TestSendMsgGet(t *testing.T) {
assert.Nil(t, res)
}
func TestSendMsgGetSignBytes(t *testing.T) {
func TestMsgSendGetSignBytes(t *testing.T) {
addr1 := sdk.Address([]byte("input"))
addr2 := sdk.Address([]byte("output"))
coins := sdk.Coins{{"atom", 10}}
var msg = SendMsg{
var msg = MsgSend{
Inputs: []Input{NewInput(addr1, coins)},
Outputs: []Output{NewOutput(addr2, coins)},
}
@@ -220,8 +202,8 @@ func TestSendMsgGetSignBytes(t *testing.T) {
assert.Equal(t, string(res), `{"inputs":[{"address":"696E707574","coins":[{"denom":"atom","amount":10}]}],"outputs":[{"address":"6F7574707574","coins":[{"denom":"atom","amount":10}]}]}`)
}
func TestSendMsgGetSigners(t *testing.T) {
var msg = SendMsg{
func TestMsgSendGetSigners(t *testing.T) {
var msg = MsgSend{
Inputs: []Input{
NewInput(sdk.Address([]byte("input1")), nil),
NewInput(sdk.Address([]byte("input2")), nil),
@@ -235,7 +217,7 @@ func TestSendMsgGetSigners(t *testing.T) {
/*
// what to do w/ this test?
func TestSendMsgSigners(t *testing.T) {
func TestMsgSendSigners(t *testing.T) {
signers := []sdk.Address{
{1, 2, 3},
{4, 5, 6},
@@ -247,24 +229,24 @@ func TestSendMsgSigners(t *testing.T) {
for i, signer := range signers {
inputs[i] = NewInput(signer, someCoins)
}
tx := NewSendMsg(inputs, nil)
tx := NewMsgSend(inputs, nil)
assert.Equal(t, signers, tx.Signers())
}
*/
// ----------------------------------------
// IssueMsg Tests
// MsgIssue Tests
func TestNewIssueMsg(t *testing.T) {
func TestNewMsgIssue(t *testing.T) {
// TODO
}
func TestIssueMsgType(t *testing.T) {
// Construct an IssueMsg
func TestMsgIssueType(t *testing.T) {
// Construct an MsgIssue
addr := sdk.Address([]byte("loan-from-bank"))
coins := sdk.Coins{{"atom", 10}}
var msg = IssueMsg{
var msg = MsgIssue{
Banker: sdk.Address([]byte("input")),
Outputs: []Output{NewOutput(addr, coins)},
}
@@ -273,29 +255,14 @@ func TestIssueMsgType(t *testing.T) {
assert.Equal(t, msg.Type(), "bank")
}
func TestIssueMsgValidation(t *testing.T) {
func TestMsgIssueValidation(t *testing.T) {
// TODO
}
func TestIssueMsgString(t *testing.T) {
addrString := "loan-from-bank"
bankerString := "input"
// Construct a IssueMsg
addr := sdk.Address([]byte(addrString))
coins := sdk.Coins{{"atom", 10}}
var msg = IssueMsg{
Banker: sdk.Address([]byte(bankerString)),
Outputs: []Output{NewOutput(addr, coins)},
}
res := msg.String()
expected := fmt.Sprintf("IssueMsg{%X#[Output{%X,10atom}]}", bankerString, addrString)
assert.Equal(t, expected, res)
}
func TestIssueMsgGet(t *testing.T) {
func TestMsgIssueGet(t *testing.T) {
addr := sdk.Address([]byte("loan-from-bank"))
coins := sdk.Coins{{"atom", 10}}
var msg = IssueMsg{
var msg = MsgIssue{
Banker: sdk.Address([]byte("input")),
Outputs: []Output{NewOutput(addr, coins)},
}
@@ -303,10 +270,10 @@ func TestIssueMsgGet(t *testing.T) {
assert.Nil(t, res)
}
func TestIssueMsgGetSignBytes(t *testing.T) {
func TestMsgIssueGetSignBytes(t *testing.T) {
addr := sdk.Address([]byte("loan-from-bank"))
coins := sdk.Coins{{"atom", 10}}
var msg = IssueMsg{
var msg = MsgIssue{
Banker: sdk.Address([]byte("input")),
Outputs: []Output{NewOutput(addr, coins)},
}
@@ -315,8 +282,8 @@ func TestIssueMsgGetSignBytes(t *testing.T) {
assert.Equal(t, string(res), `{"banker":"696E707574","outputs":[{"address":"6C6F616E2D66726F6D2D62616E6B","coins":[{"denom":"atom","amount":10}]}]}`)
}
func TestIssueMsgGetSigners(t *testing.T) {
var msg = IssueMsg{
func TestMsgIssueGetSigners(t *testing.T) {
var msg = MsgIssue{
Banker: sdk.Address([]byte("onlyone")),
}
res := msg.GetSigners()
-14
View File
@@ -1,14 +0,0 @@
package rest
import (
"github.com/gorilla/mux"
keys "github.com/tendermint/go-crypto/keys"
"github.com/cosmos/cosmos-sdk/wire"
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc("/accounts/{address}/send", SendRequestHandler(cdc, kb)).Methods("POST")
}
+6 -2
View File
@@ -15,6 +15,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/commands"
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc("/accounts/{address}/send", SendRequestHandler(cdc, kb)).Methods("POST")
}
type sendBody struct {
// fees is not used currently
// Fees sdk.Coin `json="fees"`
@@ -27,7 +32,6 @@ type sendBody struct {
// SendRequestHandler - http request handler to send coins to a address
func SendRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.ResponseWriter, *http.Request) {
c := commands.Commander{cdc}
ctx := context.NewCoreContextFromViper()
return func(w http.ResponseWriter, r *http.Request) {
// collect data
@@ -73,7 +77,7 @@ func SendRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.ResponseWrit
// sign
ctx = ctx.WithSequence(m.Sequence)
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, cdc)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(err.Error()))
+2 -2
View File
@@ -6,6 +6,6 @@ import (
// Register concrete types on wire codec
func RegisterWire(cdc *wire.Codec) {
cdc.RegisterConcrete(SendMsg{}, "cosmos-sdk/Send", nil)
cdc.RegisterConcrete(IssueMsg{}, "cosmos-sdk/Issue", nil)
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil)
cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil)
}
+27 -38
View File
@@ -23,53 +23,42 @@ const (
flagChain = "chain"
)
// IBC transfer command
func IBCTransferCmd(cdc *wire.Codec) *cobra.Command {
cmdr := sendCommander{cdc}
cmd := &cobra.Command{
Use: "transfer",
RunE: cmdr.sendIBCTransfer,
Use: "transfer",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// get the from address
from, err := ctx.GetFromAddress()
if err != nil {
return err
}
// build the message
msg, err := buildMsg(from)
if err != nil {
return err
}
// get password
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
fmt.Printf("Committed at block %d. Hash: %s\n", res.Height, res.Hash.String())
return nil
},
}
cmd.Flags().String(flagTo, "", "Address to send coins")
cmd.Flags().String(flagAmount, "", "Amount of coins to send")
cmd.Flags().String(flagChain, "", "Destination chain to send coins")
return cmd
}
type sendCommander struct {
cdc *wire.Codec
}
func (c sendCommander) sendIBCTransfer(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(c.cdc))
// get the from address
from, err := ctx.GetFromAddress()
if err != nil {
return err
}
// build the message
msg, err := buildMsg(from)
if err != nil {
return err
}
// default to next sequence number if none provided
ctx, err = context.EnsureSequence(ctx)
if err != nil {
return err
}
// get password
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, c.cdc)
if err != nil {
return err
}
fmt.Printf("Committed at block %d. Hash: %s\n", res.Height, res.Hash.String())
return nil
}
func buildMsg(from sdk.Address) (sdk.Msg, error) {
amount := viper.GetString(flagAmount)
coins, err := sdk.ParseCoins(amount)
+6 -3
View File
@@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc"
)
// flags
const (
FlagFromChainID = "from-chain-id"
FlagFromChainNode = "from-chain-node"
@@ -35,6 +36,7 @@ type relayCommander struct {
logger log.Logger
}
// IBC relay command
func IBCRelayCmd(cdc *wire.Codec) *cobra.Command {
cmdr := relayCommander{
cdc: cdc,
@@ -91,6 +93,7 @@ func (c relayCommander) loop(fromChainID, fromChainNode, toChainID, toChainNode
}
ingressKey := ibc.IngressSequenceKey(fromChainID)
OUTER:
for {
time.Sleep(5 * time.Second)
@@ -111,7 +114,7 @@ OUTER:
egressLengthbz, err := query(fromChainNode, lengthKey, c.ibcStore)
if err != nil {
c.logger.Error("Error querying outgoing packet list length", "err", err)
continue OUTER
continue OUTER //TODO replace with continue (I think it should just to the correct place where OUTER is now)
}
var egressLength int64
if egressLengthbz == nil {
@@ -129,14 +132,14 @@ OUTER:
egressbz, err := query(fromChainNode, ibc.EgressKey(toChainID, i), c.ibcStore)
if err != nil {
c.logger.Error("Error querying egress packet", "err", err)
continue OUTER
continue OUTER // TODO replace to break, will break first loop then send back to the beginning (aka OUTER)
}
err = c.broadcastTx(seq, toChainNode, c.refine(egressbz, i, passphrase))
seq++
if err != nil {
c.logger.Error("Error broadcasting ingress packet", "err", err)
continue OUTER
continue OUTER // TODO replace to break, will break first loop then send back to the beginning (aka OUTER)
}
c.logger.Info("Relayed IBC packet", "number", i)
+3 -3
View File
@@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// IBC errors reserve 200 ~ 299.
const (
DefaultCodespace sdk.CodespaceType = 3
@@ -24,10 +25,10 @@ func codeToDefaultMsg(code sdk.CodeType) string {
}
}
// nolint
func ErrInvalidSequence(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidSequence, "")
}
func ErrIdenticalChains(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeIdenticalChains, "")
}
@@ -43,7 +44,6 @@ func newError(codespace sdk.CodespaceType, code sdk.CodeType, msg string) sdk.Er
func msgOrDefaultMsg(msg string, code sdk.CodeType) string {
if msg != "" {
return msg
} else {
return codeToDefaultMsg(code)
}
return codeToDefaultMsg(code)
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
)
func NewHandler(ibcm IBCMapper, ck bank.CoinKeeper) sdk.Handler {
func NewHandler(ibcm Mapper, ck bank.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case IBCTransferMsg:
@@ -22,7 +22,7 @@ func NewHandler(ibcm IBCMapper, ck bank.CoinKeeper) sdk.Handler {
}
// IBCTransferMsg deducts coins from the account and creates an egress IBC packet.
func handleIBCTransferMsg(ctx sdk.Context, ibcm IBCMapper, ck bank.CoinKeeper, msg IBCTransferMsg) sdk.Result {
func handleIBCTransferMsg(ctx sdk.Context, ibcm Mapper, ck bank.Keeper, msg IBCTransferMsg) sdk.Result {
packet := msg.IBCPacket
_, err := ck.SubtractCoins(ctx, packet.SrcAddr, packet.Coins)
@@ -39,7 +39,7 @@ func handleIBCTransferMsg(ctx sdk.Context, ibcm IBCMapper, ck bank.CoinKeeper, m
}
// IBCReceiveMsg adds coins to the destination address and creates an ingress IBC packet.
func handleIBCReceiveMsg(ctx sdk.Context, ibcm IBCMapper, ck bank.CoinKeeper, msg IBCReceiveMsg) sdk.Result {
func handleIBCReceiveMsg(ctx sdk.Context, ibcm Mapper, ck bank.Keeper, msg IBCReceiveMsg) sdk.Result {
packet := msg.IBCPacket
seq := ibcm.GetIngressSequence(ctx, packet.SrcChain)
+6 -6
View File
@@ -16,7 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
)
// AccountMapper(/CoinKeeper) and IBCMapper should use different StoreKey later
// AccountMapper(/Keeper) and IBCMapper should use different StoreKey later
func defaultContext(key sdk.StoreKey) sdk.Context {
db := dbm.NewMemDB()
@@ -31,7 +31,7 @@ func newAddress() crypto.Address {
return crypto.GenPrivKeyEd25519().PubKey().Address()
}
func getCoins(ck bank.CoinKeeper, ctx sdk.Context, addr crypto.Address) (sdk.Coins, sdk.Error) {
func getCoins(ck bank.Keeper, ctx sdk.Context, addr crypto.Address) (sdk.Coins, sdk.Error) {
zero := sdk.Coins(nil)
return ck.AddCoins(ctx, addr, zero)
}
@@ -41,8 +41,8 @@ func makeCodec() *wire.Codec {
// Register Msgs
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.SendMsg{}, "test/ibc/Send", nil)
cdc.RegisterConcrete(bank.IssueMsg{}, "test/ibc/Issue", nil)
cdc.RegisterConcrete(bank.MsgSend{}, "test/ibc/Send", nil)
cdc.RegisterConcrete(bank.MsgIssue{}, "test/ibc/Issue", nil)
cdc.RegisterConcrete(IBCTransferMsg{}, "test/ibc/IBCTransferMsg", nil)
cdc.RegisterConcrete(IBCReceiveMsg{}, "test/ibc/IBCReceiveMsg", nil)
@@ -61,7 +61,7 @@ func TestIBC(t *testing.T) {
ctx := defaultContext(key)
am := auth.NewAccountMapper(cdc, key, &auth.BaseAccount{})
ck := bank.NewCoinKeeper(am)
ck := bank.NewKeeper(am)
src := newAddress()
dest := newAddress()
@@ -73,7 +73,7 @@ func TestIBC(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, mycoins, coins)
ibcm := NewIBCMapper(cdc, key, DefaultCodespace)
ibcm := NewMapper(cdc, key, DefaultCodespace)
h := NewHandler(ibcm, ck)
packet := IBCPacket{
SrcAddr: src,
+13 -10
View File
@@ -7,17 +7,18 @@ import (
wire "github.com/cosmos/cosmos-sdk/wire"
)
type IBCMapper struct {
// IBC Mapper
type Mapper struct {
key sdk.StoreKey
cdc *wire.Codec
codespace sdk.CodespaceType
}
// XXX: The IBCMapper should not take a CoinKeeper. Rather have the CoinKeeper
// take an IBCMapper.
func NewIBCMapper(cdc *wire.Codec, key sdk.StoreKey, codespace sdk.CodespaceType) IBCMapper {
// XXX: The Mapper should not take a CoinKeeper. Rather have the CoinKeeper
// take an Mapper.
func NewMapper(cdc *wire.Codec, key sdk.StoreKey, codespace sdk.CodespaceType) Mapper {
// XXX: How are these codecs supposed to work?
return IBCMapper{
return Mapper{
key: key,
cdc: cdc,
codespace: codespace,
@@ -28,7 +29,7 @@ func NewIBCMapper(cdc *wire.Codec, key sdk.StoreKey, codespace sdk.CodespaceType
// only be invoked from another module directly and not through a user
// transaction.
// TODO: Handle invalid IBC packets and return errors.
func (ibcm IBCMapper) PostIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error {
func (ibcm Mapper) PostIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error {
// write everything into the state
store := ctx.KVStore(ibcm.key)
index := ibcm.getEgressLength(store, packet.DestChain)
@@ -52,7 +53,7 @@ func (ibcm IBCMapper) PostIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error
// to the appropriate callbacks.
// XXX: For now this handles all interactions with the CoinKeeper.
// XXX: This needs to do some authentication checking.
func (ibcm IBCMapper) ReceiveIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error {
func (ibcm Mapper) ReceiveIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error {
return nil
}
@@ -74,7 +75,8 @@ func unmarshalBinaryPanic(cdc *wire.Codec, bz []byte, ptr interface{}) {
}
}
func (ibcm IBCMapper) GetIngressSequence(ctx sdk.Context, srcChain string) int64 {
// TODO add description
func (ibcm Mapper) GetIngressSequence(ctx sdk.Context, srcChain string) int64 {
store := ctx.KVStore(ibcm.key)
key := IngressSequenceKey(srcChain)
@@ -90,7 +92,8 @@ func (ibcm IBCMapper) GetIngressSequence(ctx sdk.Context, srcChain string) int64
return res
}
func (ibcm IBCMapper) SetIngressSequence(ctx sdk.Context, srcChain string, sequence int64) {
// TODO add description
func (ibcm Mapper) SetIngressSequence(ctx sdk.Context, srcChain string, sequence int64) {
store := ctx.KVStore(ibcm.key)
key := IngressSequenceKey(srcChain)
@@ -99,7 +102,7 @@ func (ibcm IBCMapper) SetIngressSequence(ctx sdk.Context, srcChain string, seque
}
// Retrieves the index of the currently stored outgoing IBC packets.
func (ibcm IBCMapper) getEgressLength(store sdk.KVStore, destChain string) int64 {
func (ibcm Mapper) getEgressLength(store sdk.KVStore, destChain string) int64 {
bz := store.Get(EgressLengthKey(destChain))
if bz == nil {
zero := marshalBinaryPanic(ibcm.cdc, int64(0))
-14
View File
@@ -1,14 +0,0 @@
package rest
import (
"github.com/gorilla/mux"
keys "github.com/tendermint/go-crypto/keys"
"github.com/cosmos/cosmos-sdk/wire"
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandler(cdc, kb)).Methods("POST")
}
+6 -3
View File
@@ -11,10 +11,14 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/bank/commands"
"github.com/cosmos/cosmos-sdk/x/ibc"
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandler(cdc, kb)).Methods("POST")
}
type transferBody struct {
// Fees sdk.Coin `json="fees"`
Amount sdk.Coins `json:"amount"`
@@ -27,7 +31,6 @@ type transferBody struct {
// TransferRequestHandler - http request handler to transfer coins to a address
// on a different chain via IBC
func TransferRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.ResponseWriter, *http.Request) {
c := commands.Commander{cdc}
ctx := context.NewCoreContextFromViper()
return func(w http.ResponseWriter, r *http.Request) {
// collect data
@@ -70,7 +73,7 @@ func TransferRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.Response
// sign
ctx = ctx.WithSequence(m.Sequence)
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, cdc)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(err.Error()))
+18 -26
View File
@@ -9,6 +9,7 @@ import (
// ------------------------------
// IBCPacket
// nolint - TODO rename to Packet as IBCPacket stutters (golint)
// IBCPacket defines a piece of data that can be send between two separate
// blockchains.
type IBCPacket struct {
@@ -31,6 +32,7 @@ func NewIBCPacket(srcAddr sdk.Address, destAddr sdk.Address, coins sdk.Coins,
}
}
// validator the ibc packey
func (ibcp IBCPacket) ValidateBasic() sdk.Error {
if ibcp.SrcChain == ibcp.DestChain {
return ErrIdenticalChains(DefaultCodespace).Trace("")
@@ -44,19 +46,20 @@ func (ibcp IBCPacket) ValidateBasic() sdk.Error {
// ----------------------------------
// IBCTransferMsg
// nolint - TODO rename to TransferMsg as folks will reference with ibc.TransferMsg
// IBCTransferMsg defines how another module can send an IBCPacket.
type IBCTransferMsg struct {
IBCPacket
}
func (msg IBCTransferMsg) Type() string {
return "ibc"
}
// nolint
func (msg IBCTransferMsg) Type() string { return "ibc" }
func (msg IBCTransferMsg) Get(key interface{}) interface{} { return nil }
func (msg IBCTransferMsg) Get(key interface{}) interface{} {
return nil
}
// x/bank/tx.go MsgSend.GetSigners()
func (msg IBCTransferMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.SrcAddr} }
// get the sign bytes for ibc transfer message
func (msg IBCTransferMsg) GetSignBytes() []byte {
cdc := wire.NewCodec()
bz, err := cdc.MarshalBinary(msg)
@@ -66,18 +69,15 @@ func (msg IBCTransferMsg) GetSignBytes() []byte {
return bz
}
// validate ibc transfer message
func (msg IBCTransferMsg) ValidateBasic() sdk.Error {
return msg.IBCPacket.ValidateBasic()
}
// x/bank/tx.go SendMsg.GetSigners()
func (msg IBCTransferMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.SrcAddr}
}
// ----------------------------------
// IBCReceiveMsg
// nolint - TODO rename to ReceiveMsg as folks will reference with ibc.ReceiveMsg
// IBCReceiveMsg defines the message that a relayer uses to post an IBCPacket
// to the destination chain.
type IBCReceiveMsg struct {
@@ -86,14 +86,15 @@ type IBCReceiveMsg struct {
Sequence int64
}
func (msg IBCReceiveMsg) Type() string {
return "ibc"
}
// nolint
func (msg IBCReceiveMsg) Type() string { return "ibc" }
func (msg IBCReceiveMsg) Get(key interface{}) interface{} { return nil }
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() }
func (msg IBCReceiveMsg) Get(key interface{}) interface{} {
return nil
}
// x/bank/tx.go MsgSend.GetSigners()
func (msg IBCReceiveMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Relayer} }
// get the sign bytes for ibc receive message
func (msg IBCReceiveMsg) GetSignBytes() []byte {
cdc := wire.NewCodec()
bz, err := cdc.MarshalBinary(msg)
@@ -102,12 +103,3 @@ func (msg IBCReceiveMsg) GetSignBytes() []byte {
}
return bz
}
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error {
return msg.IBCPacket.ValidateBasic()
}
// x/bank/tx.go SendMsg.GetSigners()
func (msg IBCReceiveMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.Relayer}
}
+1 -2
View File
@@ -106,7 +106,6 @@ func constructIBCPacket(valid bool) IBCPacket {
if valid {
return NewIBCPacket(srcAddr, destAddr, coins, srcChain, destChain)
} else {
return NewIBCPacket(srcAddr, destAddr, coins, srcChain, srcChain)
}
return NewIBCPacket(srcAddr, destAddr, coins, srcChain, srcChain)
}
+48 -65
View File
@@ -21,89 +21,72 @@ const (
flagValidator = "validator"
)
// simple bond tx
func BondTxCmd(cdc *wire.Codec) *cobra.Command {
cmdr := commander{cdc}
cmd := &cobra.Command{
Use: "bond",
Short: "Bond to a validator",
RunE: cmdr.bondTxCmd,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper()
from, err := ctx.GetFromAddress()
if err != nil {
return err
}
stakeString := viper.GetString(flagStake)
if len(stakeString) == 0 {
return fmt.Errorf("specify coins to bond with --stake")
}
valString := viper.GetString(flagValidator)
if len(valString) == 0 {
return fmt.Errorf("specify pubkey to bond to with --validator")
}
stake, err := sdk.ParseCoin(stakeString)
if err != nil {
return err
}
// TODO: bech32 ...
rawPubKey, err := hex.DecodeString(valString)
if err != nil {
return err
}
var pubKeyEd crypto.PubKeyEd25519
copy(pubKeyEd[:], rawPubKey)
msg := simplestake.NewMsgBond(from, stake, pubKeyEd)
return sendMsg(cdc, msg)
},
}
cmd.Flags().String(flagStake, "", "Amount of coins to stake")
cmd.Flags().String(flagValidator, "", "Validator address to stake")
return cmd
}
// simple unbond tx
func UnbondTxCmd(cdc *wire.Codec) *cobra.Command {
cmdr := commander{cdc}
cmd := &cobra.Command{
Use: "unbond",
Short: "Unbond from a validator",
RunE: cmdr.unbondTxCmd,
RunE: func(cmd *cobra.Command, args []string) error {
from, err := context.NewCoreContextFromViper().GetFromAddress()
if err != nil {
return err
}
msg := simplestake.NewMsgUnbond(from)
return sendMsg(cdc, msg)
},
}
return cmd
}
type commander struct {
cdc *wire.Codec
}
func (co commander) bondTxCmd(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper()
from, err := ctx.GetFromAddress()
if err != nil {
return err
}
stakeString := viper.GetString(flagStake)
if len(stakeString) == 0 {
return fmt.Errorf("specify coins to bond with --stake")
}
valString := viper.GetString(flagValidator)
if len(valString) == 0 {
return fmt.Errorf("specify pubkey to bond to with --validator")
}
stake, err := sdk.ParseCoin(stakeString)
if err != nil {
return err
}
// TODO: bech32 ...
rawPubKey, err := hex.DecodeString(valString)
if err != nil {
return err
}
var pubKeyEd crypto.PubKeyEd25519
copy(pubKeyEd[:], rawPubKey)
msg := simplestake.NewBondMsg(from, stake, pubKeyEd)
return co.sendMsg(msg)
}
func (co commander) unbondTxCmd(cmd *cobra.Command, args []string) error {
from, err := context.NewCoreContextFromViper().GetFromAddress()
if err != nil {
return err
}
msg := simplestake.NewUnbondMsg(from)
return co.sendMsg(msg)
}
func (co commander) sendMsg(msg sdk.Msg) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(co.cdc))
// default to next sequence number if none provided
ctx, err := context.EnsureSequence(ctx)
if err != nil {
return err
}
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, co.cdc)
func sendMsg(cdc *wire.Codec, msg sdk.Msg) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
+2 -3
View File
@@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// simple stake errors reserve 300 ~ 399.
const (
DefaultCodespace sdk.CodespaceType = 4
@@ -14,18 +15,16 @@ const (
CodeIncorrectStakingToken sdk.CodeType = 303
)
// nolint
func ErrIncorrectStakingToken(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeIncorrectStakingToken, "")
}
func ErrEmptyValidator(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeEmptyValidator, "")
}
func ErrInvalidUnbond(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeInvalidUnbond, "")
}
func ErrEmptyStake(codespace sdk.CodespaceType) sdk.Error {
return newError(codespace, CodeEmptyStake, "")
}
+6 -6
View File
@@ -10,17 +10,17 @@ import (
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case BondMsg:
return handleBondMsg(ctx, k, msg)
case UnbondMsg:
return handleUnbondMsg(ctx, k, msg)
case MsgBond:
return handleMsgBond(ctx, k, msg)
case MsgUnbond:
return handleMsgUnbond(ctx, k, msg)
default:
return sdk.ErrUnknownRequest("No match for message type.").Result()
}
}
}
func handleBondMsg(ctx sdk.Context, k Keeper, msg BondMsg) sdk.Result {
func handleMsgBond(ctx sdk.Context, k Keeper, msg MsgBond) sdk.Result {
power, err := k.Bond(ctx, msg.Address, msg.PubKey, msg.Stake)
if err != nil {
return err.Result()
@@ -37,7 +37,7 @@ func handleBondMsg(ctx sdk.Context, k Keeper, msg BondMsg) sdk.Result {
}
}
func handleUnbondMsg(ctx sdk.Context, k Keeper, msg UnbondMsg) sdk.Result {
func handleMsgUnbond(ctx sdk.Context, k Keeper, msg MsgUnbond) sdk.Result {
pubKey, _, err := k.Unbond(ctx, msg.Address)
if err != nil {
return err.Result()
+5 -2
View File
@@ -12,15 +12,16 @@ const stakingToken = "steak"
const moduleName = "simplestake"
// simple stake keeper
type Keeper struct {
ck bank.CoinKeeper
ck bank.Keeper
key sdk.StoreKey
cdc *wire.Codec
codespace sdk.CodespaceType
}
func NewKeeper(key sdk.StoreKey, coinKeeper bank.CoinKeeper, codespace sdk.CodespaceType) Keeper {
func NewKeeper(key sdk.StoreKey, coinKeeper bank.Keeper, codespace sdk.CodespaceType) Keeper {
cdc := wire.NewCodec()
wire.RegisterCrypto(cdc)
return Keeper{
@@ -59,6 +60,7 @@ func (k Keeper) deleteBondInfo(ctx sdk.Context, addr sdk.Address) {
store.Delete(addr)
}
// register a bond with the keeper
func (k Keeper) Bond(ctx sdk.Context, addr sdk.Address, pubKey crypto.PubKey, stake sdk.Coin) (int64, sdk.Error) {
if stake.Denom != stakingToken {
return 0, ErrIncorrectStakingToken(k.codespace)
@@ -83,6 +85,7 @@ func (k Keeper) Bond(ctx sdk.Context, addr sdk.Address, pubKey crypto.PubKey, st
return bi.Power, nil
}
// register an unbond with the keeper
func (k Keeper) Unbond(ctx sdk.Context, addr sdk.Address) (crypto.PubKey, int64, sdk.Error) {
bi := k.getBondInfo(ctx, addr)
if bi.isEmpty() {
+2 -2
View File
@@ -33,7 +33,7 @@ func TestKeeperGetSet(t *testing.T) {
ms, _, capKey := setupMultiStore()
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
stakeKeeper := NewKeeper(capKey, bank.NewCoinKeeper(nil), DefaultCodespace)
stakeKeeper := NewKeeper(capKey, bank.NewKeeper(nil), DefaultCodespace)
addr := sdk.Address([]byte("some-address"))
bi := stakeKeeper.getBondInfo(ctx, addr)
@@ -62,7 +62,7 @@ func TestBonding(t *testing.T) {
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
accountMapper := auth.NewAccountMapper(cdc, authKey, &auth.BaseAccount{})
coinKeeper := bank.NewCoinKeeper(accountMapper)
coinKeeper := bank.NewKeeper(accountMapper)
stakeKeeper := NewKeeper(capKey, coinKeeper, DefaultCodespace)
addr := sdk.Address([]byte("some-address"))
privKey := crypto.GenPrivKeyEd25519()
+26 -40
View File
@@ -8,44 +8,43 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// -------------------------
// BondMsg
//_________________________________________________________----
type BondMsg struct {
// simple bond message
type MsgBond struct {
Address sdk.Address `json:"address"`
Stake sdk.Coin `json:"coins"`
PubKey crypto.PubKey `json:"pub_key"`
}
func NewBondMsg(addr sdk.Address, stake sdk.Coin, pubKey crypto.PubKey) BondMsg {
return BondMsg{
func NewMsgBond(addr sdk.Address, stake sdk.Coin, pubKey crypto.PubKey) MsgBond {
return MsgBond{
Address: addr,
Stake: stake,
PubKey: pubKey,
}
}
func (msg BondMsg) Type() string {
return moduleName
}
//nolint
func (msg MsgBond) Type() string { return moduleName } //TODO update "stake/declarecandidacy"
func (msg MsgBond) Get(key interface{}) (value interface{}) { return nil }
func (msg MsgBond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
func (msg BondMsg) ValidateBasic() sdk.Error {
// basic validation of the bond message
func (msg MsgBond) ValidateBasic() sdk.Error {
if msg.Stake.IsZero() {
return ErrEmptyStake(DefaultCodespace)
}
if msg.PubKey == nil {
return sdk.ErrInvalidPubKey("BondMsg.PubKey must not be empty")
return sdk.ErrInvalidPubKey("MsgBond.PubKey must not be empty")
}
return nil
}
func (msg BondMsg) Get(key interface{}) interface{} {
return nil
}
func (msg BondMsg) GetSignBytes() []byte {
// get bond message sign bytes
func (msg MsgBond) GetSignBytes() []byte {
bz, err := json.Marshal(msg)
if err != nil {
panic(err)
@@ -53,43 +52,30 @@ func (msg BondMsg) GetSignBytes() []byte {
return bz
}
func (msg BondMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.Address}
}
//_______________________________________________________________
// -------------------------
// UnbondMsg
type UnbondMsg struct {
// simple unbond message
type MsgUnbond struct {
Address sdk.Address `json:"address"`
}
func NewUnbondMsg(addr sdk.Address) UnbondMsg {
return UnbondMsg{
func NewMsgUnbond(addr sdk.Address) MsgUnbond {
return MsgUnbond{
Address: addr,
}
}
func (msg UnbondMsg) Type() string {
return moduleName
}
//nolint
func (msg MsgUnbond) Type() string { return moduleName } //TODO update "stake/declarecandidacy"
func (msg MsgUnbond) Get(key interface{}) (value interface{}) { return nil }
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
func (msg MsgUnbond) ValidateBasic() sdk.Error { return nil }
func (msg UnbondMsg) ValidateBasic() sdk.Error {
return nil
}
func (msg UnbondMsg) Get(key interface{}) interface{} {
return nil
}
func (msg UnbondMsg) GetSignBytes() []byte {
// get unbond message sign bytes
func (msg MsgUnbond) GetSignBytes() []byte {
bz, err := json.Marshal(msg)
if err != nil {
panic(err)
}
return bz
}
func (msg UnbondMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.Address}
}
+4 -4
View File
@@ -14,14 +14,14 @@ func TestBondMsgValidation(t *testing.T) {
privKey := crypto.GenPrivKeyEd25519()
cases := []struct {
valid bool
bondMsg BondMsg
msgBond MsgBond
}{
{true, NewBondMsg(sdk.Address{}, sdk.Coin{"mycoin", 5}, privKey.PubKey())},
{false, NewBondMsg(sdk.Address{}, sdk.Coin{"mycoin", 0}, privKey.PubKey())},
{true, NewMsgBond(sdk.Address{}, sdk.Coin{"mycoin", 5}, privKey.PubKey())},
{false, NewMsgBond(sdk.Address{}, sdk.Coin{"mycoin", 0}, privKey.PubKey())},
}
for i, tc := range cases {
err := tc.bondMsg.ValidateBasic()
err := tc.msgBond.ValidateBasic()
if tc.valid {
assert.Nil(t, err, "%d: %+v", i, err)
} else {
+4 -28
View File
@@ -48,13 +48,7 @@ func GetCmdDeclareCandidacy(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// default to next sequence number if none provided
ctx, err = context.EnsureSequence(ctx)
if err != nil {
return err
}
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, cdc)
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
@@ -93,13 +87,7 @@ func GetCmdEditCandidacy(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// default to next sequence number if none provided
ctx, err = context.EnsureSequence(ctx)
if err != nil {
return err
}
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, cdc)
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
@@ -136,13 +124,7 @@ func GetCmdDelegate(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// default to next sequence number if none provided
ctx, err = context.EnsureSequence(ctx)
if err != nil {
return err
}
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, cdc)
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
@@ -190,13 +172,7 @@ func GetCmdUnbond(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// default to next sequence number if none provided
ctx, err = context.EnsureSequence(ctx)
if err != nil {
return err
}
res, err := ctx.SignBuildBroadcast(ctx.FromAddressName, msg, cdc)
res, err := ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, msg, cdc)
if err != nil {
return err
}
+2 -2
View File
@@ -13,7 +13,7 @@ import (
type Keeper struct {
storeKey sdk.StoreKey
cdc *wire.Codec
coinKeeper bank.CoinKeeper
coinKeeper bank.Keeper
// caches
gs Pool
@@ -23,7 +23,7 @@ type Keeper struct {
codespace sdk.CodespaceType
}
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.CoinKeeper, codespace sdk.CodespaceType) Keeper {
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
-15
View File
@@ -2,7 +2,6 @@ package stake
import (
"encoding/json"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
crypto "github.com/tendermint/go-crypto"
@@ -44,9 +43,6 @@ func NewMsgDeclareCandidacy(candidateAddr sdk.Address, pubkey crypto.PubKey,
func (msg MsgDeclareCandidacy) Type() string { return MsgType } //TODO update "stake/declarecandidacy"
func (msg MsgDeclareCandidacy) Get(key interface{}) (value interface{}) { return nil }
func (msg MsgDeclareCandidacy) GetSigners() []sdk.Address { return []sdk.Address{msg.CandidateAddr} }
func (msg MsgDeclareCandidacy) String() string {
return fmt.Sprintf("CandidateAddr{Address: %v}", msg.CandidateAddr) // XXX fix
}
// get the bytes for the message signer to sign on
func (msg MsgDeclareCandidacy) GetSignBytes() []byte {
@@ -67,7 +63,6 @@ func (msg MsgDeclareCandidacy) ValidateBasic() sdk.Error {
}
if msg.Bond.Amount <= 0 {
return ErrBadBondingAmount(DefaultCodespace)
// return sdk.ErrInvalidCoins(sdk.Coins{msg.Bond}.String())
}
empty := Description{}
if msg.Description == empty {
@@ -95,9 +90,6 @@ func NewMsgEditCandidacy(candidateAddr sdk.Address, description Description) Msg
func (msg MsgEditCandidacy) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
func (msg MsgEditCandidacy) Get(key interface{}) (value interface{}) { return nil }
func (msg MsgEditCandidacy) GetSigners() []sdk.Address { return []sdk.Address{msg.CandidateAddr} }
func (msg MsgEditCandidacy) String() string {
return fmt.Sprintf("CandidateAddr{Address: %v}", msg.CandidateAddr) // XXX fix
}
// get the bytes for the message signer to sign on
func (msg MsgEditCandidacy) GetSignBytes() []byte {
@@ -141,9 +133,6 @@ func NewMsgDelegate(delegatorAddr, candidateAddr sdk.Address, bond sdk.Coin) Msg
func (msg MsgDelegate) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
func (msg MsgDelegate) Get(key interface{}) (value interface{}) { return nil }
func (msg MsgDelegate) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
func (msg MsgDelegate) String() string {
return fmt.Sprintf("Addr{Address: %v}", msg.DelegatorAddr) // XXX fix
}
// get the bytes for the message signer to sign on
func (msg MsgDelegate) GetSignBytes() []byte {
@@ -167,7 +156,6 @@ func (msg MsgDelegate) ValidateBasic() sdk.Error {
}
if msg.Bond.Amount <= 0 {
return ErrBadBondingAmount(DefaultCodespace)
// return sdk.ErrInvalidCoins(sdk.Coins{msg.Bond}.String())
}
return nil
}
@@ -193,9 +181,6 @@ func NewMsgUnbond(delegatorAddr, candidateAddr sdk.Address, shares string) MsgUn
func (msg MsgUnbond) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
func (msg MsgUnbond) Get(key interface{}) (value interface{}) { return nil }
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
func (msg MsgUnbond) String() string {
return fmt.Sprintf("Addr{Address: %v}", msg.DelegatorAddr) // XXX fix
}
// get the bytes for the message signer to sign on
func (msg MsgUnbond) GetSignBytes() []byte {
+3 -3
View File
@@ -96,8 +96,8 @@ func makeTestCodec() *wire.Codec {
// Register Msgs
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.SendMsg{}, "test/stake/Send", nil)
cdc.RegisterConcrete(bank.IssueMsg{}, "test/stake/Issue", nil)
cdc.RegisterConcrete(bank.MsgSend{}, "test/stake/Send", nil)
cdc.RegisterConcrete(bank.MsgIssue{}, "test/stake/Issue", nil)
cdc.RegisterConcrete(MsgDeclareCandidacy{}, "test/stake/DeclareCandidacy", nil)
cdc.RegisterConcrete(MsgEditCandidacy{}, "test/stake/EditCandidacy", nil)
cdc.RegisterConcrete(MsgUnbond{}, "test/stake/Unbond", nil)
@@ -139,7 +139,7 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context
keyMain, // target store
&auth.BaseAccount{}, // prototype
).Seal()
ck := bank.NewCoinKeeper(accountMapper)
ck := bank.NewKeeper(accountMapper)
keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace)
keeper.setPool(ctx, initialPool())
keeper.setParams(ctx, defaultParams())