Skip to main content

soil_client/client_api/
call_executor.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! A method call executor interface.
8
9use crate::executor::{RuntimeVersion, RuntimeVersionOf};
10use std::cell::RefCell;
11use subsoil::core::traits::CallContext;
12use subsoil::externalities::Extensions;
13use subsoil::runtime::traits::{Block as BlockT, HashingFor};
14use subsoil::state_machine::{OverlayedChanges, StorageProof};
15
16use super::execution_extensions::ExecutionExtensions;
17use subsoil::api::ProofRecorder;
18
19/// Executor Provider
20pub trait ExecutorProvider<Block: BlockT> {
21	/// executor instance
22	type Executor: CallExecutor<Block>;
23
24	/// Get call executor reference.
25	fn executor(&self) -> &Self::Executor;
26
27	/// Get a reference to the execution extensions.
28	fn execution_extensions(&self) -> &ExecutionExtensions<Block>;
29}
30
31/// Method call executor.
32pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
33	/// Externalities error type.
34	type Error: subsoil::state_machine::Error;
35
36	/// The backend used by the node.
37	type Backend: super::backend::Backend<B>;
38
39	/// Returns the [`ExecutionExtensions`].
40	fn execution_extensions(&self) -> &ExecutionExtensions<B>;
41
42	/// Execute a call to a contract on top of state in a block of given hash.
43	///
44	/// No changes are made.
45	fn call(
46		&self,
47		at_hash: B::Hash,
48		method: &str,
49		call_data: &[u8],
50		context: CallContext,
51	) -> Result<Vec<u8>, crate::blockchain::Error>;
52
53	/// Execute a contextual call on top of state in a block of a given hash.
54	///
55	/// No changes are made.
56	/// Before executing the method, passed header is installed as the current header
57	/// of the execution context.
58	fn contextual_call(
59		&self,
60		at_hash: B::Hash,
61		method: &str,
62		call_data: &[u8],
63		changes: &RefCell<OverlayedChanges<HashingFor<B>>>,
64		proof_recorder: &Option<ProofRecorder<B>>,
65		call_context: CallContext,
66		extensions: &RefCell<Extensions>,
67	) -> crate::blockchain::Result<Vec<u8>>;
68
69	/// Extract RuntimeVersion of given block
70	///
71	/// No changes are made.
72	fn runtime_version(&self, at_hash: B::Hash)
73		-> Result<RuntimeVersion, crate::blockchain::Error>;
74
75	/// Prove the execution of the given `method`.
76	///
77	/// No changes are made.
78	fn prove_execution(
79		&self,
80		at_hash: B::Hash,
81		method: &str,
82		call_data: &[u8],
83	) -> Result<(Vec<u8>, StorageProof), crate::blockchain::Error>;
84}