-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_deposit_info_updated.go
106 lines (90 loc) · 3.41 KB
/
message_deposit_info_updated.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
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"
multichainTypes "github.com/router-protocol/sdk-go/routerchain/multichain/types"
"github.com/tendermint/tendermint/crypto/tmhash"
)
const TypeMsgDepositInfoUpdated = "deposit_info_updated"
var _ sdk.Msg = &MsgDepositInfoUpdated{}
func NewMsgDepositInfoUpdated(orchestrator string, srcChainId string, srcChainType multichainTypes.ChainType, srcTxHash string, srcTimestamp uint64, depositId uint64, contract string, eventNonce uint64, blockHeight uint64, feeAmount sdk.Int, initiatewithdrawal bool) *MsgDepositInfoUpdated {
return &MsgDepositInfoUpdated{
Orchestrator: orchestrator,
SrcChainId: srcChainId,
SrcChainType: srcChainType,
SrcTxHash: srcTxHash,
SrcTimestamp: srcTimestamp,
DepositId: depositId,
Contract: contract,
EventNonce: eventNonce,
BlockHeight: blockHeight,
FeeAmount: feeAmount,
Initiatewithdrawal: initiatewithdrawal,
}
}
func (msg *MsgDepositInfoUpdated) Route() string {
return RouterKey
}
func (msg *MsgDepositInfoUpdated) Type() string {
return TypeMsgDepositInfoUpdated
}
func (msg *MsgDepositInfoUpdated) GetSigners() []sdk.AccAddress {
orchestrator, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{orchestrator}
}
func (msg *MsgDepositInfoUpdated) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgDepositInfoUpdated) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid orchestrator address (%s)", err)
}
return nil
}
/////////////////////////////
// Implement Claim //
/////////////////////////////
// GetType returns the type of the claim
func (msg *MsgDepositInfoUpdated) GetType() attestationTypes.ClaimType {
return attestationTypes.CLAIM_DEPOSIT_INFO_UPDATED_REQUEST
}
func (msg *MsgDepositInfoUpdated) GetChainId() string {
return msg.SrcChainId
}
// Hash implements MsgDepositInfoUpdated.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 *MsgDepositInfoUpdated) ClaimHash() ([]byte, error) {
fundDepositRequestClaimHash := NewDepositInfoUpdatedRequest(
msg.SrcChainId,
msg.SrcChainType,
msg.SrcTxHash,
msg.SrcTimestamp,
msg.DepositId,
msg.Contract,
msg.EventNonce,
msg.BlockHeight,
msg.FeeAmount,
msg.Initiatewithdrawal,
msg.SrcToken,
)
out, err := proto.Marshal(fundDepositRequestClaimHash)
return tmhash.Sum([]byte(out)), err
}
func (msg MsgDepositInfoUpdated) 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
}