Skip to content

Commit 88a075a

Browse files
author
Felix Müller
authored
[Sidechain] Peer block fetching o-call implementation (#619)
* introduce o-call for fetching sidechain blocks from peer * re-name api-client-extensions to node-api-extensions Sub-task of #567
1 parent 17e9776 commit 88a075a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+904
-172
lines changed

Cargo.lock

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ dependencies = [
20192019
"integritee-node-runtime",
20202020
"ita-stf",
20212021
"itc-rpc-client",
2022-
"itp-api-client-extensions",
2022+
"itp-node-api-extensions",
20232023
"itp-types",
20242024
"json",
20252025
"log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2105,12 +2105,13 @@ dependencies = [
21052105
"ita-stf",
21062106
"itc-rpc-client",
21072107
"itc-rpc-server",
2108-
"itp-api-client-extensions",
21092108
"itp-enclave-api",
2109+
"itp-node-api-extensions",
21102110
"itp-settings",
21112111
"itp-test",
21122112
"itp-types",
21132113
"its-consensus-slots",
2114+
"its-peer-fetch",
21142115
"its-primitives",
21152116
"its-storage",
21162117
"its-test",
@@ -2445,18 +2446,6 @@ version = "0.4.8"
24452446
source = "registry+https://github.com/rust-lang/crates.io-index"
24462447
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
24472448

2448-
[[package]]
2449-
name = "itp-api-client-extensions"
2450-
version = "0.8.0"
2451-
dependencies = [
2452-
"itp-types",
2453-
"parity-scale-codec",
2454-
"sp-core",
2455-
"sp-finality-grandpa",
2456-
"sp-runtime",
2457-
"substrate-api-client",
2458-
]
2459-
24602449
[[package]]
24612450
name = "itp-component-container"
24622451
version = "0.8.0"
@@ -2509,6 +2498,19 @@ dependencies = [
25092498
"thiserror 1.0.9",
25102499
]
25112500

2501+
[[package]]
2502+
name = "itp-node-api-extensions"
2503+
version = "0.8.0"
2504+
dependencies = [
2505+
"itp-types",
2506+
"parity-scale-codec",
2507+
"sp-core",
2508+
"sp-finality-grandpa",
2509+
"sp-runtime",
2510+
"substrate-api-client",
2511+
"thiserror 1.0.30",
2512+
]
2513+
25122514
[[package]]
25132515
name = "itp-nonce-cache"
25142516
version = "0.8.0"
@@ -2826,7 +2828,7 @@ dependencies = [
28262828
"anyhow",
28272829
"async-trait",
28282830
"itc-rpc-client",
2829-
"itp-api-client-extensions",
2831+
"itp-node-api-extensions",
28302832
"itp-test",
28312833
"its-primitives",
28322834
"its-storage",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ members = [
1414
"core/rpc-client",
1515
"core/rpc-server",
1616
"core/tls-websocket-server",
17-
"core-primitives/api-client-extensions",
17+
"core-primitives/node-api-extensions",
1818
"core-primitives/component-container",
1919
"core-primitives/enclave-api",
2020
"core-primitives/enclave-api/ffi",

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ sp-core = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrat
4141

4242
#local dependencies
4343
itp-types = { path = "../core-primitives/types" }
44-
itp-api-client-extensions = { path = "../core-primitives/api-client-extensions" }
44+
itp-node-api-extensions = { path = "../core-primitives/node-api-extensions" }
4545
ita-stf = { path = "../app-libs/stf" }
4646
itc-rpc-client = { path = "../core/rpc-client" }

cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use teerex_primitives::Request;
5656

5757
use ita_stf::{ShardIdentifier, TrustedCallSigned, TrustedOperation};
5858
use itc_rpc_client::direct_client::{DirectApi, DirectClient as DirectWorkerApi};
59-
use itp_api_client_extensions::{PalletTeerexApi, TEEREX};
59+
use itp_node_api_extensions::{PalletTeerexApi, TEEREX};
6060
use itp_types::{DirectRequestStatus, RpcRequest, RpcResponse, RpcReturnValue};
6161
use substrate_client_keystore::{KeystoreExt, LocalKeystore};
6262

core-primitives/api-client-extensions/Cargo.toml renamed to core-primitives/node-api-extensions/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[package]
2-
name = "itp-api-client-extensions"
2+
name = "itp-node-api-extensions"
33
version = "0.8.0"
44
authors = ["Integritee AG <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8+
# crates.io
89
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }
10+
thiserror = "1.0"
911

1012
# substrate
1113
sp-core = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }

core-primitives/api-client-extensions/src/lib.rs renamed to core-primitives/node-api-extensions/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use substrate_api_client::ApiClientError;
2121

2222
pub mod account;
2323
pub mod chain;
24+
pub mod node_api_factory;
2425
pub mod pallet_teerex;
2526

2627
#[cfg(feature = "mocks")]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2021 Integritee AG and Supercomputing Systems AG
3+
Copyright (C) 2017-2019 Baidu, Inc. All Rights Reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
*/
18+
19+
use sp_core::sr25519;
20+
use substrate_api_client::{rpc::WsRpcClient, Api};
21+
22+
/// Trait to create a node API, based on a node URL and signer.
23+
pub trait CreateNodeApi {
24+
fn create_api(&self) -> Result<Api<sr25519::Pair, WsRpcClient>>;
25+
}
26+
27+
/// Node API factory error.
28+
#[derive(Debug, thiserror::Error)]
29+
pub enum NodeApiFactoryError {
30+
#[error("Failed to create a node API: {0}")]
31+
FailedToCreateNodeApi(#[from] substrate_api_client::ApiClientError),
32+
#[error(transparent)]
33+
Other(#[from] Box<dyn std::error::Error + Sync + Send + 'static>),
34+
}
35+
36+
pub type Result<T> = std::result::Result<T, NodeApiFactoryError>;
37+
38+
/// Node API factory implementation.
39+
pub struct NodeApiFactory {
40+
node_url: String,
41+
signer: sr25519::Pair,
42+
}
43+
44+
impl NodeApiFactory {
45+
pub fn new(url: String, signer: sr25519::Pair) -> Self {
46+
NodeApiFactory { node_url: url, signer }
47+
}
48+
}
49+
50+
impl CreateNodeApi for NodeApiFactory {
51+
fn create_api(&self) -> Result<Api<sr25519::Pair, WsRpcClient>> {
52+
Api::<sr25519::Pair, WsRpcClient>::new(WsRpcClient::new(self.node_url.as_str()))
53+
.map_err(NodeApiFactoryError::FailedToCreateNodeApi)
54+
.map(|a| a.set_signer(self.signer.clone()))
55+
}
56+
}

0 commit comments

Comments
 (0)