add term description, packetdata abstraction in 2/3

This commit is contained in:
mossid 2018-03-13 20:22:03 +01:00
parent ac004be491
commit ded9de18cf
3 changed files with 79 additions and 19 deletions

View File

@ -2,6 +2,16 @@
IBC(Inter-Blockchain Communication) protocol is used by multiple zones on Cosmos. Using IBC, the zones can send coins or arbitrary data to other zones. IBC(Inter-Blockchain Communication) protocol is used by multiple zones on Cosmos. Using IBC, the zones can send coins or arbitrary data to other zones.
## Terms
How IBC module treats incoming IBC packets is simillar with how BaseApp treats incoming transactions. Therefore, the components of IBC module have their corresponding pair in BaseApp.
| BaseApp Terms | IBC Terms |
| ------------- | ---------- |
| Router | Dispatcher |
| Tx | Packet |
| Msg | PacketData |
## MVP Specifications ## MVP Specifications
### [MVP1](./mvp1.md) ### [MVP1](./mvp1.md)
@ -18,4 +28,4 @@ Light client verification is added to verify the message from the other chain. R
### [MVP4](./mvp4.md) ### [MVP4](./mvp4.md)
ACK verification and messaging queue is implemented to make it failsafe. Modules will register callback to handle failure when they register handlers. ACK verification / timeout handler helper functions and messaging queue are implemented to make it failsafe. Callbacks will be registered to the dispatcher to handle failure when they register handlers.

View File

@ -11,25 +11,43 @@ IBC module will store its own router for handling custom incoming msgs. `IBCPush
```golang ```golang
// User facing API // User facing API
type IBCPacket struct { type Packet struct {
Data PacketData
SrcChain string
DestChain string
}
type PacketData interface {
Type() string
ValidateBasic() sdk.Error
}
type TransferPacketData struct {
DestAddr sdk.Address DestAddr sdk.Address
Coins sdk.Coins Coins sdk.Coins
SrcChain string
DestChain string
} }
// Implements sdk.Msg // Implements sdk.Msg
type IBCTransferMsg struct { type IBCTransferMsg struct {
IBCPacket Packet
} }
// Implements sdk.Msg // Implements sdk.Msg
type IBCReceiveMsg struct { type IBCReceiveMsg struct {
IBCPacket Packet
} }
// Internal API // Internal API
type rule struct {
r string
f func(sdk.Context, IBCPacket) sdk.Result
}
type Dispatcher struct {
rules []rule
}
func NewHandler(dispatcher Dispatcher, ibcm IBCMapper) sdk.Handler func NewHandler(dispatcher Dispatcher, ibcm IBCMapper) sdk.Handler
type IBCMapper struct { type IBCMapper struct {

View File

@ -6,29 +6,52 @@
### IBC Module ### IBC Module
// Implements sdk.Msg
type IBCTransferMsg struct {
Packet
}
// Implements sdk.Msg
type IBCReceiveMsg struct {
Packet
}
// Internal API
```golang ```golang
// User facing API // User facing API
type IBCTransferData struct { type Packet struct {
Data PacketData
SrcChain string
DestChain string
}
type PacketData interface {
Type() string
ValidateBasic() sdk.Error
}
type TransferPacketData struct {
SrcAddr sdk.Address SrcAddr sdk.Address
DestAddr sdk.Address DestAddr sdk.Address
Coins sdk.Coins Coins sdk.Coins
} }
// Implements ibc.PacketData // Implements sdk.Msg
type IBCPacket struct { type IBCTransferMsg struct {
IBCData Packet
} }
// Implements ibc.PacketData // Implements sdk.Msg
type IBCReceivePacket struct { type IBCReceiveMsg struct {
IBCData Packet
} Proof iavl.Proof
FromChainID string
type Packet struct { FromChainHeight uint64
Data PacketData
SrcChain string
DestChain string
} }
type RootOfTrust struct { type RootOfTrust struct {
@ -49,6 +72,15 @@ type IBCUpdateMsg struct {
// Internal API // Internal API
type rule struct {
r string
f func(sdk.Context, IBCPacket) sdk.Result
}
type Dispatcher struct {
rules []rule
}
func NewHandler(dispatcher Dispatcher, ibcm IBCMapper) sdk.Handler func NewHandler(dispatcher Dispatcher, ibcm IBCMapper) sdk.Handler
type IBCMapper struct { type IBCMapper struct {