Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package tx
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
types "github.com/cosmos/cosmos-sdk/types/tx"
|
|
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
|
)
|
|
|
|
var _ signing.SignModeHandler = signModeDirectAuxHandler{}
|
|
|
|
// signModeDirectAuxHandler defines the SIGN_MODE_DIRECT_AUX SignModeHandler
|
|
type signModeDirectAuxHandler struct{}
|
|
|
|
// DefaultMode implements SignModeHandler.DefaultMode
|
|
func (signModeDirectAuxHandler) DefaultMode() signingtypes.SignMode {
|
|
return signingtypes.SignMode_SIGN_MODE_DIRECT_AUX
|
|
}
|
|
|
|
// Modes implements SignModeHandler.Modes
|
|
func (signModeDirectAuxHandler) Modes() []signingtypes.SignMode {
|
|
return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_DIRECT_AUX}
|
|
}
|
|
|
|
// GetSignBytes implements SignModeHandler.GetSignBytes
|
|
func (signModeDirectAuxHandler) GetSignBytes(
|
|
mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx,
|
|
) ([]byte, error) {
|
|
if mode != signingtypes.SignMode_SIGN_MODE_DIRECT_AUX {
|
|
return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, mode)
|
|
}
|
|
|
|
protoTx, ok := tx.(*wrapper)
|
|
if !ok {
|
|
return nil, fmt.Errorf("can only handle a protobuf Tx, got %T", tx)
|
|
}
|
|
|
|
pkAny, err := codectypes.NewAnyWithValue(data.PubKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
addr := data.Address
|
|
if addr == "" {
|
|
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "got empty address in %s handler", signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
|
|
}
|
|
|
|
feePayer := protoTx.FeePayer()
|
|
|
|
// Fee payer cannot use SIGN_MODE_DIRECT_AUX, because SIGN_MODE_DIRECT_AUX
|
|
// does not sign over fees, which would create malleability issues.
|
|
if strings.EqualFold(sdk.AccAddress(feePayer).String(), data.Address) {
|
|
return nil, sdkerrors.ErrUnauthorized.Wrapf("fee payer %s cannot sign with %s", sdk.AccAddress(feePayer).String(), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
|
|
}
|
|
|
|
signDocDirectAux := types.SignDocDirectAux{
|
|
BodyBytes: protoTx.getBodyBytes(),
|
|
ChainId: data.ChainID,
|
|
AccountNumber: data.AccountNumber,
|
|
Sequence: data.Sequence,
|
|
Tip: protoTx.tx.AuthInfo.Tip,
|
|
PublicKey: pkAny,
|
|
}
|
|
|
|
return signDocDirectAux.Marshal()
|
|
}
|