@@ -10,7 +10,7 @@ use revm::{
1010 context:: { Cfg , ContextTr , LocalContextTr } ,
1111 handler:: { EthPrecompiles , PrecompileProvider } ,
1212 interpreter:: { CallInput , Gas , InputsImpl , InstructionResult , InterpreterResult } ,
13- precompile:: { PrecompileError , PrecompileResult , Precompiles } ,
13+ precompile:: { PrecompileError , PrecompileFn , PrecompileResult , Precompiles } ,
1414} ;
1515
1616/// A mapping of precompile contracts that can be either static (builtin) or dynamic.
@@ -284,6 +284,16 @@ impl<CTX: ContextTr> PrecompileProvider<CTX> for PrecompilesMap {
284284#[ derive( Clone ) ]
285285pub struct DynPrecompile ( pub ( crate ) Arc < dyn Precompile + Send + Sync > ) ;
286286
287+ impl DynPrecompile {
288+ /// Creates a new [`DynPrecompiles`] with the given closure.
289+ pub fn new < F > ( f : F ) -> Self
290+ where
291+ F : Fn ( PrecompileInput < ' _ > ) -> PrecompileResult + Send + Sync + ' static ,
292+ {
293+ Self ( Arc :: new ( f) )
294+ }
295+ }
296+
287297impl core:: fmt:: Debug for DynPrecompile {
288298 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
289299 f. debug_struct ( "DynPrecompile" ) . finish ( )
@@ -345,6 +355,13 @@ where
345355 }
346356}
347357
358+ impl From < PrecompileFn > for DynPrecompile {
359+ fn from ( f : PrecompileFn ) -> Self {
360+ let p = move |input : PrecompileInput < ' _ > | f ( input. data , input. gas ) ;
361+ p. into ( )
362+ }
363+ }
364+
348365impl Precompile for DynPrecompile {
349366 fn call ( & self , input : PrecompileInput < ' _ > ) -> PrecompileResult {
350367 self . 0 . call ( input)
0 commit comments