Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

rpc: Implement archive RPC API #12737

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion client/rpc-spec-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ sc-chain-spec = { version = "4.0.0-dev", path = "../chain-spec" }
sc-transaction-pool-api = { version = "4.0.0-dev", path = "../transaction-pool/api" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-runtime = { version = "7.0.0", path = "../../primitives/runtime" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
codec = { package = "parity-scale-codec", version = "3.0.0" }
thiserror = "1.0"
serde = "1.0"
array-bytes = "4.1"
hex = "0.4"
futures = "0.3.21"

[dev-dependencies]
serde_json = "1.0"
tokio = { version = "1.17.0", features = ["macros"] }
tokio = { version = "1.17.0", features = ["full"] }
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }
substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime" }
sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" }
sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" }
assert_matches = "1.3.0"
99 changes: 99 additions & 0 deletions client/rpc-spec-v2/src/archive/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// This file is part of Substrate.

// Copyright (C) 2022 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 <https://www.gnu.org/licenses/>.

#![allow(non_snake_case)]

//! API trait of the archive functions.
use crate::archive::event::{ArchiveEvent, NetworkConfig};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};

#[rpc(client, server)]
pub trait ArchiveApi<Hash> {
/// Retrieves the body (list of transactions) of an archive block.
//
/// Use `chainHead_unstable_body` if instead you want to retrieve the body of a recent block.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "archive_unstable_body",
unsubscribe = "archive_unstable_stopBody",
item = ArchiveEvent<String>,
)]
fn archive_unstable_body(&self, hash: Hash, networkConfig: Option<NetworkConfig>);

/// Get the chain's genesis hash.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[method(name = "archive_unstable_genesisHash", blocking)]
fn archive_unstable_genesis_hash(&self) -> RpcResult<String>;

/// Retrieves the hashes of the blocks that have the specified height.
///
/// If the height parameter is less or equal to the latest finalized block
/// height, then only finalized blocks are fetched.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "archive_unstable_hashByHeight",
unsubscribe = "archive_unstable_stopHashByHeight",
item = ArchiveEvent<String>,
)]
fn archive_unstable_hash_by_height(&self, height: String, networkConfig: Option<NetworkConfig>);

/// Retrieves the header of an archive block.
///
/// Use `chainHead_unstable_header` if instead you want to retrieve the header of a
/// recent block.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "archive_unstable_header",
unsubscribe = "archive_unstable_stopHeader",
item = ArchiveEvent<String>,
)]
fn archive_unstable_header(&self, hash: Hash, networkConfig: Option<NetworkConfig>);

/// Return a storage entry at a specific block's state.
///
/// Use `chainHead_unstable_storage` if instead you want to retrieve the
/// storage of a recent block.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[subscription(
name = "archive_unstable_storage",
unsubscribe = "archive_unstable_stopStorage",
item = ArchiveEvent<String>,
)]
fn archive_unstable_storage(
&self,
hash: Hash,
key: String,
childKey: Option<String>,
networkConfig: Option<NetworkConfig>,
);
}
Loading