Precompile

Trait Precompile 

Source
pub trait Precompile {
    // Required methods
    fn precompile_id(&self) -> &PrecompileId;
    fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult;

    // Provided method
    fn is_pure(&self) -> bool { ... }
}
Expand description

Trait for implementing precompiled contracts.

Required Methods§

Source

fn precompile_id(&self) -> &PrecompileId

Returns precompile ID.

Source

fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult

Execute the precompile with the given input data, gas limit, and caller address.

Provided Methods§

Source

fn is_pure(&self) -> bool

Returns whether the precompile is pure.

A pure precompile has deterministic output based solely on its input. Non-pure precompiles may produce different outputs for the same input based on the current state or other external factors.

§Default

Returns true by default, indicating the precompile is pure and its results should be cached as this is what most of the precompiles are.

§Examples

Override this method to return false for non-deterministic precompiles:

impl Precompile for MyDeterministicPrecompile {
    fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult {
        // non-deterministic computation dependent on state
    }

    fn is_pure(&self) -> bool {
        false // This precompile might produce different output for the same input
    }
}

Implementations on Foreign Types§

Source§

impl Precompile for Precompile

Source§

impl<'a, T: 'a + Precompile + ?Sized> Precompile for &'a T

Source§

impl<A: Precompile, B: Precompile> Precompile for Either<A, B>

Source§

impl<F> Precompile for (&PrecompileId, F)

Source§

impl<F> Precompile for (PrecompileId, F)

Source§

impl<T: Precompile + ?Sized> Precompile for Arc<T>

Implementors§