forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
238 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package auth | ||
|
||
import ( | ||
"reflect" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// NewHandler returns a handler for "auth" 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 auth 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() | ||
} | ||
|
||
// TODO: add some tags so we can search it! | ||
return sdk.Result{} // TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package auth | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/tendermint/go-crypto" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// 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 := json.Marshal(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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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()) | ||
} |