Skip to content

Commit

Permalink
improve custom queries
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Mar 11, 2024
1 parent 3f239f7 commit 7290c3c
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,19 @@ pub trait OutputManagerBackend: Send + Sync + Clone {
fn write(&self, op: WriteOperation) -> Result<Option<DbValue>, OutputManagerStorageError>;
fn fetch_pending_incoming_outputs(&self) -> Result<Vec<DbWalletOutput>, OutputManagerStorageError>;
/// Perform a batch update of the received outputs' mined height and status
fn set_received_outputs_mined_height_and_status_batch_mode(
fn set_received_outputs_mined_height_and_statuses(
&self,
updates: Vec<ReceivedOutputInfoForBatch>,
) -> Result<(), OutputManagerStorageError>;
/// Perform a batch update of the outputs' unmined and invalid state
fn set_output_to_unmined_and_invalid_batch_mode(
&self,
hashes: Vec<FixedHash>,
) -> Result<(), OutputManagerStorageError>;
fn set_outputs_to_unmined_and_invalid(&self, hashes: Vec<FixedHash>) -> Result<(), OutputManagerStorageError>;
/// Perform a batch update of the outputs' last validation timestamp
fn update_last_validation_timestamp_batch_mode(
&self,
hashes: Vec<FixedHash>,
) -> Result<(), OutputManagerStorageError>;
fn update_last_validation_timestamps(&self, hashes: Vec<FixedHash>) -> Result<(), OutputManagerStorageError>;
fn set_outputs_to_be_revalidated(&self) -> Result<(), OutputManagerStorageError>;
/// Perform a batch update of the outputs' spent status
fn mark_output_as_spent_batch_mode(
&self,
updates: Vec<SpentOutputInfoForBatch>,
) -> Result<(), OutputManagerStorageError>;
fn mark_outputs_as_spent(&self, updates: Vec<SpentOutputInfoForBatch>) -> Result<(), OutputManagerStorageError>;
/// Perform a batch update of the outputs' unspent status
fn mark_output_as_unspent_batch_mode(
&self,
hashes: Vec<(FixedHash, bool)>,
) -> Result<(), OutputManagerStorageError>;
fn mark_outputs_as_unspent(&self, hashes: Vec<(FixedHash, bool)>) -> Result<(), OutputManagerStorageError>;
/// This method encumbers the specified outputs into a `PendingTransactionOutputs` record. This is a short term
/// encumberance in case the app is closed or crashes before transaction neogtiation is complete. These will be
/// cleared on startup of the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,42 +381,18 @@ where T: OutputManagerBackend + 'static
Ok(())
}

pub fn set_received_output_mined_height_and_status(
&self,
hash: HashOutput,
mined_height: u64,
mined_in_block: HashOutput,
confirmed: bool,
mined_timestamp: u64,
) -> Result<(), OutputManagerStorageError> {
self.set_received_outputs_mined_height_and_status_batch_mode(vec![ReceivedOutputInfoForBatch {
hash,
mined_height,
mined_in_block,
confirmed,
mined_timestamp,
}])
}

pub fn set_received_outputs_mined_height_and_status_batch_mode(
pub fn set_received_outputs_mined_height_and_statuses(
&self,
updates: Vec<ReceivedOutputInfoForBatch>,
) -> Result<(), OutputManagerStorageError> {
let db = self.db.clone();
db.set_received_outputs_mined_height_and_status_batch_mode(updates)?;
db.set_received_outputs_mined_height_and_statuses(updates)?;
Ok(())
}

pub fn set_output_to_unmined_and_invalid(&self, hash: HashOutput) -> Result<(), OutputManagerStorageError> {
self.set_output_to_unmined_and_invalid_batch_mode(vec![hash])
}

pub fn set_output_to_unmined_and_invalid_batch_mode(
&self,
hashes: Vec<FixedHash>,
) -> Result<(), OutputManagerStorageError> {
pub fn set_outputs_to_unmined_and_invalid(&self, hashes: Vec<FixedHash>) -> Result<(), OutputManagerStorageError> {
let db = self.db.clone();
db.set_output_to_unmined_and_invalid_batch_mode(hashes)?;
db.set_outputs_to_unmined_and_invalid(hashes)?;
Ok(())
}

Expand All @@ -426,53 +402,24 @@ where T: OutputManagerBackend + 'static
Ok(())
}

pub fn update_last_validation_timestamp(&self, hash: HashOutput) -> Result<(), OutputManagerStorageError> {
self.update_last_validation_timestamp_batch_mode(vec![hash])
}

pub fn update_last_validation_timestamp_batch_mode(
&self,
hashes: Vec<FixedHash>,
) -> Result<(), OutputManagerStorageError> {
pub fn update_last_validation_timestamps(&self, hashes: Vec<FixedHash>) -> Result<(), OutputManagerStorageError> {
let db = self.db.clone();
db.update_last_validation_timestamp_batch_mode(hashes)?;
db.update_last_validation_timestamps(hashes)?;
Ok(())
}

pub fn mark_output_as_spent(
&self,
hash: HashOutput,
deleted_height: u64,
deleted_in_block: HashOutput,
confirmed: bool,
) -> Result<(), OutputManagerStorageError> {
self.mark_output_as_spent_batch_mode(vec![SpentOutputInfoForBatch {
hash,
confirmed,
mark_deleted_at_height: deleted_height,
mark_deleted_in_block: deleted_in_block,
}])
}

pub fn mark_output_as_spent_batch_mode(
pub fn mark_outputs_as_spent(
&self,
updates: Vec<SpentOutputInfoForBatch>,
) -> Result<(), OutputManagerStorageError> {
let db = self.db.clone();
db.mark_output_as_spent_batch_mode(updates)?;
db.mark_outputs_as_spent(updates)?;
Ok(())
}

pub fn mark_output_as_unspent(&self, hash: HashOutput, confirmed: bool) -> Result<(), OutputManagerStorageError> {
self.mark_output_as_unspent_batch_mode(vec![(hash, confirmed)])
}

pub fn mark_output_as_unspent_batch_mode(
&self,
hashes: Vec<(FixedHash, bool)>,
) -> Result<(), OutputManagerStorageError> {
pub fn mark_outputs_as_unspent(&self, hashes: Vec<(FixedHash, bool)>) -> Result<(), OutputManagerStorageError> {
let db = self.db.clone();
db.mark_output_as_unspent_batch_mode(hashes)?;
db.mark_outputs_as_unspent(hashes)?;
Ok(())
}

Expand Down
Loading

0 comments on commit 7290c3c

Please sign in to comment.