/
message_crosschain_ack_receipt.go
116 lines (98 loc) · 3.9 KB
/
message_crosschain_ack_receipt.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
proto "github.com/gogo/protobuf/proto"
attestationTypes "github.com/router-protocol/sdk-go/routerchain/attestation/types"
"github.com/tendermint/tendermint/crypto/tmhash"
)
const TypeMsgCrosschainAckReceipt = "crosschain_ack_receipt"
var _ sdk.Msg = &MsgCrosschainAckReceipt{}
func NewMsgCrosschainAckReceipt(orchestrator string, ackReceiptSrcChainId string, contract string, ackReceiptIdentifier uint64, ackReceiptBlockHeight uint64, ackReceiptTxHash string, relayerRouterAddress string, requestIdentifier uint64, ackSrcChainId string, ackRequestIdentifier uint64, feeConsumed uint64, ackExecData []byte, ackExecStatus bool) *MsgCrosschainAckReceipt {
return &MsgCrosschainAckReceipt{
Orchestrator: orchestrator,
AckReceiptSrcChainId: ackReceiptSrcChainId,
Contract: contract,
AckReceiptIdentifier: ackReceiptIdentifier,
AckReceiptBlockHeight: ackReceiptBlockHeight,
AckReceiptTxHash: ackReceiptTxHash,
RelayerRouterAddress: relayerRouterAddress,
RequestIdentifier: requestIdentifier,
AckSrcChainId: ackSrcChainId,
AckRequestIdentifier: ackRequestIdentifier,
FeeConsumed: feeConsumed,
AckExecData: ackExecData,
AckExecStatus: ackExecStatus,
}
}
func (msg *MsgCrosschainAckReceipt) Route() string {
return RouterKey
}
func (msg *MsgCrosschainAckReceipt) Type() string {
return TypeMsgCrosschainAckReceipt
}
func (msg *MsgCrosschainAckReceipt) GetSigners() []sdk.AccAddress {
orchestrator, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{orchestrator}
}
func (msg *MsgCrosschainAckReceipt) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgCrosschainAckReceipt) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid orchestrator address (%s)", err)
}
return nil
}
func (msg *MsgCrosschainAckReceipt) GetChainId() string {
return msg.AckReceiptSrcChainId
}
func (msg *MsgCrosschainAckReceipt) GetBlockHeight() uint64 {
return msg.AckReceiptBlockHeight
}
func (msg *MsgCrosschainAckReceipt) GetEventNonce() uint64 {
return msg.AckReceiptIdentifier
}
/////////////////////////////
// Implement Claim //
/////////////////////////////
// GetType returns the type of the claim
func (msg *MsgCrosschainAckReceipt) GetType() attestationTypes.ClaimType {
return attestationTypes.CLAIM_TYPE_CROSSCHAIN_ACK_RECEIPT
}
// Hash implements MsgCrosschainRequest.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 *MsgCrosschainAckReceipt) ClaimHash() ([]byte, error) {
crosschainAckReceiptClaimHash := NewCrosschainAckReceiptClaimHash(
msg.AckReceiptSrcChainId,
msg.Contract,
msg.AckReceiptIdentifier,
msg.AckReceiptBlockHeight,
msg.AckReceiptTxHash,
msg.RelayerRouterAddress,
msg.RequestIdentifier,
msg.AckSrcChainId,
msg.AckRequestIdentifier,
msg.FeeConsumed,
msg.AckExecData,
msg.AckExecStatus,
)
out, err := proto.Marshal(crosschainAckReceiptClaimHash)
return tmhash.Sum([]byte(out)), err
}
func (msg MsgCrosschainAckReceipt) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgCrosschainRequest failed ValidateBasic! Should have been handled earlier")
}
val, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
return val
}