Skip to content

Commit

Permalink
Replace PublicKey and Signature with plain Vec<u8>.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Mar 4, 2024
1 parent 2ef83df commit 5714eaa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
3 changes: 0 additions & 3 deletions kairos-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions kairos-server/src/routes/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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")]
pub struct DepositPath;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Deposit {
pub public_key: PublicKey,
pub public_key: Vec<u8>,
pub amount: u64,
}

Expand Down Expand Up @@ -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
);
Expand Down
8 changes: 4 additions & 4 deletions kairos-server/src/routes/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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")]
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<u8>,
pub signature: Vec<u8>,
pub to: Vec<u8>,
pub amount: u64,
}

Expand Down
8 changes: 4 additions & 4 deletions kairos-server/src/routes/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ 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")]
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<u8>,
pub signature: Vec<u8>,
pub amount: u64,
}

Expand Down Expand Up @@ -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
);
Expand Down
7 changes: 2 additions & 5 deletions kairos-server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<BatchState>>;

#[derive(Debug)]
pub struct BatchState {
pub balances: HashMap<PublicKey, u64>,
pub balances: HashMap<Vec<u8>, u64>,
pub batch_epoch: u64,
/// The set of transfers that will be batched in the next epoch.
pub batched_transfers: HashSet<Transfer>,
Expand Down

0 comments on commit 5714eaa

Please sign in to comment.