Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for the documentation about handling ack for SDK <= 0.45 #1122

Merged
merged 4 commits into from
Mar 15, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 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,30 @@ A router could be used, or more simply a switch statement.

```go
func handler(msgData sdk.MsgData) error {
switch msgData.TypeURL {
case banktypes.MsgSend:
sdkMsgs := []sdk.Msg{
&banktypes.MsgSend{},
&stakingtypes.MsgDelegate{},
&transfertypes.MsgTransfer{},
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
}

switch msgData.MsgType {
case sdk.MsgTypeURL(sdkMsgs[0]):
msgResponse := &banktypes.MsgSendResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
}

handleBankSendMsg(msgResponse)

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

handleStakingDelegateMsg(msgResponse)

case transfertypes.MsgTransfer:
case sdk.MsgTypeURL(sdkMsgs[2]):
msgResponse := &transfertypes.MsgTransferResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
Expand All @@ -281,8 +294,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