mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Handle batch n+1 being signed before batch n is
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use scale::Encode;
|
||||
use serai_client::primitives::{NetworkId, BlockHash};
|
||||
use scale::{Encode, Decode};
|
||||
use serai_client::{
|
||||
primitives::{NetworkId, BlockHash},
|
||||
in_instructions::primitives::SignedBatch,
|
||||
};
|
||||
|
||||
pub use serai_db::*;
|
||||
|
||||
@@ -95,4 +98,19 @@ impl<'a, D: Db> MainDb<'a, D> {
|
||||
pub fn first_preprocess<G: Get>(getter: &G, id: [u8; 32]) -> Option<Vec<u8>> {
|
||||
getter.get(Self::first_preprocess_key(id))
|
||||
}
|
||||
|
||||
fn batch_key(network: NetworkId, id: u32) -> Vec<u8> {
|
||||
Self::main_key(b"batch", (network, id).encode())
|
||||
}
|
||||
pub fn save_batch(&mut self, batch: SignedBatch) {
|
||||
let mut txn = self.0.txn();
|
||||
txn.put(Self::batch_key(batch.batch.network, batch.batch.id), batch.encode());
|
||||
txn.commit();
|
||||
}
|
||||
pub fn batch(&self, network: NetworkId, id: u32) -> Option<SignedBatch> {
|
||||
self
|
||||
.0
|
||||
.get(Self::batch_key(network, id))
|
||||
.map(|batch| SignedBatch::decode(&mut batch.as_ref()).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user