-
Notifications
You must be signed in to change notification settings - Fork 136
/
attestation.go
62 lines (54 loc) · 1.7 KB
/
attestation.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
package types
import (
sdkerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
)
func (m Attestation) ValidateBasic(cdc codec.BinaryCodec) error {
if m.Observed && len(m.Votes) == 0 {
return sdkerrors.Wrap(ErrInvalidAttestation, "must be voted on to be observed")
}
for _, validator := range m.Votes {
_, err := sdk.ValAddressFromBech32(validator)
if err != nil {
return sdkerrors.Wrap(ErrInvalidAttestation, "votes must contain bech32 validator addresses")
}
}
err := ClaimValidateBasic(cdc, m.Claim)
if err != nil {
return sdkerrors.Wrap(ErrInvalidAttestation, err.Error())
}
return nil
}
func ClaimValidateBasic(cdc codec.BinaryCodec, claim *codectypes.Any) error {
var ethClaim EthereumClaim
err := cdc.UnpackAny(claim, ðClaim)
if err != nil {
return sdkerrors.Wrap(ErrInvalidClaim, "unable to unmarshal claim")
}
if ethClaim == nil {
return sdkerrors.Wrap(ErrInvalidClaim, "decoded nil claim")
}
// Returns nil on no error from ValidateBasic
err = ethClaim.ValidateBasic()
if err != nil {
return sdkerrors.Wrap(ErrInvalidClaim, err.Error())
}
return nil
}
// ClaimTypeToTypeUrl takes a type of EthereumClaim and returns the associated protobuf Msg TypeUrl
// nolint: exhaustruct
func ClaimTypeToTypeUrl(claimType ClaimType) string {
var msgName string
switch claimType {
case CLAIM_TYPE_UNSPECIFIED:
return "unspecified"
case CLAIM_TYPE_SEND_TO_PALOMA:
msgName = proto.MessageName(&MsgSendToPalomaClaim{})
case CLAIM_TYPE_BATCH_SEND_TO_ETH:
msgName = proto.MessageName(&MsgBatchSendToRemoteClaim{})
}
return "/" + msgName
}