Merge pull request #431 from cosmos/feature/strongly_typed_msgs

Strongly typed transactions in handlers
This commit is contained in:
Ethan Buchman 2018-02-17 16:53:53 -05:00 committed by GitHub
commit 8fc12a5265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -62,9 +62,14 @@ func main() {
func DummyHandler(storeKey sdk.StoreKey) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
dTx, ok := msg.(dummyTx)
if !ok {
panic("DummyHandler should only receive dummyTx")
}
// tx is already unmarshalled
key := msg.Get("key").([]byte)
value := msg.Get("value").([]byte)
key := dTx.key
value := dTx.value
store := ctx.KVStore(storeKey)
store.Set(key, value)

View File

@ -56,6 +56,8 @@ func (tx dummyTx) GetFeePayer() crypto.Address {
return nil
}
// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has
// all the signatures and can be used to authenticate.
func decodeTx(txBytes []byte) (sdk.Tx, sdk.Error) {
var tx sdk.Tx