mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Update to parity-scale-codec (#3232)
* WIP: update codec * WIP * compiling * WIP * rename parity-scale-codec to codec * WIP * fix * remove old comments * use published crates * fix expected error msg * bump version * fmt and fix * remove old comment * fix wrong decoding impl * implement encode like for structures * undo removal of old pending changes * trailingzeroinput * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * update codec * fmt * version is 1.0.0 * show more error * fmt
This commit is contained in:
committed by
Bastian Köcher
parent
a0d442333f
commit
4ed67e03a4
@@ -19,7 +19,6 @@
|
||||
use client;
|
||||
use transaction_pool::txpool;
|
||||
use crate::rpc;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
/// Author RPC Result type.
|
||||
@@ -36,8 +35,8 @@ pub enum Error {
|
||||
#[display(fmt="Extrinsic verification error: {}", _0)]
|
||||
Verification(Box<dyn std::error::Error + Send>),
|
||||
/// Incorrect extrinsic format.
|
||||
#[display(fmt="Invalid extrinsic format")]
|
||||
BadFormat,
|
||||
#[display(fmt="Invalid extrinsic format: {}", _0)]
|
||||
BadFormat(codec::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
@@ -78,9 +77,9 @@ impl From<Error> for rpc::Error {
|
||||
use txpool::error::{Error as PoolError};
|
||||
|
||||
match e {
|
||||
Error::BadFormat => rpc::Error {
|
||||
Error::BadFormat(e) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(BAD_FORMAT),
|
||||
message: "Extrinsic has invalid format.".into(),
|
||||
message: format!("Extrinsic has invalid format: {}", e).into(),
|
||||
data: None,
|
||||
},
|
||||
Error::Verification(e) => rpc::Error {
|
||||
|
||||
@@ -30,7 +30,7 @@ use crate::subscriptions::Subscriptions;
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use log::warn;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use primitives::{Bytes, Blake2Hasher, H256};
|
||||
use sr_primitives::{generic, traits};
|
||||
use self::error::Result;
|
||||
@@ -110,7 +110,7 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
|
||||
type Metadata = crate::metadata::Metadata;
|
||||
|
||||
fn submit_extrinsic(&self, ext: Bytes) -> Result<ExHash<P>> {
|
||||
let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::BadFormat)?;
|
||||
let xt = Decode::decode(&mut &ext[..])?;
|
||||
let best_block_hash = self.client.info().chain.best_hash;
|
||||
self.pool
|
||||
.submit_one(&generic::BlockId::hash(best_block_hash), xt)
|
||||
@@ -129,7 +129,7 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
|
||||
.map(|x| match x {
|
||||
hash::ExtrinsicOrHash::Hash(h) => Ok(h),
|
||||
hash::ExtrinsicOrHash::Extrinsic(bytes) => {
|
||||
let xt = Decode::decode(&mut &bytes[..]).ok_or(error::Error::BadFormat)?;
|
||||
let xt = Decode::decode(&mut &bytes[..])?;
|
||||
Ok(self.pool.hash_of(&xt))
|
||||
},
|
||||
})
|
||||
@@ -146,8 +146,7 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
|
||||
fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: Subscriber<Status<ExHash<P>, BlockHash<P>>>, xt: Bytes) {
|
||||
let submit = || -> Result<_> {
|
||||
let best_block_hash = self.client.info().chain.best_hash;
|
||||
let dxt = <<P as PoolChainApi>::Block as traits::Block>::Extrinsic::decode(&mut &xt[..])
|
||||
.ok_or(error::Error::BadFormat)?;
|
||||
let dxt = <<P as PoolChainApi>::Block as traits::Block>::Extrinsic::decode(&mut &xt[..])?;
|
||||
self.pool
|
||||
.submit_and_watch(&generic::BlockId::hash(best_block_hash), dxt)
|
||||
.map_err(|e| e.into_pool_error()
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
use assert_matches::assert_matches;
|
||||
use parity_codec::Encode;
|
||||
use codec::Encode;
|
||||
use transaction_pool::{
|
||||
txpool::Pool,
|
||||
ChainApi,
|
||||
|
||||
Reference in New Issue
Block a user