/
ethereum_signature.go
95 lines (80 loc) · 2.42 KB
/
ethereum_signature.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
package types
import (
"fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
)
var (
_ ExternalTxConfirmation = &SignerSetTxConfirmation{}
_ ExternalTxConfirmation = &ContractCallTxConfirmation{}
_ ExternalTxConfirmation = &BatchTxConfirmation{}
)
///////////////
// GetSigner //
///////////////
func (u *SignerSetTxConfirmation) GetSigner() common.Address {
return common.HexToAddress(u.ExternalSigner)
}
func (u *ContractCallTxConfirmation) GetSigner() common.Address {
return common.HexToAddress(u.ExternalSigner)
}
func (u *BatchTxConfirmation) GetSigner() common.Address {
return common.HexToAddress(u.ExternalSigner)
}
///////////////////
// GetStoreIndex //
///////////////////
func (sstx *SignerSetTxConfirmation) GetStoreIndex(chainId ChainID) []byte {
return MakeSignerSetTxKey(chainId, sstx.SignerSetNonce)
}
func (btx *BatchTxConfirmation) GetStoreIndex(chainId ChainID) []byte {
return MakeBatchTxKey(chainId, btx.ExternalTokenId, btx.BatchNonce)
}
func (cctx *ContractCallTxConfirmation) GetStoreIndex(chainId ChainID) []byte {
return MakeContractCallTxKey(chainId, cctx.InvalidationScope, cctx.InvalidationNonce)
}
//////////////
// Validate //
//////////////
func (u *SignerSetTxConfirmation) Validate() error {
if u.SignerSetNonce == 0 {
return fmt.Errorf("nonce must be set")
}
if !common.IsHexAddress(u.ExternalSigner) {
return sdkerrors.Wrap(ErrInvalid, "ethereum signer must be address")
}
if u.Signature == nil {
return fmt.Errorf("signature must be set")
}
return nil
}
func (u *ContractCallTxConfirmation) Validate() error {
if u.InvalidationNonce == 0 {
return fmt.Errorf("invalidation nonce must be set")
}
if u.InvalidationScope == nil {
return fmt.Errorf("invalidation scope must be set")
}
if !common.IsHexAddress(u.ExternalSigner) {
return sdkerrors.Wrap(ErrInvalid, "ethereum signer must be address")
}
if u.Signature == nil {
return fmt.Errorf("signature must be set")
}
return nil
}
func (u *BatchTxConfirmation) Validate() error {
if u.BatchNonce == 0 {
return fmt.Errorf("nonce must be set")
}
//if !common.IsHexAddress(u.TokenContract) {
// return fmt.Errorf("token contract address must be valid ethereum address")
//}
if !common.IsHexAddress(u.ExternalSigner) {
return sdkerrors.Wrap(ErrInvalid, "ethereum signer must be address")
}
if u.Signature == nil {
return fmt.Errorf("signature must be set")
}
return nil
}