referrerpolicy=no-referrer-when-downgrade

sc_client_api/
call_executor.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! A method call executor interface.
20
21use sc_executor::{RuntimeVersion, RuntimeVersionOf};
22use sp_core::traits::CallContext;
23use sp_externalities::Extensions;
24use sp_runtime::traits::{Block as BlockT, HashingFor};
25use sp_state_machine::{OverlayedChanges, StorageProof};
26use std::cell::RefCell;
27
28use crate::execution_extensions::ExecutionExtensions;
29use sp_api::ProofRecorder;
30
31/// Executor Provider
32pub trait ExecutorProvider<Block: BlockT> {
33	/// executor instance
34	type Executor: CallExecutor<Block>;
35
36	/// Get call executor reference.
37	fn executor(&self) -> &Self::Executor;
38
39	/// Get a reference to the execution extensions.
40	fn execution_extensions(&self) -> &ExecutionExtensions<Block>;
41}
42
43/// Method call executor.
44pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
45	/// Externalities error type.
46	type Error: sp_state_machine::Error;
47
48	/// The backend used by the node.
49	type Backend: crate::backend::Backend<B>;
50
51	/// Returns the [`ExecutionExtensions`].
52	fn execution_extensions(&self) -> &ExecutionExtensions<B>;
53
54	/// Execute a call to a contract on top of state in a block of given hash.
55	///
56	/// No changes are made.
57	fn call(
58		&self,
59		at_hash: B::Hash,
60		method: &str,
61		call_data: &[u8],
62		context: CallContext,
63	) -> Result<Vec<u8>, sp_blockchain::Error>;
64
65	/// Execute a contextual call on top of state in a block of a given hash.
66	///
67	/// No changes are made.
68	/// Before executing the method, passed header is installed as the current header
69	/// of the execution context.
70	fn contextual_call(
71		&self,
72		at_hash: B::Hash,
73		method: &str,
74		call_data: &[u8],
75		changes: &RefCell<OverlayedChanges<HashingFor<B>>>,
76		proof_recorder: &Option<ProofRecorder<B>>,
77		call_context: CallContext,
78		extensions: &RefCell<Extensions>,
79	) -> sp_blockchain::Result<Vec<u8>>;
80
81	/// Extract RuntimeVersion of given block
82	///
83	/// No changes are made.
84	fn runtime_version(&self, at_hash: B::Hash) -> Result<RuntimeVersion, sp_blockchain::Error>;
85
86	/// Prove the execution of the given `method`.
87	///
88	/// No changes are made.
89	fn prove_execution(
90		&self,
91		at_hash: B::Hash,
92		method: &str,
93		call_data: &[u8],
94	) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error>;
95}