-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathdirect_aux.go
71 lines (58 loc) · 2.24 KB
/
direct_aux.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
package tx
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
// ValidateBasic performs stateless validation of the sign doc.
func (s *SignDocDirectAux) ValidateBasic() error {
if len(s.BodyBytes) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("body bytes cannot be empty")
}
if s.PublicKey == nil {
return sdkerrors.ErrInvalidPubKey.Wrap("public key cannot be empty")
}
if s.Tip != nil {
if s.Tip.Tipper == "" {
return sdkerrors.ErrInvalidRequest.Wrap("tipper cannot be empty")
}
}
return nil
}
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (s *SignDocDirectAux) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(s.PublicKey, new(cryptotypes.PubKey))
}
// ValidateBasic performs stateless validation of the auxiliary tx.
func (a *AuxSignerData) ValidateBasic() error {
if a.Address == "" {
return sdkerrors.ErrInvalidRequest.Wrapf("address cannot be empty")
}
if a.Mode != signing.SignMode_SIGN_MODE_DIRECT_AUX && a.Mode != signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON {
return sdkerrors.ErrInvalidRequest.Wrapf("AuxTxBuilder can only sign with %s or %s", signing.SignMode_SIGN_MODE_DIRECT_AUX, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
}
if len(a.Sig) == 0 {
return sdkerrors.ErrNoSignatures.Wrap("signature cannot be empty")
}
return a.GetSignDoc().ValidateBasic()
}
// GetSignaturesV2 gets the SignatureV2 of the aux signer.
func (a *AuxSignerData) GetSignatureV2() (signing.SignatureV2, error) {
pk, ok := a.SignDoc.PublicKey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return signing.SignatureV2{}, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (cryptotypes.PubKey)(nil), pk)
}
return signing.SignatureV2{
PubKey: pk,
Data: &signing.SingleSignatureData{
SignMode: a.Mode,
Signature: a.Sig,
},
Sequence: a.SignDoc.Sequence,
}, nil
}
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (a *AuxSignerData) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return a.GetSignDoc().UnpackInterfaces(unpacker)
}