瀏覽代碼

Minor change

Cesar Rodas 1 年之前
父節點
當前提交
663c04171b

+ 3 - 3
src/main.rs

@@ -4,7 +4,7 @@ use actix_web::{
 };
 use serde::{Deserialize, Serialize};
 use serde_json::json;
-use verax::{AccountId, AnyAmount, AnyId, Asset, Status, TransactionId, Type};
+use verax::{AccountId, AnyAmount, AnyId, Asset, RevisionId, Status, Type};
 
 #[derive(Deserialize)]
 pub struct Movement {
@@ -56,7 +56,7 @@ pub struct UpdateTransaction {
 impl UpdateTransaction {
     pub async fn to_ledger_transaction(
         self,
-        id: &TransactionId,
+        id: &RevisionId,
         ledger: &Ledger,
     ) -> Result<verax::Transaction, verax::Error> {
         ledger
@@ -183,7 +183,7 @@ async fn create_transaction(
 
 #[post("/{id}")]
 async fn update_status(
-    info: web::Path<TransactionId>,
+    info: web::Path<RevisionId>,
     item: web::Json<UpdateTransaction>,
     ledger: web::Data<Ledger>,
 ) -> impl Responder {

+ 2 - 2
utxo/docs/65cdd331-aa64-48bf-9224-0e1e13c68e41.md

@@ -10,10 +10,10 @@ Each `payment` is a data structure with this information
 
 ```
 struct Payment {
-    created_by_transaction: TransactionId,
+    created_by_transaction: RevisionId,
     amount: Amount,
     destination: Address,
-    spend_by: Option<TransactionId>
+    spend_by: Option<RevisionId>
 }
 ```
 

+ 3 - 3
utxo/src/id/mod.rs

@@ -61,15 +61,15 @@ impl<'de, const MAX_LENGTH: usize> de::Deserialize<'de> for MaxLengthString<MAX_
 
 /// The AccountId data type
 pub type AccountId = MaxLengthString<64>;
-crate::BinaryId!(TransactionId, "tx");
+crate::BinaryId!(RevisionId, "tx");
 
 /// A generic ID wrapper
 ///
 /// This enum can be used whenever a human ID is passed and needs to be parsed and validated.
 #[derive(Debug)]
 pub enum AnyId {
-    /// TransactionId
-    Transaction(TransactionId),
+    /// RevisionId
+    Transaction(RevisionId),
     /// Payment
     Payment(PaymentId),
     /// Account ID

+ 2 - 2
utxo/src/id/payment.rs

@@ -1,4 +1,4 @@
-use crate::{id::Error, TransactionId};
+use crate::{id::Error, RevisionId};
 use serde::{de, Serialize, Serializer};
 use std::{fmt, ops::Deref, str::FromStr};
 
@@ -10,7 +10,7 @@ use std::{fmt, ops::Deref, str::FromStr};
 /// transaction.
 pub struct PaymentId {
     /// Transaction which created this payment
-    pub transaction: TransactionId,
+    pub transaction: RevisionId,
     /// This payment position inside the transaction
     pub position: u16,
 }

+ 3 - 6
utxo/src/ledger.rs

@@ -1,6 +1,6 @@
 use crate::{
     amount::AmountCents, config::Config, storage::Storage, transaction::Type, AccountId, Amount,
-    Error, PaymentFrom, PaymentId, Status, Transaction, TransactionId,
+    Error, PaymentFrom, PaymentId, RevisionId, Status, Transaction,
 };
 use std::{cmp::Ordering, collections::HashMap, sync::Arc};
 
@@ -256,10 +256,7 @@ where
     }
 
     /// Returns the transaction object by a given transaction id
-    pub async fn get_transaction(
-        &self,
-        transaction_id: &TransactionId,
-    ) -> Result<Transaction, Error> {
+    pub async fn get_transaction(&self, transaction_id: &RevisionId) -> Result<Transaction, Error> {
         Ok(self.config.storage.get_transaction(transaction_id).await?)
     }
 
@@ -287,7 +284,7 @@ where
     /// new transaction object is returned, otherwise an error is returned.
     pub async fn change_status(
         &self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         new_status: Status,
         reason: String,
     ) -> Result<Transaction, Error> {

+ 11 - 11
utxo/src/storage/cache/batch.rs

@@ -2,13 +2,13 @@ use super::CacheStorage;
 use crate::{
     payment::PaymentTo,
     storage::{Batch, Error, Status},
-    AccountId, Amount, PaymentFrom, PaymentId, Transaction, TransactionId,
+    AccountId, Amount, PaymentFrom, PaymentId, RevisionId, Transaction,
 };
 use std::{collections::HashMap, marker::PhantomData};
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub enum Ids {
-    Transaction(TransactionId),
+    Transaction(RevisionId),
     Payment(PaymentId),
     Account(AccountId),
 }
@@ -20,7 +20,7 @@ where
     inner: B,
     payments: CacheStorage<PaymentId, PaymentFrom>,
     balances: CacheStorage<AccountId, Vec<Amount>>,
-    transactions: CacheStorage<TransactionId, Transaction>,
+    transactions: CacheStorage<RevisionId, Transaction>,
     to_invalidate: HashMap<Ids, ()>,
     _phantom: PhantomData<&'a ()>,
 }
@@ -33,7 +33,7 @@ where
         batch: B,
         payments: CacheStorage<PaymentId, PaymentFrom>,
         balances: CacheStorage<AccountId, Vec<Amount>>,
-        transactions: CacheStorage<TransactionId, Transaction>,
+        transactions: CacheStorage<RevisionId, Transaction>,
     ) -> Self {
         Self {
             inner: batch,
@@ -77,8 +77,8 @@ where
 
     async fn get_transaction_with_revision(
         &mut self,
-        transaction_id: &TransactionId,
-        revision_id: &TransactionId,
+        transaction_id: &RevisionId,
+        revision_id: &RevisionId,
     ) -> Result<Transaction, Error> {
         self.inner
             .get_transaction_with_revision(transaction_id, revision_id)
@@ -87,7 +87,7 @@ where
 
     async fn relate_account_to_transaction(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         account: &AccountId,
         typ: crate::Type,
     ) -> Result<(), Error> {
@@ -105,7 +105,7 @@ where
 
     async fn update_transaction_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         create_status: Status,
         spend_status: Status,
     ) -> Result<(usize, usize), Error> {
@@ -118,7 +118,7 @@ where
 
     async fn get_payment_status(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
     ) -> Result<Option<Status>, Error> {
         self.to_invalidate
             .insert(Ids::Transaction(transaction_id.clone()), ());
@@ -127,7 +127,7 @@ where
 
     async fn spend_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         spends: Vec<PaymentId>,
         status: Status,
     ) -> Result<(), Error> {
@@ -141,7 +141,7 @@ where
 
     async fn create_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         recipients: &[PaymentTo],
         status: Status,
     ) -> Result<(), Error> {

+ 3 - 3
utxo/src/storage/cache/mod.rs

@@ -3,7 +3,7 @@ use crate::{
     amount::AmountCents,
     storage::{Error, Storage},
     transaction::Transaction,
-    AccountId, Amount, Asset, PaymentFrom, PaymentId, TransactionId, Type,
+    AccountId, Amount, Asset, PaymentFrom, PaymentId, RevisionId, Type,
 };
 use std::{collections::HashMap, sync::Arc};
 use tokio::sync::RwLock;
@@ -23,7 +23,7 @@ where
 {
     payments: CacheStorage<PaymentId, PaymentFrom>,
     balances: CacheStorage<AccountId, Vec<Amount>>,
-    transactions: CacheStorage<TransactionId, Transaction>,
+    transactions: CacheStorage<RevisionId, Transaction>,
     inner: S,
 }
 
@@ -75,7 +75,7 @@ where
         }
     }
 
-    async fn get_transaction(&self, id: &TransactionId) -> Result<Transaction, Error> {
+    async fn get_transaction(&self, id: &RevisionId) -> Result<Transaction, Error> {
         let transactions = self.transactions.read().await;
         if let Some(transaction) = transactions.get(id).cloned() {
             Ok(transaction)

+ 13 - 14
utxo/src/storage/mod.rs

@@ -1,7 +1,7 @@
 //! Storage layer trait
 use crate::{
     amount::AmountCents, payment::PaymentTo, transaction::Type, AccountId, Amount, Asset,
-    PaymentFrom, PaymentId, Transaction, TransactionId,
+    PaymentFrom, PaymentId, RevisionId, Transaction,
 };
 use serde::Serialize;
 
@@ -108,14 +108,14 @@ pub trait Batch<'a> {
     /// is expected to put some hold on the transaction
     async fn get_transaction_with_revision(
         &mut self,
-        transaction_id: &TransactionId,
-        revision_id: &TransactionId,
+        transaction_id: &RevisionId,
+        revision_id: &RevisionId,
     ) -> Result<Transaction, Error>;
 
     /// Flag the given payments as spent by the given transaction.
     async fn spend_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         spends: Vec<PaymentId>,
         status: Status,
     ) -> Result<(), Error>;
@@ -123,7 +123,7 @@ pub trait Batch<'a> {
     /// Create a new list of payments
     async fn create_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         recipients: &[PaymentTo],
         status: Status,
     ) -> Result<(), Error>;
@@ -137,7 +137,7 @@ pub trait Batch<'a> {
     /// from NotSpentable to Spendable can only be done by the parent transaction, and not other.
     async fn update_transaction_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         create_status: Status,
         spend_status: Status,
     ) -> Result<(usize, usize), Error>;
@@ -145,7 +145,7 @@ pub trait Batch<'a> {
     /// Returns the stats of a payment from the point of view of the on-going transaction
     async fn get_payment_status(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
     ) -> Result<Option<Status>, Error>;
 
     /// Stores a transaction
@@ -167,7 +167,7 @@ pub trait Batch<'a> {
     /// layer.
     async fn relate_account_to_transaction(
         &mut self,
-        transaction: &TransactionId,
+        transaction: &RevisionId,
         account: &AccountId,
         typ: Type,
     ) -> Result<(), Error>;
@@ -213,7 +213,7 @@ pub trait Storage {
     ) -> Result<Vec<PaymentFrom>, Error>;
 
     /// Returns a transaction object by id
-    async fn get_transaction(&self, transaction_id: &TransactionId) -> Result<Transaction, Error>;
+    async fn get_transaction(&self, transaction_id: &RevisionId) -> Result<Transaction, Error>;
 
     /// Returns a list of a transactions for a given account (and optionally
     /// filter by types). The list of transactions is expected to be sorted by
@@ -377,7 +377,7 @@ pub mod test {
             .expect("valid amount");
 
         for (i, status) in [Status::Locked, Status::Spendable].into_iter().enumerate() {
-            let transaction_id: TransactionId = vec![i as u8; 32].try_into().expect("valid tx id");
+            let transaction_id: RevisionId = vec![i as u8; 32].try_into().expect("valid tx id");
 
             writer
                 .create_payments(
@@ -420,7 +420,7 @@ pub mod test {
             .expect("valid amount");
 
         for (i, status) in [Status::Failed, Status::Spent].into_iter().enumerate() {
-            let transaction_id: TransactionId = vec![i as u8; 32].try_into().expect("valid tx id");
+            let transaction_id: RevisionId = vec![i as u8; 32].try_into().expect("valid tx id");
 
             writer
                 .create_payments(
@@ -467,8 +467,7 @@ pub mod test {
         let usd: Asset = "USD/2".parse().expect("valid asset");
 
         for (index, account) in accounts.iter().enumerate() {
-            let transaction_id: TransactionId =
-                vec![index as u8; 32].try_into().expect("valid tx id");
+            let transaction_id: RevisionId = vec![index as u8; 32].try_into().expect("valid tx id");
             let recipients = (0..target_inputs_per_account)
                 .map(|_| {
                     let amount = usd
@@ -593,7 +592,7 @@ pub mod test {
             .from_human(&format!("{}", rng.gen_range(10.0..10000.0)))
             .expect("valid amount");
 
-        let transaction: TransactionId = vec![0u8; 32].try_into().expect("valid tx id");
+        let transaction: RevisionId = vec![0u8; 32].try_into().expect("valid tx id");
 
         writer
             .create_payments(

+ 8 - 8
utxo/src/storage/sqlite/batch.rs

@@ -2,7 +2,7 @@ use crate::{
     payment::PaymentTo,
     storage::{self, Error, Status},
     transaction::inner::Revision,
-    AccountId, PaymentId, Transaction, TransactionId, Type,
+    AccountId, PaymentId, RevisionId, Transaction, Type,
 };
 use sqlx::{Row, Sqlite, Transaction as SqlxTransaction};
 use std::{marker::PhantomData, num::TryFromIntError};
@@ -37,7 +37,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
 
     async fn relate_account_to_transaction(
         &mut self,
-        transaction: &TransactionId,
+        transaction: &RevisionId,
         account: &AccountId,
         typ: Type,
     ) -> Result<(), Error> {
@@ -58,8 +58,8 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
 
     async fn get_transaction_with_revision(
         &mut self,
-        transaction_id: &TransactionId,
-        revision_id: &TransactionId,
+        transaction_id: &RevisionId,
+        revision_id: &RevisionId,
     ) -> Result<Transaction, Error> {
         let row = sqlx::query(
             r#"
@@ -98,7 +98,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
 
     async fn spend_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         spends: Vec<PaymentId>,
         status: Status,
     ) -> Result<(), Error> {
@@ -140,7 +140,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
 
     async fn create_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         recipients: &[PaymentTo],
         status: Status,
     ) -> Result<(), Error> {
@@ -174,7 +174,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
 
     async fn update_transaction_payments(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
         create_status: Status,
         spend_status: Status,
     ) -> Result<(usize, usize), Error> {
@@ -221,7 +221,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
 
     async fn get_payment_status(
         &mut self,
-        transaction_id: &TransactionId,
+        transaction_id: &RevisionId,
     ) -> Result<Option<Status>, Error> {
         let row = sqlx::query(
             r#"

+ 3 - 3
utxo/src/storage/sqlite/mod.rs

@@ -3,7 +3,7 @@ use crate::{
     amount::AmountCents,
     storage::{Error, Storage},
     transaction::{inner::Revision, Type},
-    AccountId, Amount, Asset, PaymentFrom, PaymentId, Transaction, TransactionId,
+    AccountId, Amount, Asset, PaymentFrom, PaymentId, RevisionId, Transaction,
 };
 use futures::TryStreamExt;
 use sqlx::{sqlite::SqliteRow, Executor, Row};
@@ -230,7 +230,7 @@ impl Storage for SQLite {
         }
     }
 
-    async fn get_transaction(&self, transaction_id: &TransactionId) -> Result<Transaction, Error> {
+    async fn get_transaction(&self, transaction_id: &RevisionId) -> Result<Transaction, Error> {
         let mut conn = self
             .db
             .acquire()
@@ -305,7 +305,7 @@ impl Storage for SQLite {
         .map_err(|e| Error::Storage(e.to_string()))?
         .into_iter()
         .map(|row| {
-            let id: Result<TransactionId, _> = row
+            let id: Result<RevisionId, _> = row
                 .try_get::<String, usize>(0)
                 .map_err(|_| Error::Storage("Invalid transaction_id".to_string()))?
                 .as_str()

+ 3 - 4
utxo/src/tests/mod.rs

@@ -1,6 +1,5 @@
 use crate::{
-    storage::sqlite::SQLite, storage::Storage, AccountId, Amount, Error, Ledger, Status,
-    TransactionId,
+    storage::sqlite::SQLite, storage::Storage, AccountId, Amount, Error, Ledger, RevisionId, Status,
 };
 use sqlx::sqlite::SqlitePoolOptions;
 
@@ -38,7 +37,7 @@ pub async fn withdrawal(
     account_id: &AccountId,
     status: Status,
     amount: Amount,
-) -> Result<TransactionId, Error> {
+) -> Result<RevisionId, Error> {
     Ok(ledger
         .withdrawal(account_id, amount, status, "Test".to_owned())
         .await?
@@ -46,7 +45,7 @@ pub async fn withdrawal(
         .clone())
 }
 
-pub async fn deposit<S>(ledger: &Ledger<S>, account_id: &AccountId, amount: Amount) -> TransactionId
+pub async fn deposit<S>(ledger: &Ledger<S>, account_id: &AccountId, amount: Amount) -> RevisionId
 where
     S: Storage + Send + Sync,
 {

+ 2 - 2
utxo/src/transaction/error.rs

@@ -1,4 +1,4 @@
-use crate::{status, storage, Amount, Asset, Status, TransactionId};
+use crate::{status, storage, Amount, Asset, RevisionId, Status};
 use serde::Serialize;
 
 #[derive(thiserror::Error, Debug, Serialize)]
@@ -42,7 +42,7 @@ pub enum Error {
     NoUpdate,
 
     #[error("Invalid calculated id {0} (expected {1})")]
-    InvalidTransactionId(TransactionId, TransactionId),
+    InvalidRevisionId(RevisionId, RevisionId),
 
     #[error("Overflow")]
     Overflow,

+ 12 - 12
utxo/src/transaction/inner.rs

@@ -4,7 +4,7 @@ use crate::{
     payment::PaymentTo,
     storage::{self, Batch, Storage},
     transaction::*,
-    AccountId, Amount, Asset, PaymentFrom, Status, TransactionId,
+    AccountId, Amount, Asset, PaymentFrom, RevisionId, Status,
 };
 use chrono::{serde::ts_milliseconds, DateTime, Utc};
 use serde::{Deserialize, Serialize};
@@ -24,9 +24,9 @@ use std::collections::HashMap;
 #[derive(Debug, Clone, Deserialize, Serialize)]
 pub struct Revision {
     /// A pointer to the first revision of the transaction.
-    first: Option<TransactionId>,
+    first: Option<RevisionId>,
     /// Any previous transaction that this transaction is replacing.
-    previous: Option<TransactionId>,
+    previous: Option<RevisionId>,
     /// A human-readable description of the transaction changes.
     changelog: String,
     spends: Vec<PaymentFrom>,
@@ -44,23 +44,23 @@ pub struct Revision {
 }
 
 impl Revision {
-    pub fn calculate_id(&self) -> Result<TransactionId, Error> {
+    pub fn calculate_id(&self) -> Result<RevisionId, Error> {
         let mut hasher = Sha256::new();
         let bytes = bincode::serialize(self)?;
         hasher.update(bytes);
-        Ok(TransactionId::new(hasher.finalize().into()))
+        Ok(RevisionId::new(hasher.finalize().into()))
     }
 
     /// The transaction fingerprint is a hash of the properties that are not allowed to be updated
     /// in a transaction.
-    pub fn transaction_fingerprint(&self) -> Result<TransactionId, Error> {
+    pub fn transaction_fingerprint(&self) -> Result<RevisionId, Error> {
         let mut hasher = Sha256::new();
         hasher.update(&bincode::serialize(&self.spends)?);
         hasher.update(&bincode::serialize(&self.creates)?);
         hasher.update(&self.typ.to_string());
         hasher.update(&self.reference);
         hasher.update(&self.created_at.timestamp_millis().to_string());
-        Ok(TransactionId::new(hasher.finalize().into()))
+        Ok(RevisionId::new(hasher.finalize().into()))
     }
 
     /// Validates the transaction input and output (debit and credit)
@@ -159,10 +159,10 @@ impl Revision {
 /// The transaction ID, and the revision ID, are the cryptographic hash of the transactions
 #[derive(Debug, Clone, Serialize)]
 pub struct Transaction {
-    /// The TransactionID is the RevisionID of the first revision of the transaction.
-    pub id: TransactionId,
+    /// The RevisionId is the RevisionID of the first revision of the transaction.
+    pub id: RevisionId,
     /// Current Revision ID.
-    pub current: TransactionId,
+    pub current: RevisionId,
     /// The transaction inner details
     #[serde(flatten)]
     inner: Revision,
@@ -337,7 +337,7 @@ impl Transaction {
         if self.current != calculated_revision_id
             || (self.inner.previous.is_none() && self.id != calculated_revision_id)
         {
-            return Err(Error::InvalidTransactionId(
+            return Err(Error::InvalidRevisionId(
                 self.id.clone(),
                 calculated_revision_id,
             ));
@@ -357,7 +357,7 @@ impl Transaction {
     }
 
     /// Returns the transaction ID
-    pub fn id(&self) -> &TransactionId {
+    pub fn id(&self) -> &RevisionId {
         &self.id
     }