mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Misc tidying of serai-db calls
This commit is contained in:
@@ -107,7 +107,7 @@ create_db!(
|
||||
pub(crate) struct ScannerGlobalDb<S: ScannerFeed>(PhantomData<S>);
|
||||
impl<S: ScannerFeed> ScannerGlobalDb<S> {
|
||||
pub(crate) fn has_any_key_been_queued(getter: &impl Get) -> bool {
|
||||
ActiveKeys::get::<EncodableG<KeyFor<S>>>(getter).is_some()
|
||||
ActiveKeys::<EncodableG<KeyFor<S>>>::get(getter).is_some()
|
||||
}
|
||||
|
||||
/// Queue a key.
|
||||
@@ -315,7 +315,7 @@ pub(crate) struct ReceiverScanData<S: ScannerFeed> {
|
||||
|
||||
db_channel! {
|
||||
ScannerScanEventuality {
|
||||
ScannedBlock: (empty_key: ()) -> Vec<u8>,
|
||||
ScannedBlock: () -> Vec<u8>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,14 +364,14 @@ impl<S: ScannerFeed> ScanToEventualityDb<S> {
|
||||
for output in &data.returns {
|
||||
output.write(&mut buf).unwrap();
|
||||
}
|
||||
ScannedBlock::send(txn, (), &buf);
|
||||
ScannedBlock::send(txn, &buf);
|
||||
}
|
||||
pub(crate) fn recv_scan_data(
|
||||
txn: &mut impl DbTxn,
|
||||
expected_block_number: u64,
|
||||
) -> ReceiverScanData<S> {
|
||||
let data =
|
||||
ScannedBlock::try_recv(txn, ()).expect("receiving data for a scanned block not yet sent");
|
||||
ScannedBlock::try_recv(txn).expect("receiving data for a scanned block not yet sent");
|
||||
let mut data = data.as_slice();
|
||||
|
||||
let block_number = {
|
||||
@@ -462,7 +462,7 @@ struct BlockBoundInInstructions {
|
||||
|
||||
db_channel! {
|
||||
ScannerScanReport {
|
||||
InInstructions: (empty_key: ()) -> BlockBoundInInstructions,
|
||||
InInstructions: () -> BlockBoundInInstructions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,7 +484,6 @@ impl<S: ScannerFeed> ScanToReportDb<S> {
|
||||
}
|
||||
InInstructions::send(
|
||||
txn,
|
||||
(),
|
||||
&BlockBoundInInstructions { block_number, returnable_in_instructions: buf },
|
||||
);
|
||||
}
|
||||
@@ -493,7 +492,7 @@ impl<S: ScannerFeed> ScanToReportDb<S> {
|
||||
txn: &mut impl DbTxn,
|
||||
block_number: u64,
|
||||
) -> InInstructionData<S> {
|
||||
let data = InInstructions::try_recv(txn, ())
|
||||
let data = InInstructions::try_recv(txn)
|
||||
.expect("receiving InInstructions for a scanned block not yet sent");
|
||||
assert_eq!(
|
||||
block_number, data.block_number,
|
||||
@@ -556,7 +555,7 @@ mod _public_db {
|
||||
|
||||
db_channel! {
|
||||
ScannerPublic {
|
||||
Batches: (empty_key: ()) -> Batch,
|
||||
Batches: () -> Batch,
|
||||
BatchesToSign: (key: &[u8]) -> Batch,
|
||||
AcknowledgedBatches: (key: &[u8]) -> u32,
|
||||
CompletedEventualities: (key: &[u8]) -> [u8; 32],
|
||||
@@ -570,12 +569,12 @@ mod _public_db {
|
||||
pub struct Batches;
|
||||
impl Batches {
|
||||
pub(crate) fn send(txn: &mut impl DbTxn, batch: &Batch) {
|
||||
_public_db::Batches::send(txn, (), batch);
|
||||
_public_db::Batches::send(txn, batch);
|
||||
}
|
||||
|
||||
/// Receive a batch to publish.
|
||||
pub fn try_recv(txn: &mut impl DbTxn) -> Option<Batch> {
|
||||
_public_db::Batches::try_recv(txn, ())
|
||||
_public_db::Batches::try_recv(txn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +54,7 @@ impl<S: ScannerFeed> ReportDb<S> {
|
||||
}
|
||||
|
||||
pub(crate) fn take_block_number_for_batch(txn: &mut impl DbTxn, id: u32) -> Option<u64> {
|
||||
let block_number = BlockNumberForBatch::get(txn, id)?;
|
||||
BlockNumberForBatch::del(txn, id);
|
||||
Some(block_number)
|
||||
BlockNumberForBatch::take(txn, id)
|
||||
}
|
||||
|
||||
pub(crate) fn save_external_key_for_session_to_sign_batch(
|
||||
@@ -103,8 +101,7 @@ impl<S: ScannerFeed> ReportDb<S> {
|
||||
txn: &mut impl DbTxn,
|
||||
id: u32,
|
||||
) -> Option<Vec<Option<ReturnInformation<S>>>> {
|
||||
let buf = SerializedReturnAddresses::get(txn, id)?;
|
||||
SerializedReturnAddresses::del(txn, id);
|
||||
let buf = SerializedReturnAddresses::take(txn, id)?;
|
||||
let mut buf = buf.as_slice();
|
||||
|
||||
let mut res = Vec::with_capacity(buf.len() / (32 + 1 + 8));
|
||||
|
||||
@@ -37,7 +37,7 @@ pub(crate) enum Action<S: ScannerFeed> {
|
||||
|
||||
db_channel!(
|
||||
ScannerSubstrate {
|
||||
Actions: (empty_key: ()) -> ActionEncodable,
|
||||
Actions: () -> ActionEncodable,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -52,7 +52,6 @@ impl<S: ScannerFeed> SubstrateDb<S> {
|
||||
) {
|
||||
Actions::send(
|
||||
txn,
|
||||
(),
|
||||
&ActionEncodable::AcknowledgeBatch(AcknowledgeBatchEncodable {
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
@@ -62,11 +61,11 @@ impl<S: ScannerFeed> SubstrateDb<S> {
|
||||
);
|
||||
}
|
||||
pub(crate) fn queue_queue_burns(txn: &mut impl DbTxn, burns: Vec<OutInstructionWithBalance>) {
|
||||
Actions::send(txn, (), &ActionEncodable::QueueBurns(burns));
|
||||
Actions::send(txn, &ActionEncodable::QueueBurns(burns));
|
||||
}
|
||||
|
||||
pub(crate) fn next_action(txn: &mut impl DbTxn) -> Option<Action<S>> {
|
||||
let action_encodable = Actions::try_recv(txn, ())?;
|
||||
let action_encodable = Actions::try_recv(txn)?;
|
||||
Some(match action_encodable {
|
||||
ActionEncodable::AcknowledgeBatch(AcknowledgeBatchEncodable {
|
||||
batch_id,
|
||||
|
||||
Reference in New Issue
Block a user