mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 05:47:58 +00:00
Fix folder names in client and test (#4360)
* client/rpc/api -> client/rpc-api * client/util/wasm-builder-runner -> utils/wasm-builder-runner * client/grafana-data-source -> utils/grafana-data-source * test/utils -> test-utils * fix moved path * Update Cargo.lock * Update Cargo.lock
This commit is contained in:
committed by
GitHub
parent
8131dc8a66
commit
c5a709a882
@@ -0,0 +1,155 @@
|
||||
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Authoring RPC module errors.
|
||||
|
||||
use crate::errors;
|
||||
use jsonrpc_core as rpc;
|
||||
|
||||
/// Author RPC Result type.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Author RPC future Result type.
|
||||
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
|
||||
|
||||
/// Author RPC errors.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
pub enum Error {
|
||||
/// Client error.
|
||||
#[display(fmt="Client error: {}", _0)]
|
||||
#[from(ignore)]
|
||||
Client(Box<dyn std::error::Error + Send>),
|
||||
/// Transaction pool error,
|
||||
#[display(fmt="Transaction pool error: {}", _0)]
|
||||
Pool(txpool_api::error::Error),
|
||||
/// Verification error
|
||||
#[display(fmt="Extrinsic verification error: {}", _0)]
|
||||
#[from(ignore)]
|
||||
Verification(Box<dyn std::error::Error + Send>),
|
||||
/// Incorrect extrinsic format.
|
||||
#[display(fmt="Invalid extrinsic format: {}", _0)]
|
||||
BadFormat(codec::Error),
|
||||
/// Incorrect seed phrase.
|
||||
#[display(fmt="Invalid seed phrase/SURI")]
|
||||
BadSeedPhrase,
|
||||
/// Key type ID has an unknown format.
|
||||
#[display(fmt="Invalid key type ID format (should be of length four)")]
|
||||
BadKeyType,
|
||||
/// Key type ID has some unsupported crypto.
|
||||
#[display(fmt="The crypto of key type ID is unknown")]
|
||||
UnsupportedKeyType,
|
||||
/// Some random issue with the key store. Shouldn't happen.
|
||||
#[display(fmt="The key store is unavailable")]
|
||||
KeyStoreUnavailable,
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Client(ref err) => Some(&**err),
|
||||
Error::Pool(ref err) => Some(err),
|
||||
Error::Verification(ref err) => Some(&**err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Base code for all authorship errors.
|
||||
const BASE_ERROR: i64 = 1000;
|
||||
/// Extrinsic has an invalid format.
|
||||
const BAD_FORMAT: i64 = BASE_ERROR + 1;
|
||||
/// Error during transaction verification in runtime.
|
||||
const VERIFICATION_ERROR: i64 = BASE_ERROR + 2;
|
||||
|
||||
/// Pool rejected the transaction as invalid
|
||||
const POOL_INVALID_TX: i64 = BASE_ERROR + 10;
|
||||
/// Cannot determine transaction validity.
|
||||
const POOL_UNKNOWN_VALIDITY: i64 = POOL_INVALID_TX + 1;
|
||||
/// The transaction is temporarily banned.
|
||||
const POOL_TEMPORARILY_BANNED: i64 = POOL_INVALID_TX + 2;
|
||||
/// The transaction is already in the pool
|
||||
const POOL_ALREADY_IMPORTED: i64 = POOL_INVALID_TX + 3;
|
||||
/// Transaction has too low priority to replace existing one in the pool.
|
||||
const POOL_TOO_LOW_PRIORITY: i64 = POOL_INVALID_TX + 4;
|
||||
/// Including this transaction would cause a dependency cycle.
|
||||
const POOL_CYCLE_DETECTED: i64 = POOL_INVALID_TX + 5;
|
||||
/// The transaction was not included to the pool because of the limits.
|
||||
const POOL_IMMEDIATELY_DROPPED: i64 = POOL_INVALID_TX + 6;
|
||||
/// The key type crypto is not known.
|
||||
const UNSUPPORTED_KEY_TYPE: i64 = POOL_INVALID_TX + 7;
|
||||
|
||||
impl From<Error> for rpc::Error {
|
||||
fn from(e: Error) -> Self {
|
||||
use txpool_api::error::{Error as PoolError};
|
||||
|
||||
match e {
|
||||
Error::BadFormat(e) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(BAD_FORMAT),
|
||||
message: format!("Extrinsic has invalid format: {}", e).into(),
|
||||
data: None,
|
||||
},
|
||||
Error::Verification(e) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(VERIFICATION_ERROR),
|
||||
message: format!("Verification Error: {}", e).into(),
|
||||
data: Some(format!("{:?}", e).into()),
|
||||
},
|
||||
Error::Pool(PoolError::InvalidTransaction(e)) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_INVALID_TX),
|
||||
message: "Invalid Transaction".into(),
|
||||
data: serde_json::to_value(e).ok(),
|
||||
},
|
||||
Error::Pool(PoolError::UnknownTransaction(e)) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_UNKNOWN_VALIDITY),
|
||||
message: "Unknown Transaction Validity".into(),
|
||||
data: serde_json::to_value(e).ok(),
|
||||
},
|
||||
Error::Pool(PoolError::TemporarilyBanned) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_TEMPORARILY_BANNED),
|
||||
message: "Transaction is temporarily banned".into(),
|
||||
data: None,
|
||||
},
|
||||
Error::Pool(PoolError::AlreadyImported(hash)) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_ALREADY_IMPORTED),
|
||||
message: "Transaction Already Imported".into(),
|
||||
data: Some(format!("{:?}", hash).into()),
|
||||
},
|
||||
Error::Pool(PoolError::TooLowPriority { old, new }) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_TOO_LOW_PRIORITY),
|
||||
message: format!("Priority is too low: ({} vs {})", old, new),
|
||||
data: Some("The transaction has too low priority to replace another transaction already in the pool.".into()),
|
||||
},
|
||||
Error::Pool(PoolError::CycleDetected) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_CYCLE_DETECTED),
|
||||
message: "Cycle Detected".into(),
|
||||
data: None,
|
||||
},
|
||||
Error::Pool(PoolError::ImmediatelyDropped) => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(POOL_IMMEDIATELY_DROPPED),
|
||||
message: "Immediately Dropped".into(),
|
||||
data: Some("The transaction couldn't enter the pool because of the limit".into()),
|
||||
},
|
||||
Error::UnsupportedKeyType => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(UNSUPPORTED_KEY_TYPE),
|
||||
message: "Unknown key type crypto" .into(),
|
||||
data: Some(
|
||||
"The crypto for the given key type is unknown, please add the public key to the \
|
||||
request to insert the key successfully.".into()
|
||||
),
|
||||
},
|
||||
e => errors::internal(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Extrinsic helpers for author RPC module.
|
||||
|
||||
use primitives::Bytes;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// RPC Extrinsic or hash
|
||||
///
|
||||
/// Allows to refer to extrinsic either by its raw representation or its hash.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum ExtrinsicOrHash<Hash> {
|
||||
/// The hash of the extrinsic.
|
||||
Hash(Hash),
|
||||
/// Raw extrinsic bytes.
|
||||
Extrinsic(Bytes),
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Substrate block-author/full-node API.
|
||||
|
||||
pub mod error;
|
||||
pub mod hash;
|
||||
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use primitives::Bytes;
|
||||
use txpool_api::TransactionStatus;
|
||||
use self::error::{FutureResult, Result};
|
||||
|
||||
pub use self::gen_client::Client as AuthorClient;
|
||||
|
||||
/// Substrate authoring RPC API
|
||||
#[rpc]
|
||||
pub trait AuthorApi<Hash, BlockHash> {
|
||||
/// RPC metadata
|
||||
type Metadata;
|
||||
|
||||
/// Submit hex-encoded extrinsic for inclusion in block.
|
||||
#[rpc(name = "author_submitExtrinsic")]
|
||||
fn submit_extrinsic(&self, extrinsic: Bytes) -> FutureResult<Hash>;
|
||||
|
||||
/// Insert a key into the keystore.
|
||||
#[rpc(name = "author_insertKey")]
|
||||
fn insert_key(&self,
|
||||
key_type: String,
|
||||
suri: String,
|
||||
public: Bytes,
|
||||
) -> Result<()>;
|
||||
|
||||
/// Generate new session keys and returns the corresponding public keys.
|
||||
#[rpc(name = "author_rotateKeys")]
|
||||
fn rotate_keys(&self) -> Result<Bytes>;
|
||||
|
||||
/// Returns all pending extrinsics, potentially grouped by sender.
|
||||
#[rpc(name = "author_pendingExtrinsics")]
|
||||
fn pending_extrinsics(&self) -> Result<Vec<Bytes>>;
|
||||
|
||||
/// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
|
||||
#[rpc(name = "author_removeExtrinsic")]
|
||||
fn remove_extrinsic(&self,
|
||||
bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>
|
||||
) -> Result<Vec<Hash>>;
|
||||
|
||||
/// Submit an extrinsic to watch.
|
||||
#[pubsub(
|
||||
subscription = "author_extrinsicUpdate",
|
||||
subscribe,
|
||||
name = "author_submitAndWatchExtrinsic"
|
||||
)]
|
||||
fn watch_extrinsic(&self,
|
||||
metadata: Self::Metadata,
|
||||
subscriber: Subscriber<TransactionStatus<Hash, BlockHash>>,
|
||||
bytes: Bytes
|
||||
);
|
||||
|
||||
/// Unsubscribe from extrinsic watching.
|
||||
#[pubsub(
|
||||
subscription = "author_extrinsicUpdate",
|
||||
unsubscribe,
|
||||
name = "author_unwatchExtrinsic"
|
||||
)]
|
||||
fn unwatch_extrinsic(&self,
|
||||
metadata: Option<Self::Metadata>,
|
||||
id: SubscriptionId
|
||||
) -> Result<bool>;
|
||||
}
|
||||
Reference in New Issue
Block a user