-
Notifications
You must be signed in to change notification settings - Fork 1
/
crosschain_request.go
134 lines (111 loc) · 3.79 KB
/
crosschain_request.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
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/gogo/protobuf/proto"
multichainTypes "github.com/router-protocol/sdk-go/routerchain/multichain/types"
"github.com/tendermint/tendermint/crypto/tmhash"
)
func (c CrosschainRequest) ValidateBasic() error {
//TODO: Validate id?
//TODO: Validate cosmos sender?
return nil
}
// Hash implements IncomingTx.Hash
// modify this with care as it is security sensitive. If an element of the claim is not in this hash a single hostile validator
// could engineer a hash collision and execute a version of the claim with any unhashed data changed to benefit them.
// note that the Orchestrator is the only field excluded from this hash, this is because that value is used higher up in the store
// structure for who has made what claim and is verified by the msg ante-handler for signatures
func (msg *CrosschainRequest) ClaimHash() ([]byte, error) {
crosschainRequestClaimHash := NewCrosschainRequestClaimHash(
msg.SrcChainId,
msg.Contract,
msg.RequestIdentifier,
msg.BlockHeight,
msg.SourceTxHash,
msg.SrcTimestamp,
msg.SrcTxOrigin,
msg.RouteAmount,
msg.RouteRecipient,
msg.DestChainId,
msg.RequestSender,
msg.RequestMetadata,
msg.RequestPacket,
msg.SrcChainType,
msg.DestChainType)
out, err := proto.Marshal(crosschainRequestClaimHash)
return tmhash.Sum([]byte(out)), err
}
func (msg *CrosschainRequest) ExecuteMsgType() ExecuteMsgType {
// Routerchain <-> Cosmos communication is only using IBC
if (msg.DestChainType == multichainTypes.CHAIN_TYPE_COSMOS) || (msg.DestChainType == multichainTypes.CHAIN_TYPE_ROUTER && msg.SrcChainType == multichainTypes.CHAIN_TYPE_COSMOS) {
return EXECUTE_IBC_MSG
} else { // Routerchain <-> EVM/Near communication is only through Gateway contract call
return EXECUTE_CONTRACT_CALL
}
}
func (msg *CrosschainRequest) RelayerType() RelayerType {
switch msg.DestChainType {
case multichainTypes.CHAIN_TYPE_COSMOS:
return IBC_RELAYER
case multichainTypes.CHAIN_TYPE_ROUTER:
return RELAYER_NONE
default:
return ROUTER_RELAYER
}
}
func (msg *CrosschainRequest) AckRelayerType() RelayerType {
switch msg.SrcChainType {
case multichainTypes.CHAIN_TYPE_COSMOS:
return IBC_RELAYER
case multichainTypes.CHAIN_TYPE_ROUTER:
return RELAYER_NONE
default:
return ROUTER_RELAYER
}
}
func (msg *CrosschainRequest) IsConfirmationRequired() bool {
// Skip Crosstalk requests as it's already confirmed by Orchestrator when MsgCrosschainRequest is submitted
if msg.RelayerType() == ROUTER_RELAYER && msg.WorkflowType() != CROSSTALK {
return true
}
return false
}
func (msg *CrosschainRequest) WorkflowType() WorkflowType {
// If request is to_router, then it's Inbound
if msg.DestChainType == multichainTypes.CHAIN_TYPE_ROUTER {
return INBOUND
}
// If request is from_router, then it's Outbound
if msg.SrcChainType == multichainTypes.CHAIN_TYPE_ROUTER {
return OUTBOUND
}
// If request is via_router, then it's Crosstalk
return CROSSTALK
}
func (msg *CrosschainRequest) ValidationType() ValidationType {
switch msg.SrcChainType {
case multichainTypes.CHAIN_TYPE_COSMOS:
return IBC_VALIDATION
case multichainTypes.CHAIN_TYPE_ROUTER:
return DEFAULT_VALIDATION
default:
return ORCHESTRATOR_VALIDATION
}
}
func (msg *CrosschainRequest) AckValidationType() ValidationType {
switch msg.DestChainType {
case multichainTypes.CHAIN_TYPE_COSMOS:
return IBC_VALIDATION
case multichainTypes.CHAIN_TYPE_ROUTER:
return DEFAULT_VALIDATION
default:
return ORCHESTRATOR_VALIDATION
}
}
// GetBytes is a helper for serialising
func (msg *CrosschainRequest) GetBytes() []byte {
cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
return sdk.MustSortJSON(cdc.MustMarshalJSON(msg))
}