Przeglądaj źródła

Working on stuff

Cesar Rodas 1 rok temu
rodzic
commit
76230c499e

+ 0 - 2
utxo/src/ledger.rs

@@ -157,9 +157,7 @@ where
         }
 
         let mut transaction = Transaction::new(reference, status, payments, to).await?;
-
         transaction.persist(&self.storage).await?;
-
         Ok(transaction)
     }
 

+ 5 - 5
utxo/src/sqlite/batch.rs

@@ -131,14 +131,14 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
                     DO UPDATE SET "status" = excluded."status", "reference" = excluded."reference"
             "#,
         )
-        .bind(transaction.id.to_string())
-        .bind::<u32>((&transaction.status).into())
-        .bind(transaction.reference.to_string())
+        .bind(transaction.id().to_string())
+        .bind::<u32>(transaction.status().into())
+        .bind(transaction.reference())
         .execute(&mut *self.inner)
         .await
         .map_err(|e| Error::Storage(e.to_string()))?;
 
-        for payment in transaction.spend.iter() {
+        for payment in transaction.spent().iter() {
             sqlx::query(
                 r#"
             INSERT INTO "transaction_payments"("transaction_id", "payment_transaction_id", "payment_position_id")
@@ -147,7 +147,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
                 DO NOTHING
             "#,
             )
-            .bind(transaction.id.to_string())
+            .bind(transaction.id().to_string())
             .bind(payment.id.transaction.to_string())
             .bind(payment.id.position.to_string())
             .execute(&mut *self.inner)

+ 10 - 5
utxo/src/tests/deposit.rs

@@ -13,7 +13,8 @@ pub async fn deposit(
         .deposit(account_id, amount, Status::Settled, "Test".to_owned())
         .await
         .expect("valid tx")
-        .id
+        .id()
+        .clone()
 }
 
 #[tokio::test]
@@ -29,7 +30,8 @@ async fn pending_deposit_and_failure() {
         )
         .await
         .expect("valid tx")
-        .id;
+        .id()
+        .clone();
 
     assert!(ledger
         .get_balance(&source)
@@ -118,7 +120,8 @@ async fn balance_decreases_while_pending_spending_and_confirm() {
         )
         .await
         .expect("valid tx")
-        .id;
+        .id()
+        .clone();
 
     assert_eq!(
         vec![assets.amount(2, 1700).expect("amount")],
@@ -173,7 +176,8 @@ async fn balance_decreases_while_pending_spending_and_cancel() {
         )
         .await
         .expect("valid tx")
-        .id;
+        .id()
+        .clone();
 
     assert_eq!(
         vec![assets.amount(2, 1700).expect("amount")],
@@ -222,7 +226,8 @@ async fn balance_decreases_while_pending_spending_and_failed() {
         )
         .await
         .expect("valid tx")
-        .id;
+        .id()
+        .clone();
 
     assert_eq!(
         vec![assets.amount(2, 1700).expect("amount")],

+ 18 - 6
utxo/src/transaction/mod.rs

@@ -37,13 +37,13 @@ pub use error::Error;
 /// unrelated funds will be held unspentable until the transaction is finalized.
 #[derive(Debug, Clone)]
 pub struct Transaction {
-    pub(crate) id: TransactionId,
-    pub(crate) spend: Vec<Payment>,
+    id: TransactionId,
+    spend: Vec<Payment>,
     #[allow(dead_code)]
-    pub(crate) reference: String,
-    pub(crate) create: Vec<Payment>,
-    pub(crate) status: Status,
-    pub(crate) is_external_deposit: bool,
+    reference: String,
+    create: Vec<Payment>,
+    status: Status,
+    is_external_deposit: bool,
 }
 
 impl Transaction {
@@ -235,6 +235,18 @@ impl Transaction {
         &self.create
     }
 
+    pub fn id(&self) -> &TransactionId {
+        &self.id
+    }
+
+    pub fn status(&self) -> &Status {
+        &self.status
+    }
+
+    pub fn reference(&self) -> &str {
+        &self.reference
+    }
+
     pub async fn persist<'a, B, S>(&mut self, storage: &'a S) -> Result<(), Error>
     where
         B: Batch<'a>,