-
Notifications
You must be signed in to change notification settings - Fork 13
/
offchain.go
75 lines (63 loc) · 2.02 KB
/
offchain.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)
// interface implementation assertions
var _ msg = &MsgSignData{}
const (
// ExpectedChainID defines the chain id an off-chain message must have
ExpectedChainID = ""
// ExpectedAccountNumber defines the account number an off-chain message must have
ExpectedAccountNumber = 0
// ExpectedSequence defines the sequence number an off-chain message must have
ExpectedSequence = 0
// ExpectedRoute defines the route to use for sdk.Msg.ExpectedRoute() implementation for offchain messages
ExpectedRoute = "offchain"
)
// msg defines an off-chain msg this exists so that offchain verification
// procedures are only applied to transactions lying in this package.
// TODO: making this exported would allow external types to use the SignatureVerifier and Signer
type msg interface {
legacytx.LegacyMsg
offchain()
}
// NewMsgSignData is MsgSignData's constructor
func NewMsgSignData(signer sdk.AccAddress, data []byte) *MsgSignData {
return &MsgSignData{
Signer: signer.String(),
Data: data,
}
}
// sdk.Msg implementation
func (m *MsgSignData) Route() string {
return ExpectedRoute
}
func (m *MsgSignData) Type() string {
return "MsgSignData"
}
func (m *MsgSignData) ValidateBasic() error {
signer, err := sdk.AccAddressFromBech32(m.Signer)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid signer: %s", err.Error())
}
if signer.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty signer")
}
if len(m.Data) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty data")
}
return nil
}
func (m *MsgSignData) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
}
func (m *MsgSignData) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(m.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
func (m *MsgSignData) offchain() {}