From d6a01ba3a42d375b3f6267111cbbcaa766f610ab Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 27 Jun 2018 08:24:40 -0400 Subject: [PATCH] minor updates in App2 --- docs/core/app2.md | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/docs/core/app2.md b/docs/core/app2.md index f97448b6ca..f9a2e060f3 100644 --- a/docs/core/app2.md +++ b/docs/core/app2.md @@ -62,25 +62,50 @@ Amino can also be used for persistent storage of interfaces. To use Amino, simply create a codec, and then register types: ``` -cdc := wire.NewCodec() - -cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil) -cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil) +func NewCodec() *wire.Codec { + cdc := wire.NewCodec() + cdc.RegisterInterface((*sdk.Msg)(nil), nil) + cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil) + cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil) + return cdc +} ``` -TODO: JSON, types table +Amino supports encoding and decoding in both a binary and JSON format. +See the [codec API docs](https://godoc.org/github.com/tendermint/go-amino#Codec) for more details. + +TODO: Update Amino and demo `cdc.PrintTypes` ## Tx -TODO +Now that we're using Amino, we can embed the `Msg` interface directly in our +`Tx`. We can also add a public key and a signature for authentication. + +```go +// Simple tx to wrap the Msg. +type app2Tx struct { + sdk.Msg + + PubKey crypto.PubKey + Signature crypto.Signature +} + +// This tx only has one Msg. +func (tx app2Tx) GetMsgs() []sdk.Msg { + return []sdk.Msg{tx.Msg} +} +``` + +We don't need a custom TxDecoder function anymore, since we're just using the +Amino codec! ## AnteHandler -Now that we have an implementation of `Tx` that includes more than just the Msgs, +Now that we have an implementation of `Tx` that includes more than just the Msg, we need to specify how that extra information is validated and processed. This is the role of the `AnteHandler`. The word `ante` here denotes "before", as the -`AnteHandler` is run before a `Handler`. While an app may have many Handlers, -one for each set of messages, it may have only a single `AnteHandler` that +`AnteHandler` is run before a `Handler`. While an app can have many Handlers, +one for each set of messages, it can have only a single `AnteHandler` that corresponds to its single implementation of `Tx`.