mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Have InInstructions track the latest block for a network in storage
This commit is contained in:
@@ -4,11 +4,24 @@ use primitives::SignedBatch;
|
||||
|
||||
use subxt::utils::Encoded;
|
||||
|
||||
use crate::{Serai, SeraiError};
|
||||
use crate::{
|
||||
primitives::{BlockHash, NetworkId},
|
||||
SeraiError, Serai, scale_value,
|
||||
};
|
||||
|
||||
pub type InInstructionsEvent = in_instructions::Event<Runtime>;
|
||||
|
||||
const PALLET: &str = "InInstructions";
|
||||
|
||||
impl Serai {
|
||||
pub async fn get_latest_block_for_network(
|
||||
&self,
|
||||
hash: [u8; 32],
|
||||
network: NetworkId,
|
||||
) -> Result<Option<BlockHash>, SeraiError> {
|
||||
self.storage(PALLET, "LatestBlock", Some(vec![scale_value(network)]), hash).await
|
||||
}
|
||||
|
||||
pub async fn get_batch_events(
|
||||
&self,
|
||||
block: [u8; 32],
|
||||
|
||||
@@ -41,6 +41,7 @@ serai_test!(
|
||||
let block = provide_batch(batch).await;
|
||||
|
||||
let serai = serai().await;
|
||||
assert_eq!(serai.get_latest_block_for_network(block, network).await.unwrap(), Some(block_hash));
|
||||
let batches = serai.get_batch_events(block).await.unwrap();
|
||||
assert_eq!(batches, vec![InInstructionsEvent::Batch { network, id, block: block_hash }]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user