-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* docs: added 'tx-encoding.md' file to docs * feat: added tx encoding to frontend * docs: improved tx encoding docs * style(docs): moved tx encoding to bottom * docs: improved tx encoding * docs: improved ica tx encoding docs * docs: in ica tx encoding, added small code blocks around some interface names * docs: improved ica client docs + reordered tx encoding in sidebar * docs(ica/cmd): updated docs of 'generate-packet-data' * docs: improved ica tx encoding docs (cherry picked from commit 585e56b) Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com>
- Loading branch information
1 parent
ec30a3a
commit fd6e6a7
Showing
5 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- | ||
order: 8 | ||
order: 9 | ||
--> | ||
|
||
# Understanding Active Channels | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!-- | ||
order: 7 | ||
--> | ||
|
||
# Transaction Encoding | ||
|
||
When orchestrating an interchain account transaction, which comprises multiple `sdk.Msg` objects represented as `Any` types, the transactions must be encoded as bytes within [`InterchainAccountPacketData`](https://github.com/cosmos/ibc-go/blob/v7.2.0/proto/ibc/applications/interchain_accounts/v1/packet.proto#L21-L26). | ||
|
||
```protobuf | ||
// InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field. | ||
message InterchainAccountPacketData { | ||
Type type = 1; | ||
bytes data = 2; | ||
string memo = 3; | ||
} | ||
``` | ||
|
||
The `data` field must be encoded as a [`CosmosTx`](https://github.com/cosmos/ibc-go/blob/v7.2.0/proto/ibc/applications/interchain_accounts/v1/packet.proto#L28-L31). | ||
|
||
```protobuf | ||
// CosmosTx contains a list of sdk.Msg's. It should be used when sending transactions to an SDK host chain. | ||
message CosmosTx { | ||
repeated google.protobuf.Any messages = 1; | ||
} | ||
``` | ||
|
||
The encoding method for `CosmosTx` is determined during the channel handshake process. If the channel version [metadata's `encoding` field](https://github.com/cosmos/ibc-go/blob/v7.2.0/proto/ibc/applications/interchain_accounts/v1/metadata.proto#L22) is marked as `proto3`, then `CosmosTx` undergoes protobuf encoding. Conversely, if the field is set to `proto3json`, then [proto3 json](https://protobuf.dev/programming-guides/proto3/#json) encoding takes place, which generates a JSON representation of the protobuf message. | ||
|
||
## Protobuf Encoding | ||
|
||
Protobuf encoding serves as the standard encoding process for `CosmosTx`. This occurs if the channel handshake initiates with an empty channel version metadata or if the `encoding` field explicitly denotes `proto3`. In Golang, the protobuf encoding procedure utilizes the `proto.Marshal` function. Every protobuf autogenerated Golang type comes equipped with a `Marshal` method that can be employed to encode the message. | ||
|
||
## (Protobuf) JSON Encoding | ||
|
||
The proto3 JSON encoding presents an alternative encoding technique for `CosmosTx`. It is selected if the channel handshake begins with the channel version metadata `encoding` field labeled as `proto3json`. In Golang, the Proto3 canonical encoding in JSON is implemented by the `"github.com/cosmos/gogoproto/jsonpb"` package. Within Cosmos SDK, the `ProtoCodec` structure implements the `JSONCodec` interface, leveraging the `jsonpb` package. This method generates a JSON format as follows: | ||
|
||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"@type": "/cosmos.bank.v1beta1.MsgSend", | ||
"from_address": "cosmos1...", | ||
"to_address": "cosmos1...", | ||
"amount": [ | ||
{ | ||
"denom": "uatom", | ||
"amount": "1000000" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
Here, the `"messages"` array is populated with transactions. Each transaction is represented as a JSON object with the `@type` field denoting the transaction type and the remaining fields representing the transaction's attributes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters