mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-28 06:29:38 +00:00
c511a54d18
Uses a full-fledged serai-abi to do so. Removes use of UncheckedExtrinsic as a pointlessly (for us) length-prefixed block with a more complicated signing algorithm than advantageous. In the future, we should considering consolidating the various primitives crates. I'm not convinced we benefit from one primitives crate per pallet.
46 lines
1,018 B
Rust
46 lines
1,018 B
Rust
use core::time::Duration;
|
|
|
|
use tokio::time::sleep;
|
|
|
|
use serai_client::{Transaction, Serai};
|
|
|
|
#[allow(dead_code)]
|
|
pub async fn publish_tx(serai: &Serai, tx: &Transaction) -> [u8; 32] {
|
|
let mut latest = serai
|
|
.block(serai.latest_finalized_block_hash().await.unwrap())
|
|
.await
|
|
.unwrap()
|
|
.unwrap()
|
|
.number();
|
|
|
|
serai.publish(tx).await.unwrap();
|
|
|
|
// Get the block it was included in
|
|
// TODO: Add an RPC method for this/check the guarantee on the subscription
|
|
let mut ticks = 0;
|
|
loop {
|
|
latest += 1;
|
|
|
|
let block = {
|
|
let mut block;
|
|
while {
|
|
block = serai.finalized_block_by_number(latest).await.unwrap();
|
|
block.is_none()
|
|
} {
|
|
sleep(Duration::from_secs(1)).await;
|
|
ticks += 1;
|
|
|
|
if ticks > 60 {
|
|
panic!("60 seconds without inclusion in a finalized block");
|
|
}
|
|
}
|
|
block.unwrap()
|
|
};
|
|
|
|
for transaction in &block.transactions {
|
|
if transaction == tx {
|
|
return block.hash();
|
|
}
|
|
}
|
|
}
|
|
}
|