@@ -92,12 +92,25 @@ type UIClientAPI interface {
9292 RegisterUIServer (api * UIServerAPI )
9393}
9494
95+ // Validator defines the methods required to validate a transaction against some
96+ // sanity defaults as well as any underlying 4byte method database.
97+ //
98+ // Use fourbyte.Database as an implementation. It is separated out of this package
99+ // to allow pieces of the signer package to be used without having to load the
100+ // 7MB embedded 4byte dump.
101+ type Validator interface {
102+ // ValidateTransaction does a number of checks on the supplied transaction, and
103+ // returns either a list of warnings, or an error (indicating that the transaction
104+ // should be immediately rejected).
105+ ValidateTransaction (selector * string , tx * SendTxArgs ) (* ValidationMessages , error )
106+ }
107+
95108// SignerAPI defines the actual implementation of ExternalAPI
96109type SignerAPI struct {
97110 chainID * big.Int
98111 am * accounts.Manager
99112 UI UIClientAPI
100- validator * Validator
113+ validator Validator
101114 rejectMode bool
102115 credentials storage.Storage
103116}
@@ -235,11 +248,11 @@ var ErrRequestDenied = errors.New("Request denied")
235248// key that is generated when a new Account is created.
236249// noUSB disables USB support that is required to support hardware devices such as
237250// ledger and trezor.
238- func NewSignerAPI (am * accounts.Manager , chainID int64 , noUSB bool , ui UIClientAPI , abidb * AbiDb , advancedMode bool , credentials storage.Storage ) * SignerAPI {
251+ func NewSignerAPI (am * accounts.Manager , chainID int64 , noUSB bool , ui UIClientAPI , validator Validator , advancedMode bool , credentials storage.Storage ) * SignerAPI {
239252 if advancedMode {
240253 log .Info ("Clef is in advanced mode: will warn instead of reject" )
241254 }
242- signer := & SignerAPI {big .NewInt (chainID ), am , ui , NewValidator ( abidb ) , ! advancedMode , credentials }
255+ signer := & SignerAPI {big .NewInt (chainID ), am , ui , validator , ! advancedMode , credentials }
243256 if ! noUSB {
244257 signer .startUSBListener ()
245258 }
@@ -458,7 +471,7 @@ func (api *SignerAPI) SignTransaction(ctx context.Context, args SendTxArgs, meth
458471 err error
459472 result SignTxResponse
460473 )
461- msgs , err := api .validator .ValidateTransaction (& args , methodSelector )
474+ msgs , err := api .validator .ValidateTransaction (methodSelector , & args )
462475 if err != nil {
463476 return nil , err
464477 }
0 commit comments