mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
transaction-pool: expose blocking api for tx submission (#6325)
* transaction-pool: expose blocking api for tx submission * service: separate ServiceBuilder::build for full and light * service: add ServiceBuilder::build_common * transaction-pool: extend docs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
@@ -352,6 +352,59 @@ impl<PoolApi, Block> TransactionPool for BasicPool<PoolApi, Block>
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, Client> sp_transaction_pool::LocalTransactionPool
|
||||
for BasicPool<FullChainApi<Client, Block>, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
Client: sp_api::ProvideRuntimeApi<Block>
|
||||
+ sc_client_api::BlockBackend<Block>
|
||||
+ sp_runtime::traits::BlockIdTo<Block>,
|
||||
Client: Send + Sync + 'static,
|
||||
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
|
||||
sp_api::ApiErrorFor<Client, Block>: Send + std::fmt::Display,
|
||||
{
|
||||
type Block = Block;
|
||||
type Hash = sc_transaction_graph::ExtrinsicHash<FullChainApi<Client, Block>>;
|
||||
type Error = <FullChainApi<Client, Block> as ChainApi>::Error;
|
||||
|
||||
fn submit_local(
|
||||
&self,
|
||||
at: &BlockId<Self::Block>,
|
||||
xt: sp_transaction_pool::LocalTransactionFor<Self>,
|
||||
) -> Result<Self::Hash, Self::Error> {
|
||||
use sc_transaction_graph::ValidatedTransaction;
|
||||
use sp_runtime::traits::SaturatedConversion;
|
||||
use sp_runtime::transaction_validity::TransactionValidityError;
|
||||
|
||||
let validity = self
|
||||
.api
|
||||
.validate_transaction_blocking(at, TransactionSource::Local, xt.clone())?
|
||||
.map_err(|e| {
|
||||
Self::Error::Pool(match e {
|
||||
TransactionValidityError::Invalid(i) => i.into(),
|
||||
TransactionValidityError::Unknown(u) => u.into(),
|
||||
})
|
||||
})?;
|
||||
|
||||
let (hash, bytes) = self.pool.validated_pool().api().hash_and_length(&xt);
|
||||
let block_number = self
|
||||
.api
|
||||
.block_id_to_number(at)?
|
||||
.ok_or_else(|| error::Error::BlockIdConversion(format!("{:?}", at)))?;
|
||||
|
||||
let validated = ValidatedTransaction::valid_at(
|
||||
block_number.saturated_into::<u64>(),
|
||||
hash.clone(),
|
||||
TransactionSource::Local,
|
||||
xt,
|
||||
bytes,
|
||||
validity,
|
||||
);
|
||||
|
||||
self.pool.validated_pool().submit(vec![validated]).remove(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
enum RevalidationStatus<N> {
|
||||
/// The revalidation has never been completed.
|
||||
|
||||
Reference in New Issue
Block a user