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

minor channel fixes #8665

Merged
merged 10 commits into from
Mar 1, 2021
24 changes: 21 additions & 3 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,10 @@

- [Msg](#ibc.applications.transfer.v1.Msg)

- [ibc/core/channel/v1/channel.proto](#ibc/core/channel/v1/channel.proto)
- [ibc/core/channel/v1/acknowledgement.proto](#ibc/core/channel/v1/acknowledgement.proto)
- [Acknowledgement](#ibc.core.channel.v1.Acknowledgement)

- [ibc/core/channel/v1/channel.proto](#ibc/core/channel/v1/channel.proto)
- [Channel](#ibc.core.channel.v1.Channel)
- [Counterparty](#ibc.core.channel.v1.Counterparty)
- [IdentifiedChannel](#ibc.core.channel.v1.IdentifiedChannel)
Expand Down Expand Up @@ -8230,10 +8232,10 @@ Msg defines the ibc/transfer Msg service.



<a name="ibc/core/channel/v1/channel.proto"></a>
<a name="ibc/core/channel/v1/acknowledgement.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/core/channel/v1/channel.proto
## ibc/core/channel/v1/acknowledgement.proto



Expand All @@ -8258,6 +8260,22 @@ https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semant



<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="ibc/core/channel/v1/channel.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/core/channel/v1/channel.proto



<a name="ibc.core.channel.v1.Channel"></a>

Expand Down
19 changes: 19 additions & 0 deletions proto/ibc/core/channel/v1/acknowledgement.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";
package ibc.core.channel.v1;

option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types";

// Acknowledgement is the recommended acknowledgement format to be used by
// app-specific protocols.
// NOTE: The field numbers 21 and 22 were explicitly chosen to avoid accidental
// conflicts with other protobuf message formats used for acknowledgements.
// The first byte of any message with this format will be the non-ASCII values
// `0xaa` (result) or `0xb2` (error). Implemented as defined by ICS:
// https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope
message Acknowledgement {
// response contains either a result or an error and must be non-empty
oneof response {
bytes result = 21;
string error = 22;
}
}
15 changes: 0 additions & 15 deletions proto/ibc/core/channel/v1/channel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,3 @@ message PacketState {
// embedded data that represents packet state.
bytes data = 4;
}

// Acknowledgement is the recommended acknowledgement format to be used by
// app-specific protocols.
// NOTE: The field numbers 21 and 22 were explicitly chosen to avoid accidental
// conflicts with other protobuf message formats used for acknowledgements.
// The first byte of any message with this format will be the non-ASCII values
// `0xaa` (result) or `0xb2` (error). Implemented as defined by ICS:
// https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope
message Acknowledgement {
// response contains either a result or an error and must be non-empty
oneof response {
bytes result = 21;
string error = 22;
}
}
50 changes: 50 additions & 0 deletions x/ibc/core/04-channel/types/acknowledgement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package types

import (
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// NewResultAcknowledgement returns a new instance of Acknowledgement using an Acknowledgement_Result
// type in the Response field.
func NewResultAcknowledgement(result []byte) Acknowledgement {
return Acknowledgement{
Response: &Acknowledgement_Result{
Result: result,
},
}
}

// NewErrorAcknowledgement returns a new instance of Acknowledgement using an Acknowledgement_Error
// type in the Response field.
func NewErrorAcknowledgement(err string) Acknowledgement {
return Acknowledgement{
Response: &Acknowledgement_Error{
Error: err,
},
}
}

// GetBytes is a helper for serialising acknowledgements
func (ack Acknowledgement) GetBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&ack))
}

// ValidateBasic performs a basic validation of the acknowledgement
func (ack Acknowledgement) ValidateBasic() error {
switch resp := ack.Response.(type) {
case *Acknowledgement_Result:
if len(resp.Result) == 0 {
return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement result cannot be empty")
}
case *Acknowledgement_Error:
if strings.TrimSpace(resp.Error) == "" {
return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement error cannot be empty")
}
default:
return sdkerrors.Wrapf(ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", resp)
}
return nil
}
Loading