mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
committed by
Bastian Köcher
parent
31a6cbeafb
commit
cb100624a6
@@ -138,6 +138,15 @@ struct ClientData {
|
|||||||
client: Arc<RpcClient>,
|
client: Arc<RpcClient>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Already encoded value.
|
||||||
|
struct PreEncoded(Vec<u8>);
|
||||||
|
|
||||||
|
impl Encode for PreEncoded {
|
||||||
|
fn encode(&self) -> Vec<u8> {
|
||||||
|
self.0.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: Chain> relay_utils::relay_loop::Client for Client<C> {
|
impl<C: Chain> relay_utils::relay_loop::Client for Client<C> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
@@ -438,6 +447,16 @@ impl<C: Chain> Client<C> {
|
|||||||
///
|
///
|
||||||
/// Note: The given transaction needs to be SCALE encoded beforehand.
|
/// Note: The given transaction needs to be SCALE encoded beforehand.
|
||||||
pub async fn submit_unsigned_extrinsic(&self, transaction: Bytes) -> Result<C::Hash> {
|
pub async fn submit_unsigned_extrinsic(&self, transaction: Bytes) -> Result<C::Hash> {
|
||||||
|
// one last check that the transaction is valid. Most of checks happen in the relay loop and
|
||||||
|
// it is the "final" check before submission.
|
||||||
|
let best_header_hash = self.best_header().await?.hash();
|
||||||
|
self.validate_transaction(best_header_hash, PreEncoded(transaction.0.clone()))
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!(target: "bridge", "Pre-submit {} transaction validation failed: {:?}", C::NAME, e);
|
||||||
|
e
|
||||||
|
})??;
|
||||||
|
|
||||||
self.jsonrpsee_execute(move |client| async move {
|
self.jsonrpsee_execute(move |client| async move {
|
||||||
let tx_hash = SubstrateAuthorClient::<C>::submit_extrinsic(&*client, transaction)
|
let tx_hash = SubstrateAuthorClient::<C>::submit_extrinsic(&*client, transaction)
|
||||||
.await
|
.await
|
||||||
@@ -494,9 +513,19 @@ impl<C: Chain> Client<C> {
|
|||||||
// will be dropped from the pool.
|
// will be dropped from the pool.
|
||||||
let best_header_id = best_header.parent_id().unwrap_or_else(|| best_header.id());
|
let best_header_id = best_header.parent_id().unwrap_or_else(|| best_header.id());
|
||||||
|
|
||||||
self.jsonrpsee_execute(move |client| async move {
|
|
||||||
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce)?;
|
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce)?;
|
||||||
let signed_extrinsic = C::sign_transaction(signing_data, extrinsic)?.encode();
|
let signed_extrinsic = C::sign_transaction(signing_data, extrinsic)?.encode();
|
||||||
|
|
||||||
|
// one last check that the transaction is valid. Most of checks happen in the relay loop and
|
||||||
|
// it is the "final" check before submission.
|
||||||
|
self.validate_transaction(best_header_id.1, PreEncoded(signed_extrinsic.clone()))
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!(target: "bridge", "Pre-submit {} transaction validation failed: {:?}", C::NAME, e);
|
||||||
|
e
|
||||||
|
})??;
|
||||||
|
|
||||||
|
self.jsonrpsee_execute(move |client| async move {
|
||||||
let tx_hash =
|
let tx_hash =
|
||||||
SubstrateAuthorClient::<C>::submit_extrinsic(&*client, Bytes(signed_extrinsic))
|
SubstrateAuthorClient::<C>::submit_extrinsic(&*client, Bytes(signed_extrinsic))
|
||||||
.await
|
.await
|
||||||
@@ -529,9 +558,7 @@ impl<C: Chain> Client<C> {
|
|||||||
let transaction_nonce = self.next_account_index(signer.public().into()).await?;
|
let transaction_nonce = self.next_account_index(signer.public().into()).await?;
|
||||||
let best_header = self.best_header().await?;
|
let best_header = self.best_header().await?;
|
||||||
let best_header_id = best_header.id();
|
let best_header_id = best_header.id();
|
||||||
let (sender, receiver) = futures::channel::mpsc::channel(MAX_SUBSCRIPTION_CAPACITY);
|
|
||||||
let (tracker, subscription) = self
|
|
||||||
.jsonrpsee_execute(move |client| async move {
|
|
||||||
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce)?;
|
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce)?;
|
||||||
let stall_timeout = transaction_stall_timeout(
|
let stall_timeout = transaction_stall_timeout(
|
||||||
extrinsic.era.mortality_period(),
|
extrinsic.era.mortality_period(),
|
||||||
@@ -539,6 +566,19 @@ impl<C: Chain> Client<C> {
|
|||||||
STALL_TIMEOUT,
|
STALL_TIMEOUT,
|
||||||
);
|
);
|
||||||
let signed_extrinsic = C::sign_transaction(signing_data, extrinsic)?.encode();
|
let signed_extrinsic = C::sign_transaction(signing_data, extrinsic)?.encode();
|
||||||
|
|
||||||
|
// one last check that the transaction is valid. Most of checks happen in the relay loop and
|
||||||
|
// it is the "final" check before submission.
|
||||||
|
self.validate_transaction(best_header_id.1, PreEncoded(signed_extrinsic.clone()))
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!(target: "bridge", "Pre-submit {} transaction validation failed: {:?}", C::NAME, e);
|
||||||
|
e
|
||||||
|
})??;
|
||||||
|
|
||||||
|
let (sender, receiver) = futures::channel::mpsc::channel(MAX_SUBSCRIPTION_CAPACITY);
|
||||||
|
let (tracker, subscription) = self
|
||||||
|
.jsonrpsee_execute(move |client| async move {
|
||||||
let tx_hash = C::Hasher::hash(&signed_extrinsic);
|
let tx_hash = C::Hasher::hash(&signed_extrinsic);
|
||||||
let subscription = SubstrateAuthorClient::<C>::submit_and_watch_extrinsic(
|
let subscription = SubstrateAuthorClient::<C>::submit_and_watch_extrinsic(
|
||||||
&*client,
|
&*client,
|
||||||
|
|||||||
Reference in New Issue
Block a user