forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
113 lines (92 loc) · 2.24 KB
/
types.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
package ibc
import (
sdk "github.com/cosmos/cosmos-sdk/types"
wire "github.com/cosmos/cosmos-sdk/wire"
)
// ------------------------------
// IBCPacket
// IBCPacket defines a piece of data that can be send between two separate
// blockchains.
type IBCPacket struct {
SrcAddr sdk.Address
DestAddr sdk.Address
Coins sdk.Coins
SrcChain string
DestChain string
}
func NewIBCPacket(srcAddr sdk.Address, destAddr sdk.Address, coins sdk.Coins,
srcChain string, destChain string) IBCPacket {
return IBCPacket{
SrcAddr: srcAddr,
DestAddr: destAddr,
Coins: coins,
SrcChain: srcChain,
DestChain: destChain,
}
}
func (ibcp IBCPacket) ValidateBasic() sdk.Error {
if ibcp.SrcChain == ibcp.DestChain {
return ErrIdenticalChains().Trace("")
}
if !ibcp.Coins.IsValid() {
return sdk.ErrInvalidCoins("")
}
return nil
}
// ----------------------------------
// IBCTransferMsg
// IBCTransferMsg defines how another module can send an IBCPacket.
type IBCTransferMsg struct {
IBCPacket
}
func (msg IBCTransferMsg) Type() string {
return "ibc"
}
func (msg IBCTransferMsg) Get(key interface{}) interface{} {
return nil
}
func (msg IBCTransferMsg) GetSignBytes() []byte {
cdc := wire.NewCodec()
bz, err := cdc.MarshalBinary(msg)
if err != nil {
panic(err)
}
return bz
}
func (msg IBCTransferMsg) ValidateBasic() sdk.Error {
return msg.IBCPacket.ValidateBasic()
}
// x/bank/tx.go SendMsg.GetSigners()
func (msg IBCTransferMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.SrcAddr}
}
// ----------------------------------
// IBCReceiveMsg
// IBCReceiveMsg defines the message that a relayer uses to post an IBCPacket
// to the destination chain.
type IBCReceiveMsg struct {
IBCPacket
Relayer sdk.Address
Sequence int64
}
func (msg IBCReceiveMsg) Type() string {
return "ibc"
}
func (msg IBCReceiveMsg) Get(key interface{}) interface{} {
return nil
}
func (msg IBCReceiveMsg) GetSignBytes() []byte {
cdc := wire.NewCodec()
bz, err := cdc.MarshalBinary(msg)
if err != nil {
panic(err)
}
return bz
}
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error {
return msg.IBCPacket.ValidateBasic()
}
// x/bank/tx.go SendMsg.GetSigners()
func (msg IBCReceiveMsg) GetSigners() []sdk.Address {
return []sdk.Address{msg.Relayer}
}