-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_funds_paid.go
112 lines (94 loc) · 3.42 KB
/
message_funds_paid.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
package types
import (
"github.com/cometbft/cometbft/crypto/tmhash"
proto "github.com/cosmos/gogoproto/proto"
attestationTypes "github.com/router-protocol/sdk-go/routerchain/attestation/types"
multichainTypes "github.com/router-protocol/sdk-go/routerchain/multichain/types"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgFundsPaid = "funds_paid"
var _ sdk.Msg = &MsgFundsPaid{}
func NewMsgFundsPaid(orchestrator string, srcChainId string, srcChainType multichainTypes.ChainType, srcTxHash string, srcTimestamp uint64, contract string, eventNonce uint64, blockHeight uint64, messageHash []byte, forwarder string, forwarderRouterAddr string, execData []byte, execStatus bool) *MsgFundsPaid {
return &MsgFundsPaid{
Orchestrator: orchestrator,
SrcChainId: srcChainId,
SrcChainType: srcChainType,
SrcTxHash: srcTxHash,
SrcTimestamp: srcTimestamp,
Contract: contract,
EventNonce: eventNonce,
BlockHeight: blockHeight,
MessageHash: messageHash,
Forwarder: forwarder,
ForwarderRouterAddr: forwarderRouterAddr,
ExecData: execData,
ExecStatus: execStatus,
}
}
func (msg *MsgFundsPaid) Route() string {
return RouterKey
}
func (msg *MsgFundsPaid) Type() string {
return TypeMsgFundsPaid
}
func (msg *MsgFundsPaid) GetSigners() []sdk.AccAddress {
orchestrator, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{orchestrator}
}
func (msg *MsgFundsPaid) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgFundsPaid) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid orchestrator address (%s)", err)
}
return nil
}
/////////////////////////////
// Implement Claim //
/////////////////////////////
// GetType returns the type of the claim
func (msg *MsgFundsPaid) GetType() attestationTypes.ClaimType {
return attestationTypes.CLAIM_TYPE_FUND_PAID_REQUEST
}
func (msg *MsgFundsPaid) GetChainId() string {
return msg.SrcChainId
}
// Hash implements MsgFundsPaid.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 *MsgFundsPaid) ClaimHash() ([]byte, error) {
fundPaidRequestClaimHash := NewFundPaidRequestClaimHash(
msg.SrcChainId,
msg.SrcChainType,
msg.SrcTxHash,
msg.SrcTimestamp,
msg.Contract,
msg.EventNonce,
msg.BlockHeight,
msg.MessageHash,
msg.Forwarder,
msg.ForwarderRouterAddr,
msg.ExecData,
msg.ExecStatus,
)
out, err := proto.Marshal(fundPaidRequestClaimHash)
return tmhash.Sum([]byte(out)), err
}
func (msg MsgFundsPaid) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic("MsgInboundRequest failed ValidateBasic! Should have been handled earlier")
}
val, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
return val
}