2021-09-14 02:42:42 -07:00
package tx
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
2021-10-18 03:32:43 -07:00
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
2021-09-14 02:42:42 -07:00
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 )
}
2021-10-18 03:32:43 -07:00
signerInfo := protoTx . tx . AuthInfo . SignerInfos [ data . SignerIndex ]
if signerInfo == nil || signerInfo . PublicKey == nil {
return nil , sdkerrors . ErrInvalidRequest . Wrapf ( "got empty pubkey for signer #%d in %s handler" , data . SignerIndex , signingtypes . SignMode_SIGN_MODE_DIRECT_AUX )
}
2021-09-14 02:42:42 -07:00
signDocDirectAux := types . SignDocDirectAux {
BodyBytes : protoTx . getBodyBytes ( ) ,
ChainId : data . ChainID ,
AccountNumber : data . AccountNumber ,
Sequence : data . Sequence ,
Tip : protoTx . tx . AuthInfo . Tip ,
PublicKey : protoTx . tx . AuthInfo . SignerInfos [ data . SignerIndex ] . PublicKey ,
}
return signDocDirectAux . Marshal ( )
}