forked from CosmWasm/wasmvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibc.go
127 lines (112 loc) · 5.07 KB
/
ibc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package types
type IBCEndpoint struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
}
type IBCChannel struct {
Endpoint IBCEndpoint `json:"endpoint"`
CounterpartyEndpoint IBCEndpoint `json:"counterparty_endpoint"`
Order IBCOrder `json:"order"`
Version string `json:"version"`
// optional
CounterpartyVersion string `json:"counterparty_version,omitempty"`
ConnectionID string `json:"connection_id"`
}
// TODO: test what the sdk Order.String() represents and how to parse back
// Proto files: https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/core/channel/v1/channel.proto#L69-L80
// Auto-gen code: https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/x/ibc/core/04-channel/types/channel.pb.go#L70-L101
type IBCOrder = string
// These are the only two valid values for IbcOrder
const Unordered = "ORDER_UNORDERED"
const Ordered = "ORDER_ORDERED"
// IBCTimeoutBlock Height is a monotonically increasing data type
// that can be compared against another Height for the purposes of updating and
// freezing clients.
// Ordering is (revision_number, timeout_height)
type IBCTimeoutBlock struct {
// the version that the client is currently on
// (eg. after reseting the chain this could increment 1 as height drops to 0)
Revision uint64 `json:"revision"`
// block height after which the packet times out.
// the height within the given revision
Height uint64 `json:"height"`
}
func (t IBCTimeoutBlock) IsZero() bool {
return t.Revision == 0 && t.Height == 0
}
// IBCTimeout is the timeout for an IBC packet. At least one of block and timestamp is required.
type IBCTimeout struct {
Block *IBCTimeoutBlock `json:"block"`
// Nanoseconds since UNIX epoch
Timestamp uint64 `json:"timestamp,string,omitempty"`
}
type IBCAcknowledgement struct {
Data []byte `json:"data"`
}
type IBCPacket struct {
Data []byte `json:"data"`
Src IBCEndpoint `json:"src"`
Dest IBCEndpoint `json:"dest"`
Sequence uint64 `json:"sequence"`
Timeout IBCTimeout `json:"timeout"`
}
type IBCAcknowledgementWithPacket struct {
Acknowledgement IBCAcknowledgement `json:"acknowledgement"`
OriginalPacket IBCPacket `json:"original_packet"`
}
// IBCChannelOpenResult is the raw response from the ibc_channel_open call.
// This is mirrors Rust's ContractResult<()>.
// We just check if Err == "" to see if this is success (no other data on success)
type IBCChannelOpenResult struct {
Ok *struct{} `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// This is the return value for the majority of the ibc handlers.
// That are able to dispatch messages / events on their own,
// but have no meaningful return value to the calling code.
//
// Callbacks that have return values (like ibc_receive_packet)
// or that cannot redispatch messages (like ibc_channel_open)
// will use other Response types
type IBCBasicResult struct {
Ok *IBCBasicResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// IBCBasicResponse defines the return value on a successful processing.
// This is the counterpart of [IbcBasicResponse](https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta1/packages/std/src/ibc.rs#L194-L216).
type IBCBasicResponse struct {
// Messages comes directly from the contract and is its request for action.
// If the ReplyOn value matches the result, the runtime will invoke this
// contract's `reply` entry point after execution. Otherwise, this is all
// "fire and forget".
Messages []SubMsg `json:"messages"`
// attributes for a log event to return over abci interface
Attributes []EventAttribute `json:"attributes"`
}
// This is the return value for the majority of the ibc handlers.
// That are able to dispatch messages / events on their own,
// but have no meaningful return value to the calling code.
//
// Callbacks that have return values (like receive_packet)
// or that cannot redispatch messages (like the handshake callbacks)
// will use other Response types
type IBCReceiveResult struct {
Ok *IBCReceiveResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// IBCReceiveResponse defines the return value on packet response processing.
// This "success" case should be returned even in application-level errors,
// Where the Acknowledgement bytes contain an encoded error message to be returned to
// the calling chain. (Returning IBCReceiveResult::Err will abort processing of this packet
// and not inform the calling chain).
// This is the counterpart of (IbcReceiveResponse)(https://github.com/CosmWasm/cosmwasm/blob/v0.15.0/packages/std/src/ibc.rs#L247-L267).
type IBCReceiveResponse struct {
// binary encoded data to be returned to calling chain as the acknowledgement
Acknowledgement []byte `json:"acknowledgement"`
// Messages comes directly from the contract and is it's request for action.
// If the ReplyOn value matches the result, the runtime will invoke this
// contract's `reply` entry point after execution. Otherwise, this is all
// "fire and forget".
Messages []SubMsg `json:"messages"`
Attributes []EventAttribute `json:"attributes"`
}