From 5714eaac0732d7311a91462192a1f5db1292b873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Mon, 4 Mar 2024 14:56:54 +0100 Subject: [PATCH] Replace `PublicKey` and `Signature` with plain `Vec`. --- kairos-server/src/lib.rs | 3 --- kairos-server/src/routes/deposit.rs | 6 +++--- kairos-server/src/routes/transfer.rs | 8 ++++---- kairos-server/src/routes/withdraw.rs | 8 ++++---- kairos-server/src/state.rs | 7 ++----- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/kairos-server/src/lib.rs b/kairos-server/src/lib.rs index 7efc0001..b9555f22 100644 --- a/kairos-server/src/lib.rs +++ b/kairos-server/src/lib.rs @@ -9,9 +9,6 @@ use state::LockedBatchState; pub use errors::AppErr; -type PublicKey = String; -type Signature = String; - pub fn app_router(state: LockedBatchState) -> Router { Router::new() .typed_post(routes::deposit_handler) diff --git a/kairos-server/src/routes/deposit.rs b/kairos-server/src/routes/deposit.rs index f40cecd8..58ab3fd0 100644 --- a/kairos-server/src/routes/deposit.rs +++ b/kairos-server/src/routes/deposit.rs @@ -6,7 +6,7 @@ use axum_extra::routing::TypedPath; use serde::{Deserialize, Serialize}; use tracing::*; -use crate::{state::LockedBatchState, AppErr, PublicKey}; +use crate::{state::LockedBatchState, AppErr}; #[derive(TypedPath, Debug, Clone, Copy)] #[typed_path("/api/v1/deposit")] @@ -14,7 +14,7 @@ pub struct DepositPath; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Deposit { - pub public_key: PublicKey, + pub public_key: Vec, pub amount: u64, } @@ -42,7 +42,7 @@ pub async fn deposit_handler( *balance = updated_balance; tracing::info!( - "Updated account public_key={} balance={}", + "Updated account public_key={:?} balance={}", public_key, updated_balance ); diff --git a/kairos-server/src/routes/transfer.rs b/kairos-server/src/routes/transfer.rs index 3c2ba15c..e9d9b65c 100644 --- a/kairos-server/src/routes/transfer.rs +++ b/kairos-server/src/routes/transfer.rs @@ -4,7 +4,7 @@ use axum_extra::routing::TypedPath; use serde::{Deserialize, Serialize}; use tracing::instrument; -use crate::{state::LockedBatchState, AppErr, PublicKey, Signature}; +use crate::{state::LockedBatchState, AppErr}; #[derive(TypedPath)] #[typed_path("/api/v1/transfer")] @@ -12,9 +12,9 @@ pub struct TransferPath; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Transfer { - pub from: PublicKey, - pub signature: Signature, - pub to: PublicKey, + pub from: Vec, + pub signature: Vec, + pub to: Vec, pub amount: u64, } diff --git a/kairos-server/src/routes/withdraw.rs b/kairos-server/src/routes/withdraw.rs index 2fdf0968..ed76328d 100644 --- a/kairos-server/src/routes/withdraw.rs +++ b/kairos-server/src/routes/withdraw.rs @@ -4,7 +4,7 @@ use axum_extra::routing::TypedPath; use serde::{Deserialize, Serialize}; use tracing::*; -use crate::{state::LockedBatchState, AppErr, PublicKey}; +use crate::{state::LockedBatchState, AppErr}; #[derive(Debug, TypedPath)] #[typed_path("/api/v1/withdraw")] @@ -12,8 +12,8 @@ pub struct WithdrawPath; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Withdrawal { - pub public_key: PublicKey, - pub signature: String, + pub public_key: Vec, + pub signature: Vec, pub amount: u64, } @@ -63,7 +63,7 @@ pub async fn withdraw_handler( } tracing::info!( - "Updated account public_key={} balance={}", + "Updated account public_key={:?} balance={}", withdrawal.public_key, updated_balance ); diff --git a/kairos-server/src/state.rs b/kairos-server/src/state.rs index 12563194..c830e0c8 100644 --- a/kairos-server/src/state.rs +++ b/kairos-server/src/state.rs @@ -5,16 +5,13 @@ use std::{ use tokio::sync::RwLock; -use crate::{ - routes::{deposit::Deposit, transfer::Transfer, withdraw::Withdrawal}, - PublicKey, -}; +use crate::routes::{deposit::Deposit, transfer::Transfer, withdraw::Withdrawal}; pub type LockedBatchState = Arc>; #[derive(Debug)] pub struct BatchState { - pub balances: HashMap, + pub balances: HashMap, u64>, pub batch_epoch: u64, /// The set of transfers that will be batched in the next epoch. pub batched_transfers: HashSet,