Cesar Rodas 10 月之前
父節點
當前提交
4d07facc5d
共有 4 個文件被更改,包括 21 次插入15 次删除
  1. 1 1
      utxo/src/storage/cursor.rs
  2. 11 7
      utxo/src/storage/mod.rs
  3. 4 6
      utxo/src/storage/sqlite/batch.rs
  4. 5 1
      utxo/src/storage/sqlite/mod.rs

+ 1 - 1
utxo/src/storage/cursor.rs

@@ -87,7 +87,7 @@ impl Cursor {
         if !self.filter.tags.is_empty() {
             let mut found = false;
             for tag in revision.tags.iter() {
-                if self.filter.tags.binary_search(&tag).is_ok() {
+                if self.filter.tags.binary_search(tag).is_ok() {
                     found = true;
                     break;
                 }

+ 11 - 7
utxo/src/storage/mod.rs

@@ -42,6 +42,7 @@ pub fn from_bytes<T>(val: &[u8]) -> Result<T, Error>
 where
     T: serde::de::DeserializeOwned + borsh::BorshDeserialize,
 {
+    #[allow(clippy::useless_asref)]
     borsh::BorshDeserialize::deserialize(&mut val.as_ref())
         .map_err(|e| Error::Encoding(e.to_string()))
 }
@@ -275,16 +276,19 @@ pub trait Storage {
     ) -> Result<Vec<PaymentFrom>, Error> {
         let mut payments = self.get_negative_unspent_payments(account, asset).await?;
         let target_amount = target_amount
-            + payments
-                .iter()
-                .map(|payment| payment.amount.cents())
-                .sum::<AmountCents>()
-                .abs();
+            .checked_add(
+                payments
+                    .iter()
+                    .map(|payment| payment.amount.cents())
+                    .sum::<AmountCents>()
+                    .checked_abs()
+                    .ok_or(Error::Overflow)?,
+            )
+            .ok_or(Error::Overflow)?;
 
         payments.extend(
             self.get_positive_unspent_payments(account, asset, target_amount)
-                .await?
-                .into_iter(),
+                .await?,
         );
         Ok(payments)
     }

+ 4 - 6
utxo/src/storage/sqlite/batch.rs

@@ -294,11 +294,9 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
         .bind(revision_id.to_string())
         .bind(to_bytes(revision)?)
         .bind(revision.transaction_id().to_string())
-        .bind(if let Some(prev_id) = revision.previous_revision_id() {
-            Some(prev_id.to_string())
-        } else {
-            None
-        })
+        .bind(
+            revision.previous_revision_id().map(|prev_rev| prev_rev.to_string())
+        )
         .bind(revision.status.to_string())
         .execute(&mut *self.inner)
         .await
@@ -325,7 +323,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
                 "#)
                 .bind(transaction_id.to_string())
                 .bind(tag.as_str())
-                .bind(base_tx.created_at.timestamp() as i64)
+                .bind(base_tx.created_at.timestamp())
                 .execute(&mut *self.inner)
                 .await
                 .map_err(|e| Error::Storage(e.to_string()))?;

+ 5 - 1
utxo/src/storage/sqlite/mod.rs

@@ -243,7 +243,11 @@ where
         })
         .collect::<Result<Vec<_>, Error>>()?;
 
-    cursor.filter.skip += results.len();
+    cursor.filter.skip = cursor
+        .filter
+        .skip
+        .checked_add(results.len())
+        .ok_or(Error::Overflow)?;
 
     Ok(results)
 }