mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-10 17:11:03 +00:00
Refactor sr-api to not depend on client anymore (#4086)
* Refactor sr-api to not depend on client anymore * Fix benches * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Apply suggestions from code review
This commit is contained in:
committed by
Benjamin Kampmann
parent
e26d1a0b3e
commit
2ecffa1cd0
@@ -10,7 +10,8 @@ log = { version = "0.4.8", optional = true }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
keyring = { package = "substrate-keyring", path = "../keyring", optional = true }
|
||||
substrate-client = { path = "../client", default-features = false }
|
||||
sr-api = { path = "../sr-api", default-features = false }
|
||||
substrate-client = { path = "../client", optional = true }
|
||||
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
|
||||
app-crypto = { package = "substrate-application-crypto", path = "../application-crypto", default-features = false }
|
||||
inherents = { package = "substrate-inherents", path = "../inherents", default-features = false }
|
||||
@@ -33,6 +34,8 @@ srml-babe = { path = "../../srml/babe", default-features = false }
|
||||
srml-timestamp = { path = "../../srml/timestamp", default-features = false }
|
||||
srml-system = { path = "../../srml/system", default-features = false }
|
||||
srml-system-rpc-runtime-api = { path = "../../srml/system/rpc/runtime-api", default-features = false }
|
||||
transaction-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../transaction-pool/runtime-api", default-features = false }
|
||||
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../block-builder/runtime-api", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-executor = { path = "../executor" }
|
||||
@@ -49,7 +52,7 @@ default = [
|
||||
std = [
|
||||
"log",
|
||||
"serde",
|
||||
"substrate-client/std",
|
||||
"sr-api/std",
|
||||
"keyring",
|
||||
"codec/std",
|
||||
"rstd/std",
|
||||
@@ -74,4 +77,7 @@ std = [
|
||||
"app-crypto/std",
|
||||
"session/std",
|
||||
"runtime-interface/std",
|
||||
"transaction-pool-api/std",
|
||||
"block-builder-api/std",
|
||||
"substrate-client",
|
||||
]
|
||||
|
||||
@@ -7,14 +7,8 @@ edition = "2018"
|
||||
[dependencies]
|
||||
generic-test-client = { package = "substrate-test-client", path = "../../test-client" }
|
||||
primitives = { package = "substrate-primitives", path = "../../primitives" }
|
||||
runtime = { package = "substrate-test-runtime", path = "../../test-runtime", default-features = false }
|
||||
block-builder = { package = "substrate-block-builder", path = "../../block-builder" }
|
||||
runtime = { package = "substrate-test-runtime", path = "../../test-runtime" }
|
||||
sr-primitives = { path = "../../sr-primitives" }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"std",
|
||||
]
|
||||
std = [
|
||||
"runtime/std",
|
||||
]
|
||||
|
||||
@@ -19,25 +19,34 @@
|
||||
use runtime;
|
||||
use sr_primitives::traits::ProvideRuntimeApi;
|
||||
use generic_test_client::client;
|
||||
use generic_test_client::client::block_builder::api::BlockBuilder;
|
||||
|
||||
use block_builder::BlockBuilderApi;
|
||||
|
||||
/// Extension trait for test block builder.
|
||||
pub trait BlockBuilderExt {
|
||||
/// Add transfer extrinsic to the block.
|
||||
fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error>;
|
||||
/// Add storage change extrinsic to the block.
|
||||
fn push_storage_change(&mut self, key: Vec<u8>, value: Option<Vec<u8>>) -> Result<(), client::error::Error>;
|
||||
fn push_storage_change(
|
||||
&mut self,
|
||||
key: Vec<u8>,
|
||||
value: Option<Vec<u8>>,
|
||||
) -> Result<(), client::error::Error>;
|
||||
}
|
||||
|
||||
impl<'a, A> BlockBuilderExt for client::block_builder::BlockBuilder<'a, runtime::Block, A> where
|
||||
A: ProvideRuntimeApi + client::blockchain::HeaderBackend<runtime::Block> + 'a,
|
||||
A::Api: BlockBuilder<runtime::Block>
|
||||
impl<'a, A> BlockBuilderExt for block_builder::BlockBuilder<'a, runtime::Block, A> where
|
||||
A: ProvideRuntimeApi + 'a,
|
||||
A::Api: BlockBuilderApi<runtime::Block, Error = client::error::Error>,
|
||||
{
|
||||
fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error> {
|
||||
self.push(transfer.into_signed_tx())
|
||||
}
|
||||
|
||||
fn push_storage_change(&mut self, key: Vec<u8>, value: Option<Vec<u8>>) -> Result<(), client::error::Error> {
|
||||
fn push_storage_change(
|
||||
&mut self,
|
||||
key: Vec<u8>,
|
||||
value: Option<Vec<u8>>,
|
||||
) -> Result<(), client::error::Error> {
|
||||
self.push(runtime::Extrinsic::StorageChange(key, value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,7 @@ use trie_db::{TrieMut, Trie};
|
||||
use substrate_trie::PrefixedMemoryDB;
|
||||
use substrate_trie::trie_types::{TrieDB, TrieDBMut};
|
||||
|
||||
use substrate_client::{
|
||||
runtime_api as client_api, block_builder::api as block_builder_api, decl_runtime_apis,
|
||||
impl_runtime_apis,
|
||||
};
|
||||
use sr_api::{decl_runtime_apis, impl_runtime_apis};
|
||||
use sr_primitives::{
|
||||
ApplyResult, create_runtime_str, Perbill, impl_opaque_keys,
|
||||
transaction_validity::{
|
||||
@@ -460,7 +457,7 @@ static mut MUTABLE_STATIC: u64 = 32;
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "std")] {
|
||||
impl_runtime_apis! {
|
||||
impl client_api::Core<Block> for Runtime {
|
||||
impl sr_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion {
|
||||
version()
|
||||
}
|
||||
@@ -474,13 +471,13 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
impl client_api::Metadata<Block> for Runtime {
|
||||
impl sr_api::Metadata<Block> for Runtime {
|
||||
fn metadata() -> OpaqueMetadata {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl client_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
impl transaction_pool_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
fn validate_transaction(utx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
|
||||
if let Extrinsic::IncludeData(data) = utx {
|
||||
return Ok(ValidTransaction {
|
||||
@@ -645,7 +642,7 @@ cfg_if! {
|
||||
}
|
||||
} else {
|
||||
impl_runtime_apis! {
|
||||
impl client_api::Core<Block> for Runtime {
|
||||
impl sr_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion {
|
||||
version()
|
||||
}
|
||||
@@ -659,13 +656,13 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
impl client_api::Metadata<Block> for Runtime {
|
||||
impl sr_api::Metadata<Block> for Runtime {
|
||||
fn metadata() -> OpaqueMetadata {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl client_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
impl transaction_pool_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
fn validate_transaction(utx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
|
||||
if let Extrinsic::IncludeData(data) = utx {
|
||||
return Ok(ValidTransaction{
|
||||
|
||||
Reference in New Issue
Block a user