mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-07 15:28:02 +00:00
9063d1acae
* Move `initialise_block` into `Core` trait as it is crucial calling the API functions * Switch to first version of new runtime API implementation * Fixes bug in tests * Reenable asserts * Directly use the `TestAPI` in the tests * Start improving the api traits :100644 100644 898aadc7 49217199 M Cargo.lock :100644 10064461570436465ed664 M core/client/src/backend.rs :100644 100644 5d0c886b 64d710fd M core/client/src/block_builder.rs :100644 100644 c447855e 5ecbe474 M core/client/src/client.rs :100644 100644139cef13f90dbf3d M core/client/src/error.rs :100644 100644 2800c503 3298e66a M core/client/src/runtime_api.rs :100644 100644affa1c5c809b08bc M core/primitives/src/lib.rs :100644 1006442877dfa9d5547413 M core/sr-api/Cargo.toml :100644 100644 9a49784d 6a625a03 M core/sr-api/src/lib.rs :100644 100644 7c28e1c7 a1a444a9 M core/sr-primitives/src/traits.rs :100644 1006442e113ab6dcc01a6d M srml/metadata/Cargo.toml :100644 100644ea722a700809531aM srml/metadata/src/lib.rs * Refactoring * Move `sr-api` into client and more refactoring * Fixes tests * Some documentation and cleanup * Fixes compilation after rebase * More refactoring and more documentation * Makes `substrate-client` compilable on `wasm` On `wasm` it basically just exports the runtime api stuff. * Fixes grumbles * Updates wasm files after rebasing the master * Remove TODO comment * Remove whitespaces * Fixes after rebasing master * Another rebase, another fix commit
83 lines
2.3 KiB
Rust
83 lines
2.3 KiB
Rust
// Copyright 2018 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/>.
|
|
|
|
//! Chain api required for the transaction pool.
|
|
|
|
use std::{
|
|
sync::Arc,
|
|
marker::PhantomData,
|
|
};
|
|
use client::{runtime_api::TaggedTransactionQueue, blockchain::HeaderBackend};
|
|
use parity_codec::Encode;
|
|
use txpool;
|
|
use substrate_primitives::{
|
|
H256,
|
|
Blake2Hasher,
|
|
Hasher,
|
|
};
|
|
use sr_primitives::{
|
|
generic::BlockId,
|
|
traits,
|
|
transaction_validity::TransactionValidity,
|
|
};
|
|
|
|
use error;
|
|
|
|
/// The transaction pool logic
|
|
pub struct ChainApi<T, Block> {
|
|
client: Arc<T>,
|
|
_marker: PhantomData<Block>,
|
|
}
|
|
|
|
impl<T, Block> ChainApi<T, Block> where
|
|
Block: traits::Block,
|
|
T: traits::ProvideRuntimeApi + HeaderBackend<Block> {
|
|
/// Create new transaction pool logic.
|
|
pub fn new(client: Arc<T>) -> Self {
|
|
ChainApi {
|
|
client,
|
|
_marker: Default::default()
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T, Block> txpool::ChainApi for ChainApi<T, Block> where
|
|
Block: traits::Block<Hash=H256>,
|
|
T: traits::ProvideRuntimeApi + HeaderBackend<Block>,
|
|
T::Api: TaggedTransactionQueue<Block>
|
|
{
|
|
type Block = Block;
|
|
type Hash = H256;
|
|
type Error = error::Error;
|
|
|
|
fn validate_transaction(&self, at: &BlockId<Self::Block>, uxt: &txpool::ExtrinsicFor<Self>) -> error::Result<TransactionValidity> {
|
|
Ok(self.client.runtime_api().validate_transaction(at, uxt)?)
|
|
}
|
|
|
|
// TODO [toDr] Use proper lbock number type
|
|
fn block_id_to_number(&self, at: &BlockId<Self::Block>) -> error::Result<Option<txpool::NumberFor<Self>>> {
|
|
Ok(self.client.block_number_from_id(at)?)
|
|
}
|
|
|
|
fn block_id_to_hash(&self, at: &BlockId<Self::Block>) -> error::Result<Option<txpool::BlockHash<Self>>> {
|
|
Ok(self.client.block_hash_from_id(at)?)
|
|
}
|
|
|
|
fn hash(&self, ex: &txpool::ExtrinsicFor<Self>) -> Self::Hash {
|
|
Blake2Hasher::hash(&ex.encode())
|
|
}
|
|
}
|