mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 06:01:06 +00:00
Remove some substrate dependencies to improve compile time (#194)
* Copy ReadProof and TransactionStatus types * Define local app crypto types * Fmt * Restore logging and add comments
This commit is contained in:
@@ -42,16 +42,10 @@ pallet-indices = { version = "2.0.0", package = "pallet-indices" }
|
||||
hex = "0.4.2"
|
||||
sp-std = "2.0.0"
|
||||
application-crypto = { version = "2.0.0", package = "sp-application-crypto" }
|
||||
sp-finality-grandpa = "2.0.0"
|
||||
sp-consensus-babe = "0.8.0"
|
||||
pallet-im-online = "2.0.0"
|
||||
sp-authority-discovery = "2.0.0"
|
||||
pallet-staking = "2.0.0"
|
||||
|
||||
sp-rpc = { version = "2.0.0", package = "sp-rpc" }
|
||||
sp-core = { version = "2.0.0", package = "sp-core" }
|
||||
sc-rpc-api = { version = "0.8.0", package = "sc-rpc-api" }
|
||||
sp-transaction-pool = { version = "2.0.0", package = "sp-transaction-pool" }
|
||||
substrate-subxt-client = { version = "0.5.0", path = "client", optional = true }
|
||||
substrate-subxt-proc-macro = { version = "0.13.0", path = "proc-macro" }
|
||||
|
||||
|
||||
+1
-1
@@ -52,7 +52,6 @@ pub use sp_runtime;
|
||||
use codec::Decode;
|
||||
use futures::future;
|
||||
use jsonrpsee::client::Subscription;
|
||||
use sc_rpc_api::state::ReadProof;
|
||||
use sp_core::{
|
||||
storage::{
|
||||
StorageChangeSet,
|
||||
@@ -94,6 +93,7 @@ pub use crate::{
|
||||
rpc::{
|
||||
BlockNumber,
|
||||
ExtrinsicSuccess,
|
||||
ReadProof,
|
||||
SystemProperties,
|
||||
},
|
||||
runtimes::*,
|
||||
|
||||
+55
-6
@@ -37,8 +37,10 @@ use jsonrpsee::{
|
||||
},
|
||||
Client,
|
||||
};
|
||||
use sc_rpc_api::state::ReadProof;
|
||||
use serde::Serialize;
|
||||
use serde::{
|
||||
Deserialize,
|
||||
Serialize,
|
||||
};
|
||||
use sp_core::{
|
||||
storage::{
|
||||
StorageChangeSet,
|
||||
@@ -59,7 +61,6 @@ use sp_runtime::{
|
||||
},
|
||||
traits::Hash,
|
||||
};
|
||||
use sp_transaction_pool::TransactionStatus;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
use crate::{
|
||||
@@ -96,9 +97,9 @@ impl From<u32> for BlockNumber {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
/// System properties for a Substrate-based runtime
|
||||
#[derive(serde::Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SystemProperties {
|
||||
/// The address format
|
||||
pub ss58_format: u8,
|
||||
@@ -108,6 +109,54 @@ pub struct SystemProperties {
|
||||
pub token_symbol: String,
|
||||
}
|
||||
|
||||
/// Possible transaction status events.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This is copied from `sp-transaction-pool` to avoid a dependency on that crate. Therefore it
|
||||
/// must be kept compatible with that type from the target substrate version.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum TransactionStatus<Hash, BlockHash> {
|
||||
/// Transaction is part of the future queue.
|
||||
Future,
|
||||
/// Transaction is part of the ready queue.
|
||||
Ready,
|
||||
/// The transaction has been broadcast to the given peers.
|
||||
Broadcast(Vec<String>),
|
||||
/// Transaction has been included in block with given hash.
|
||||
InBlock(BlockHash),
|
||||
/// The block this transaction was included in has been retracted.
|
||||
Retracted(BlockHash),
|
||||
/// Maximum number of finality watchers has been reached,
|
||||
/// old watchers are being removed.
|
||||
FinalityTimeout(BlockHash),
|
||||
/// Transaction has been finalized by a finality-gadget, e.g GRANDPA
|
||||
Finalized(BlockHash),
|
||||
/// Transaction has been replaced in the pool, by another transaction
|
||||
/// that provides the same tags. (e.g. same (sender, nonce)).
|
||||
Usurped(Hash),
|
||||
/// Transaction has been dropped from the pool because of the limit.
|
||||
Dropped,
|
||||
/// Transaction is no longer valid in the current state.
|
||||
Invalid,
|
||||
}
|
||||
|
||||
/// ReadProof struct returned by the RPC
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This is copied from `sc-rpc-api` to avoid a dependency on that crate. Therefore it
|
||||
/// must be kept compatible with that type from the target substrate version.
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReadProof<Hash> {
|
||||
/// Block hash used to generate the proof
|
||||
pub at: Hash,
|
||||
/// A proof used to prove that storage entries are included in the storage trie
|
||||
pub proof: Vec<Bytes>,
|
||||
}
|
||||
|
||||
/// Client for substrate rpc interfaces
|
||||
pub struct Rpc<T: Runtime> {
|
||||
client: Client,
|
||||
@@ -386,7 +435,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
let mut xt_sub = self.watch_extrinsic(extrinsic).await?;
|
||||
|
||||
while let status = xt_sub.next().await {
|
||||
log::info!("received status {:?}", status);
|
||||
// log::info!("received status {:?}", status);
|
||||
match status {
|
||||
// ignore in progress extrinsic for now
|
||||
TransactionStatus::Future
|
||||
|
||||
+47
-16
@@ -15,7 +15,6 @@
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use codec::Encode;
|
||||
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
|
||||
use sp_runtime::{
|
||||
generic::Header,
|
||||
impl_opaque_keys,
|
||||
@@ -32,32 +31,64 @@ use sp_std::prelude::*;
|
||||
/// BABE marker struct
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Babe;
|
||||
|
||||
/// Application specific crypto types
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// These are redefined here to avoid dependencies on the substrate creates where they are defined.
|
||||
/// They must be identical to the definitions in the target substrate version.
|
||||
pub mod app {
|
||||
use application_crypto::{
|
||||
app_crypto,
|
||||
ed25519,
|
||||
key_types,
|
||||
sr25519,
|
||||
};
|
||||
|
||||
/// Authority discovery app crypto types
|
||||
pub mod authority_discovery {
|
||||
use super::*;
|
||||
app_crypto!(sr25519, key_types::AUTHORITY_DISCOVERY);
|
||||
}
|
||||
/// Babe app crypto types
|
||||
pub mod babe {
|
||||
use super::*;
|
||||
app_crypto!(sr25519, key_types::BABE);
|
||||
}
|
||||
/// Im online discovery app crypto types
|
||||
pub mod im_online {
|
||||
use super::*;
|
||||
app_crypto!(ed25519, key_types::IM_ONLINE);
|
||||
}
|
||||
/// Grandpa app crypto types
|
||||
pub mod grandpa {
|
||||
use super::*;
|
||||
app_crypto!(ed25519, key_types::GRANDPA);
|
||||
}
|
||||
/// Validator app crypto types
|
||||
pub mod validator {
|
||||
use super::*;
|
||||
app_crypto!(ed25519, sp_core::crypto::KeyTypeId(*b"para"));
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_runtime::BoundToRuntimeAppPublic for Babe {
|
||||
type Public = sp_consensus_babe::AuthorityId;
|
||||
type Public = app::babe::Public;
|
||||
}
|
||||
|
||||
/// ImOnline marker struct
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct ImOnline;
|
||||
impl sp_runtime::BoundToRuntimeAppPublic for ImOnline {
|
||||
type Public = ImOnlineId;
|
||||
type Public = app::im_online::Public;
|
||||
}
|
||||
|
||||
/// GRANDPA marker struct
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Grandpa;
|
||||
impl sp_runtime::BoundToRuntimeAppPublic for Grandpa {
|
||||
type Public = sp_finality_grandpa::AuthorityId;
|
||||
}
|
||||
|
||||
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
|
||||
mod validator_app {
|
||||
use application_crypto::{
|
||||
app_crypto,
|
||||
sr25519,
|
||||
};
|
||||
app_crypto!(sr25519, sp_core::crypto::KeyTypeId(*b"para"));
|
||||
type Public = app::grandpa::Public;
|
||||
}
|
||||
|
||||
/// Parachain marker struct
|
||||
@@ -65,14 +96,14 @@ mod validator_app {
|
||||
pub struct Parachains;
|
||||
|
||||
impl sp_runtime::BoundToRuntimeAppPublic for Parachains {
|
||||
type Public = validator_app::Public;
|
||||
type Public = app::validator::Public;
|
||||
}
|
||||
|
||||
/// Authority discovery marker struct
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct AuthorityDiscovery;
|
||||
impl sp_runtime::BoundToRuntimeAppPublic for AuthorityDiscovery {
|
||||
type Public = AuthorityDiscoveryId;
|
||||
type Public = app::authority_discovery::Public;
|
||||
}
|
||||
|
||||
impl_opaque_keys! {
|
||||
|
||||
Reference in New Issue
Block a user