// This file is part of Substrate.
// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//! Substrate state API.
mod state_full;
mod state_light;
#[cfg(test)]
mod tests;
use std::sync::Arc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager};
use rpc::{Result as RpcResult, futures::{Future, future::result}};
use sc_rpc_api::state::ReadProof;
use sc_client_api::light::{RemoteBlockchain, Fetcher};
use sp_core::{Bytes, storage::{StorageKey, PrefixedStorageKey, StorageData, StorageChangeSet}};
use sp_version::RuntimeVersion;
use sp_runtime::traits::Block as BlockT;
use sp_api::{Metadata, ProvideRuntimeApi, CallApiAt};
use self::error::{Error, FutureResult};
pub use sc_rpc_api::state::*;
pub use sc_rpc_api::child_state::*;
use sc_client_api::{ExecutorProvider, StorageProvider, BlockchainEvents, Backend, ProofProvider};
use sp_blockchain::{HeaderMetadata, HeaderBackend};
const STORAGE_KEYS_PAGED_MAX_COUNT: u32 = 1000;
/// State backend API.
pub trait StateBackend: Send + Sync + 'static
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
{
/// Call runtime method at given block.
fn call(
&self,
block: Option,
method: String,
call_data: Bytes,
) -> FutureResult;
/// Returns the keys with prefix, leave empty to get all the keys.
fn storage_keys(
&self,
block: Option,
prefix: StorageKey,
) -> FutureResult>;
/// Returns the keys with prefix along with their values, leave empty to get all the pairs.
fn storage_pairs(
&self,
block: Option,
prefix: StorageKey,
) -> FutureResult>;
/// Returns the keys with prefix with pagination support.
fn storage_keys_paged(
&self,
block: Option,
prefix: Option,
count: u32,
start_key: Option,
) -> FutureResult>;
/// Returns a storage entry at a specific block's state.
fn storage(
&self,
block: Option,
key: StorageKey,
) -> FutureResult