Skip to content

Commit

Permalink
fixes for the documentation about handling ack for SDK <= 0.45 (cosmo…
Browse files Browse the repository at this point in the history
…s#1122)

* fixes for documentation

* review comment

Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
Carlos Rodriguez and crodriguezvega authored Mar 15, 2022
1 parent 13bc4a0 commit 4fe874e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions docs/apps/interchain-accounts/auth-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,13 @@ If the controller chain is connected to a host chain using the host module on ib

Begin by unmarshaling the acknowledgement into sdk.TxMsgData:
```go
var ack channeltypes.Acknowledgement
if err := channeltypes.SubModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
return err
}

txMsgData := &sdk.TxMsgData{}
if err := proto.Unmarshal(ack.Acknowledgement(), txMsgData); err != nil {
if err := proto.Unmarshal(ack.GetResult(), txMsgData); err != nil {
return err
}
```
Expand All @@ -232,6 +237,8 @@ The auth module should interpret the txMsgData.Data as follows:
```go
switch len(txMsgData.Data) {
case 0:
// see documentation below for SDK 0.46.x or greater
default:
for _, msgData := range txMsgData.Data {
if err := handler(msgData); err != nil {
return err
Expand All @@ -246,24 +253,24 @@ A router could be used, or more simply a switch statement.

```go
func handler(msgData sdk.MsgData) error {
switch msgData.TypeURL {
case banktypes.MsgSend:
switch msgData.MsgType {
case sdk.MsgTypeURL(&banktypes.MsgSend{}):
msgResponse := &banktypes.MsgSendResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
}

handleBankSendMsg(msgResponse)

case stakingtypes.MsgDelegate:
case sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}):
msgResponse := &stakingtypes.MsgDelegateResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
}

handleStakingDelegateMsg(msgResponse)

case transfertypes.MsgTransfer:
case sdk.MsgTypeURL(&transfertypes.MsgTransfer{}):
msgResponse := &transfertypes.MsgTransferResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
Expand All @@ -281,8 +288,8 @@ The auth module should interpret the txMsgData.Responses as follows:

```go
...
// switch statement from above continued
default:
// switch statement from above
case 0:
for _, any := range txMsgData.MsgResponses {
if err := handleAny(any); err != nil {
return err
Expand Down

0 comments on commit 4fe874e

Please sign in to comment.