mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Remove unneeded Serde requirements (#1076)
* Remove superfluous serde requirements. * Try to ensure hash is serde * Fixups * Building again * Attempt to reenable Block (doesn't build) * Fixes compilation for node cli * Fixes test compilation * Fix wasm * Fix tests * Remove unneeded changes * Fix up comments * Reenable some code * Compile error when origin misused. * Remove unnecessary includes of `serde_derive` * Cleanups
This commit is contained in:
@@ -19,13 +19,12 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use client::{self, Client};
|
||||
use codec::Decode;
|
||||
use codec::{Encode, Decode};
|
||||
use transaction_pool::{
|
||||
txpool::{
|
||||
ChainApi as PoolChainApi,
|
||||
BlockHash,
|
||||
ExHash,
|
||||
ExtrinsicFor,
|
||||
IntoPoolError,
|
||||
Pool,
|
||||
watcher::Status,
|
||||
@@ -47,19 +46,16 @@ use self::error::Result;
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Substrate authoring RPC API
|
||||
pub trait AuthorApi<Hash, BlockHash, Extrinsic, PendingExtrinsics> {
|
||||
pub trait AuthorApi<Hash, BlockHash> {
|
||||
type Metadata;
|
||||
|
||||
/// Submit extrinsic for inclusion in block.
|
||||
#[rpc(name = "author_submitRichExtrinsic")]
|
||||
fn submit_rich_extrinsic(&self, Extrinsic) -> Result<Hash>;
|
||||
/// Submit hex-encoded extrinsic for inclusion in block.
|
||||
#[rpc(name = "author_submitExtrinsic")]
|
||||
fn submit_extrinsic(&self, Bytes) -> Result<Hash>;
|
||||
|
||||
/// Returns all pending extrinsics, potentially grouped by sender.
|
||||
#[rpc(name = "author_pendingExtrinsics")]
|
||||
fn pending_extrinsics(&self) -> Result<PendingExtrinsics>;
|
||||
fn pending_extrinsics(&self) -> Result<Vec<Bytes>>;
|
||||
|
||||
#[pubsub(name = "author_extrinsicUpdate")] {
|
||||
/// Submit an extrinsic to watch.
|
||||
@@ -103,7 +99,7 @@ impl<B, E, P> Author<B, E, P> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>, ExtrinsicFor<P>, Vec<ExtrinsicFor<P>>> for Author<B, E, P> where
|
||||
impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P> where
|
||||
B: client::backend::Backend<<P as PoolChainApi>::Block, Blake2Hasher> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<<P as PoolChainApi>::Block, Blake2Hasher> + Send + Sync + 'static,
|
||||
P: PoolChainApi + Sync + Send + 'static,
|
||||
@@ -112,12 +108,8 @@ impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>, ExtrinsicFor<P>, Vec<ExtrinsicF
|
||||
{
|
||||
type Metadata = ::metadata::Metadata;
|
||||
|
||||
fn submit_extrinsic(&self, xt: Bytes) -> Result<ExHash<P>> {
|
||||
let dxt = Decode::decode(&mut &xt[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?;
|
||||
self.submit_rich_extrinsic(dxt)
|
||||
}
|
||||
|
||||
fn submit_rich_extrinsic(&self, xt: <<P as PoolChainApi>::Block as traits::Block>::Extrinsic) -> Result<ExHash<P>> {
|
||||
fn submit_extrinsic(&self, ext: Bytes) -> Result<ExHash<P>> {
|
||||
let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?;
|
||||
let best_block_hash = self.client.info()?.chain.best_hash;
|
||||
self.pool
|
||||
.submit_one(&generic::BlockId::hash(best_block_hash), xt)
|
||||
@@ -127,8 +119,8 @@ impl<B, E, P> AuthorApi<ExHash<P>, BlockHash<P>, ExtrinsicFor<P>, Vec<ExtrinsicF
|
||||
)
|
||||
}
|
||||
|
||||
fn pending_extrinsics(&self) -> Result<Vec<ExtrinsicFor<P>>> {
|
||||
Ok(self.pool.ready().map(|tx| tx.data.clone()).collect())
|
||||
fn pending_extrinsics(&self) -> Result<Vec<Bytes>> {
|
||||
Ok(self.pool.ready().map(|tx| tx.data.encode().into()).collect())
|
||||
}
|
||||
|
||||
fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: pubsub::Subscriber<Status<ExHash<P>, BlockHash<P>>>, xt: Bytes) {
|
||||
|
||||
@@ -71,11 +71,11 @@ fn submit_rich_transaction_should_not_cause_error() {
|
||||
let h: H256 = hex!("fccc48291473c53746cd267cf848449edd7711ee6511fba96919d5f9f4859e4f").into();
|
||||
|
||||
assert_matches!(
|
||||
AuthorApi::submit_rich_extrinsic(&p, uxt(Keyring::Alice, 0)),
|
||||
AuthorApi::submit_extrinsic(&p, uxt(Keyring::Alice, 0).encode().into()),
|
||||
Ok(h2) if h == h2
|
||||
);
|
||||
assert!(
|
||||
AuthorApi::submit_rich_extrinsic(&p, uxt(Keyring::Alice, 0)).is_err()
|
||||
AuthorApi::submit_extrinsic(&p, uxt(Keyring::Alice, 0).encode().into()).is_err()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ fn should_watch_extrinsic() {
|
||||
let signature = Keyring::from_raw_public(tx.from.to_fixed_bytes()).unwrap().sign(&tx.encode()).into();
|
||||
Extrinsic { transfer: tx, signature }
|
||||
};
|
||||
AuthorApi::submit_rich_extrinsic(&p, replacement).unwrap();
|
||||
AuthorApi::submit_extrinsic(&p, replacement.encode().into()).unwrap();
|
||||
let (res, data) = runtime.block_on(data.into_future()).unwrap();
|
||||
assert_eq!(
|
||||
res,
|
||||
@@ -131,9 +131,9 @@ fn should_return_pending_extrinsics() {
|
||||
subscriptions: Subscriptions::new(runtime.executor()),
|
||||
};
|
||||
let ex = uxt(Keyring::Alice, 0);
|
||||
AuthorApi::submit_rich_extrinsic(&p, ex.clone()).unwrap();
|
||||
AuthorApi::submit_extrinsic(&p, ex.encode().into()).unwrap();
|
||||
assert_matches!(
|
||||
p.pending_extrinsics(),
|
||||
Ok(ref expected) if expected == &vec![ex]
|
||||
Ok(ref expected) if *expected == vec![Bytes(ex.encode())]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user