,
>;
/// Extract the state backend type for a type that implements `ProvideRuntimeApi`.
#[cfg(feature = "std")]
pub type StateBackendFor =
<
>::Api as ApiExt>::StateBackend;
/// Extract the state backend transaction type for a type that implements `ProvideRuntimeApi`.
#[cfg(feature = "std")]
pub type TransactionFor =
as StateBackend>>::Transaction;
/// Something that can be constructed to a runtime api.
#[cfg(feature = "std")]
pub trait ConstructRuntimeApi> {
/// The actual runtime api that will be constructed.
type RuntimeApi: ApiExt;
/// Construct an instance of the runtime api.
fn construct_runtime_api(call: &C) -> ApiRef;
}
/// Init the [`RuntimeLogger`](sp_runtime::runtime_logger::RuntimeLogger).
pub fn init_runtime_logger() {
#[cfg(not(feature = "disable-logging"))]
sp_runtime::runtime_logger::RuntimeLogger::init();
}
/// An error describing which API call failed.
#[cfg(feature = "std")]
#[derive(Debug, thiserror::Error)]
pub enum ApiError {
#[error("Failed to decode return value of {function}")]
FailedToDecodeReturnValue {
function: &'static str,
#[source]
error: codec::Error,
},
#[error("Failed to convert return value from runtime to node of {function}")]
FailedToConvertReturnValue {
function: &'static str,
#[source]
error: codec::Error,
},
#[error("Failed to convert parameter `{parameter}` from node to runtime of {function}")]
FailedToConvertParameter {
function: &'static str,
parameter: &'static str,
#[source]
error: codec::Error,
},
#[error("The given `StateBackend` isn't a `TrieBackend`.")]
StateBackendIsNotTrie,
#[error(transparent)]
Application(#[from] Box),
#[error("Api called for an unknown Block: {0}")]
UnknownBlock(String),
}
/// Extends the runtime api implementation with some common functionality.
#[cfg(feature = "std")]
pub trait ApiExt {
/// The state backend that is used to store the block states.
type StateBackend: StateBackend>;
/// Execute the given closure inside a new transaction.
///
/// Depending on the outcome of the closure, the transaction is committed or rolled-back.
///
/// The internal result of the closure is returned afterwards.
fn execute_in_transaction TransactionOutcome, R>(&self, call: F) -> R
where
Self: Sized;
/// Checks if the given api is implemented and versions match.
fn has_api(&self, at_hash: Block::Hash) -> Result
where
Self: Sized;
/// Check if the given api is implemented and the version passes a predicate.
fn has_api_with bool>(
&self,
at_hash: Block::Hash,
pred: P,
) -> Result
where
Self: Sized;
/// Returns the version of the given api.
fn api_version(
&self,
at_hash: Block::Hash,
) -> Result