-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathtypes.go
163 lines (145 loc) · 5.23 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package types
import (
"bytes"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
ethbridge "github.com/Sifchain/sifnode/x/ethbridge/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Event enum containing supported chain events
type Event byte
const (
// Unsupported is an invalid Cosmos or Ethereum event
Unsupported Event = iota
// MsgBurn is a Cosmos msg of type MsgBurn
MsgBurn
// MsgLock is a Cosmos msg of type MsgLock
MsgLock
// LogLock is for Ethereum event LogLock
LogLock
// LogBurn is for Ethereum event LogBurn
LogBurn
// LogNewProphecyClaim is an Ethereum event named 'LogNewProphecyClaim'
LogNewProphecyClaim
)
// String returns the event type as a string
func (d Event) String() string {
return [...]string{"unsupported", "burn", "lock", "LogLock", "LogBurn", "LogNewProphecyClaim"}[d]
}
// EthereumEvent struct is used by LogLock and LogBurn
type EthereumEvent struct {
EthereumChainID *big.Int
BridgeContractAddress common.Address
ID [32]byte
From common.Address
To []byte
Token common.Address
Symbol string
Value *big.Int
Nonce *big.Int
ClaimType ethbridge.ClaimType
}
// Equal two events
func (e EthereumEvent) Equal(other EthereumEvent) bool {
return e.EthereumChainID == other.EthereumChainID &&
e.BridgeContractAddress == other.BridgeContractAddress &&
bytes.Equal(e.ID[:], other.ID[:]) &&
e.From == other.From &&
bytes.Equal(e.To, other.To) &&
e.Symbol == other.Symbol &&
e.Value.Cmp(other.Value) == 0 &&
e.Nonce.Cmp(other.Nonce) == 0 &&
e.ClaimType == other.ClaimType
}
// String implements fmt.Stringer
func (e EthereumEvent) String() string {
return fmt.Sprintf("\nChain ID: %v\nBridge contract address: %v\nToken symbol: %v\nToken "+
"contract address: %v\nSender: %v\nRecipient: %v\nValue: %v\nNonce: %v\nClaim type: %v",
e.EthereumChainID, e.BridgeContractAddress.Hex(), e.Symbol, e.Token.Hex(), e.From.Hex(),
string(e.To), e.Value, e.Nonce, e.ClaimType.String())
}
// ProphecyClaimEvent struct which represents a LogNewProphecyClaim event
type ProphecyClaimEvent struct {
CosmosSender []byte
Symbol string
ProphecyID *big.Int
Amount sdk.Int
EthereumReceiver common.Address
ValidatorAddress common.Address
TokenAddress common.Address
ClaimType uint8
}
// NewProphecyClaimEvent creates a new ProphecyClaimEvent
func NewProphecyClaimEvent(cosmosSender []byte, symbol string, prophecyID *big.Int, amount sdk.Int, ethereumReceiver,
validatorAddress, tokenAddress common.Address, claimType uint8) ProphecyClaimEvent {
return ProphecyClaimEvent{
CosmosSender: cosmosSender,
Symbol: symbol,
ProphecyID: prophecyID,
Amount: amount,
EthereumReceiver: ethereumReceiver,
ValidatorAddress: validatorAddress,
TokenAddress: tokenAddress,
ClaimType: claimType,
}
}
// String implements fmt.Stringer
func (p ProphecyClaimEvent) String() string {
return fmt.Sprintf("\nProphecy ID: %v\nClaim Type: %v\nSender: %v\n"+
"Recipient: %v\nSymbol: %v\nToken: %v\nAmount: %v\nValidator: %v\n\n",
p.ProphecyID, p.ClaimType, string(p.CosmosSender), p.EthereumReceiver.Hex(),
p.Symbol, p.TokenAddress.Hex(), p.Amount, p.ValidatorAddress.Hex())
}
// CosmosMsg contains data from MsgBurn and MsgLock events
type CosmosMsg struct {
CosmosSender []byte
CosmosSenderSequence *big.Int
Symbol string
Amount sdk.Int
EthereumReceiver common.Address
ClaimType Event
}
// NewCosmosMsg creates a new CosmosMsg
func NewCosmosMsg(claimType Event, cosmosSender []byte, cosmosSenderSequence *big.Int, ethereumReceiver common.Address, symbol string,
amount sdk.Int) CosmosMsg {
return CosmosMsg{
ClaimType: claimType,
CosmosSender: cosmosSender,
CosmosSenderSequence: cosmosSenderSequence,
EthereumReceiver: ethereumReceiver,
Symbol: symbol,
Amount: amount,
}
}
// String implements fmt.Stringer
func (c CosmosMsg) String() string {
if c.ClaimType == MsgLock {
return fmt.Sprintf("\nClaim Type: %v\nCosmos Sender: %v\nEthereum Recipient: %v"+
"\nSymbol: %v\nAmount: %v\n",
c.ClaimType.String(), string(c.CosmosSender), c.EthereumReceiver.Hex(), c.Symbol, c.Amount)
}
return fmt.Sprintf("\nClaim Type: %v\nCosmos Sender: %v\nEthereum Recipient: %v"+
"\nSymbol: %v\nAmount: %v\n",
c.ClaimType.String(), string(c.CosmosSender), c.EthereumReceiver.Hex(), c.Symbol, c.Amount)
}
// CosmosMsgAttributeKey enum containing supported attribute keys
type CosmosMsgAttributeKey int
const (
// UnsupportedAttributeKey unsupported attribute key
UnsupportedAttributeKey CosmosMsgAttributeKey = iota
// CosmosSender sender's address on Cosmos network
CosmosSender
// CosmosSenderSequence sender's sequence on Cosmos network
CosmosSenderSequence
// EthereumReceiver receiver's address on Ethereum network
EthereumReceiver
// Amount is coin's value
Amount
// Symbol is the coin type
Symbol
)
// String returns the event type as a string
func (d CosmosMsgAttributeKey) String() string {
return [...]string{"unsupported", "cosmos_sender", "cosmos_sender_sequence", "ethereum_receiver", "amount", "symbol"}[d]
}