diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d786bf3..64f168505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ BREAKING CHANGES * AltBytes renamed to Memo, now a string, max 100 characters, costs a bit of gas * Transactions now take a list of Messages * Signers of a transaction now only sign over their account and sequence number +* Removed MsgChangePubKey from auth +* Removed setPubKey from account mapper FEATURES * [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag diff --git a/examples/basecoin/app/app.go b/examples/basecoin/app/app.go index f654ba05e..06ccd4a0c 100644 --- a/examples/basecoin/app/app.go +++ b/examples/basecoin/app/app.go @@ -77,7 +77,6 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp { // register message routes app.Router(). - AddRoute("auth", auth.NewHandler(app.accountMapper)). AddRoute("bank", bank.NewHandler(app.coinKeeper)). AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)). AddRoute("stake", stake.NewHandler(app.stakeKeeper)) diff --git a/x/auth/handler.go b/x/auth/handler.go deleted file mode 100644 index 764c6f7a2..000000000 --- a/x/auth/handler.go +++ /dev/null @@ -1,34 +0,0 @@ -package auth - -import ( - "reflect" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// NewHandler returns a handler for "baseaccount" type messages. -func NewHandler(am AccountMapper) sdk.Handler { - return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { - switch msg := msg.(type) { - case MsgChangeKey: - return handleMsgChangeKey(ctx, am, msg) - default: - errMsg := "Unrecognized baseaccount Msg type: " + reflect.TypeOf(msg).Name() - return sdk.ErrUnknownRequest(errMsg).Result() - } - } -} - -// Handle MsgChangeKey -// Should be very expensive, because once this happens, an account is un-prunable -func handleMsgChangeKey(ctx sdk.Context, am AccountMapper, msg MsgChangeKey) sdk.Result { - - err := am.SetPubKey(ctx, msg.Address, msg.NewPubKey) - if err != nil { - return err.Result() - } - - return sdk.Result{ - Tags: sdk.NewTags("action", []byte("changePubkey"), "address", msg.Address.Bytes(), "pubkey", msg.NewPubKey.Bytes()), - } -} diff --git a/x/auth/mapper.go b/x/auth/mapper.go index b4364f768..4baa9c466 100644 --- a/x/auth/mapper.go +++ b/x/auth/mapper.go @@ -100,17 +100,6 @@ func (am AccountMapper) GetPubKey(ctx sdk.Context, addr sdk.Address) (crypto.Pub return acc.GetPubKey(), nil } -// Sets the PubKey of the account at address -func (am AccountMapper) SetPubKey(ctx sdk.Context, addr sdk.Address, newPubKey crypto.PubKey) sdk.Error { - acc := am.GetAccount(ctx, addr) - if acc == nil { - return sdk.ErrUnknownAddress(addr.String()) - } - acc.SetPubKey(newPubKey) - am.SetAccount(ctx, acc) - return nil -} - // Returns the Sequence of the account at address func (am AccountMapper) GetSequence(ctx sdk.Context, addr sdk.Address) (int64, sdk.Error) { acc := am.GetAccount(ctx, addr) diff --git a/x/auth/mock/auth_app_test.go b/x/auth/mock/auth_app_test.go index bd56a538c..4442200f1 100644 --- a/x/auth/mock/auth_app_test.go +++ b/x/auth/mock/auth_app_test.go @@ -3,14 +3,11 @@ package mock import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" - abci "github.com/tendermint/abci/types" crypto "github.com/tendermint/go-crypto" ) @@ -35,64 +32,7 @@ func getMockApp(t *testing.T) *App { coinKeeper := bank.NewKeeper(mapp.AccountMapper) mapp.Router().AddRoute("bank", bank.NewHandler(coinKeeper)) - mapp.Router().AddRoute("auth", auth.NewHandler(mapp.AccountMapper)) require.NoError(t, mapp.CompleteSetup([]*sdk.KVStoreKey{})) return mapp } - -func TestMsgChangePubKey(t *testing.T) { - mapp := getMockApp(t) - - // Construct some genesis bytes to reflect basecoin/types/AppAccount - // Give 77 foocoin to the first key - coins := sdk.Coins{sdk.NewCoin("foocoin", 77)} - acc1 := &auth.BaseAccount{ - Address: addr1, - Coins: coins, - } - accs := []auth.Account{acc1} - - // Construct genesis state - SetGenesis(mapp, accs) - - // A checkTx context (true) - ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) - res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) - assert.Equal(t, acc1, res1.(*auth.BaseAccount)) - - // Run a CheckDeliver - SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1}, []int64{0}, []int64{0}, true, priv1) - - // Check balances - CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("foocoin", 67)}) - CheckBalance(t, mapp, addr2, sdk.Coins{sdk.NewCoin("foocoin", 10)}) - - changePubKeyMsg := auth.MsgChangeKey{ - Address: addr1, - NewPubKey: priv2.PubKey(), - } - - mapp.BeginBlock(abci.RequestBeginBlock{}) - ctxDeliver := mapp.BaseApp.NewContext(false, abci.Header{}) - acc2 := mapp.AccountMapper.GetAccount(ctxDeliver, addr1) - - // send a MsgChangePubKey - SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{changePubKeyMsg}, []int64{0}, []int64{1}, true, priv1) - acc2 = mapp.AccountMapper.GetAccount(ctxDeliver, addr1) - - assert.True(t, priv2.PubKey().Equals(acc2.GetPubKey())) - - // signing a SendMsg with the old privKey should be an auth error - mapp.BeginBlock(abci.RequestBeginBlock{}) - tx := GenTx([]sdk.Msg{sendMsg1}, []int64{0}, []int64{2}, priv1) - res := mapp.Deliver(tx) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) - - // resigning the tx with the new correct priv key should work - SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1}, []int64{0}, []int64{2}, true, priv2) - - // Check balances - CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("foocoin", 57)}) - CheckBalance(t, mapp, addr2, sdk.Coins{sdk.NewCoin("foocoin", 20)}) -} diff --git a/x/auth/msgs.go b/x/auth/msgs.go deleted file mode 100644 index 3eb5cc8ba..000000000 --- a/x/auth/msgs.go +++ /dev/null @@ -1,41 +0,0 @@ -package auth - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - crypto "github.com/tendermint/go-crypto" -) - -// MsgChangeKey - high level transaction of the auth module -type MsgChangeKey struct { - Address sdk.Address `json:"address"` - NewPubKey crypto.PubKey `json:"public_key"` -} - -var _ sdk.Msg = MsgChangeKey{} - -// NewMsgChangeKey - msg to claim an account and set the PubKey -func NewMsgChangeKey(addr sdk.Address, pubkey crypto.PubKey) MsgChangeKey { - return MsgChangeKey{Address: addr, NewPubKey: pubkey} -} - -// Implements Msg. -func (msg MsgChangeKey) Type() string { return "auth" } - -// Implements Msg. -func (msg MsgChangeKey) ValidateBasic() sdk.Error { - return nil -} - -// Implements Msg. -func (msg MsgChangeKey) GetSignBytes() []byte { - b, err := msgCdc.MarshalJSON(msg) // XXX: ensure some canonical form - if err != nil { - panic(err) - } - return b -} - -// Implements Msg. -func (msg MsgChangeKey) GetSigners() []sdk.Address { - return []sdk.Address{msg.Address} -} diff --git a/x/auth/msgs_test.go b/x/auth/msgs_test.go deleted file mode 100644 index 30c98b073..000000000 --- a/x/auth/msgs_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package auth - -import ( - "testing" - - "github.com/stretchr/testify/assert" - crypto "github.com/tendermint/go-crypto" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestNewMsgChangeKey(t *testing.T) {} - -func TestMsgChangeKeyType(t *testing.T) { - addr1 := sdk.Address([]byte("input")) - newPubKey := crypto.GenPrivKeyEd25519().PubKey() - - var msg = MsgChangeKey{ - Address: addr1, - NewPubKey: newPubKey, - } - - assert.Equal(t, msg.Type(), "auth") -} - -func TestMsgChangeKeyValidation(t *testing.T) { - - addr1 := sdk.Address([]byte("input")) - - // emptyPubKey := crypto.PubKeyEd25519{} - // var msg = MsgChangeKey{ - // Address: addr1, - // NewPubKey: emptyPubKey, - // } - - // // fmt.Println(msg.NewPubKey.Empty()) - // fmt.Println(msg.NewPubKey.Bytes()) - - // assert.NotNil(t, msg.ValidateBasic()) - - newPubKey := crypto.GenPrivKeyEd25519().PubKey() - msg := MsgChangeKey{ - Address: addr1, - NewPubKey: newPubKey, - } - assert.Nil(t, msg.ValidateBasic()) -} diff --git a/x/auth/wire.go b/x/auth/wire.go index 6e430be4c..e22151101 100644 --- a/x/auth/wire.go +++ b/x/auth/wire.go @@ -8,7 +8,6 @@ import ( func RegisterWire(cdc *wire.Codec) { cdc.RegisterInterface((*Account)(nil), nil) cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil) - cdc.RegisterConcrete(MsgChangeKey{}, "auth/ChangeKey", nil) cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil) }