diff --git a/primitives/src/spender.rs b/primitives/src/spender.rs index 474b50837..165e05a21 100644 --- a/primitives/src/spender.rs +++ b/primitives/src/spender.rs @@ -1,17 +1,11 @@ use crate::{Address, Channel, Deposit, UnifiedNum}; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] -#[serde(rename_all = "camelCase")] -pub struct SpenderLeaf { - pub total_spent: UnifiedNum, - // merkle_proof: [u8; 32], // TODO -} - #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[serde(rename_all = "camelCase")] pub struct Spender { pub total_deposited: UnifiedNum, - pub spender_leaf: Option, + pub total_spent: Option, } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/sentry/src/routes/channel.rs b/sentry/src/routes/channel.rs index 05a958463..c00f7cf24 100644 --- a/sentry/src/routes/channel.rs +++ b/sentry/src/routes/channel.rs @@ -16,7 +16,7 @@ use primitives::{ channel_list::ChannelListQuery, AccountingResponse, AllSpendersQuery, AllSpendersResponse, LastApproved, LastApprovedQuery, LastApprovedResponse, SpenderResponse, SuccessResponse, }, - spender::{Spendable, Spender, SpenderLeaf}, + spender::{Spendable, Spender}, validator::{MessageTypes, NewState}, Address, Channel, Deposit, UnifiedNum, }; @@ -190,7 +190,7 @@ fn spender_response_without_leaf( let res = SpenderResponse { spender: Spender { total_deposited, - spender_leaf: None, + total_spent: None, }, }; Ok(success_response(serde_json::to_string(&res)?)) @@ -240,18 +240,17 @@ pub async fn get_spender_limits( None => return spender_response_without_leaf(latest_spendable.deposit.total), }; - let total_spent = new_state.balances.spenders.get(&spender); - - let spender_leaf = total_spent.map(|total_spent| SpenderLeaf { - total_spent: *total_spent, - //merkle_proof: [u8; 32], // TODO - }); + let total_spent = new_state + .balances + .spenders + .get(&spender) + .map(|spent| spent.to_owned()); // returned output let res = SpenderResponse { spender: Spender { total_deposited: latest_spendable.deposit.total, - spender_leaf, + total_spent, }, }; Ok(success_response(serde_json::to_string(&res)?)) @@ -284,23 +283,20 @@ pub async fn get_all_spender_limits( // Using for loop to avoid async closures for spendable in all_spendables { let spender = spendable.spender; - let spender_leaf = match new_state { + let total_spent = match new_state { Some(ref new_state) => new_state.balances.spenders.get(&spender).map(|balance| { - SpenderLeaf { - total_spent: spendable - .deposit - .total - .checked_sub(balance) - .unwrap_or_default(), - // merkle_proof: [u8; 32], // TODO - } + spendable + .deposit + .total + .checked_sub(balance) + .unwrap_or_default() }), None => None, }; let spender_info = Spender { total_deposited: spendable.deposit.total, - spender_leaf, + total_spent, }; all_spender_limits.insert(spender, spender_info); diff --git a/test_harness/src/lib.rs b/test_harness/src/lib.rs index 3b339650f..599cc6f41 100644 --- a/test_harness/src/lib.rs +++ b/test_harness/src/lib.rs @@ -606,7 +606,7 @@ mod tests { Spender { // Expected: 30 TOKENs total_deposited: UnifiedNum::from(3_000_000_000), - spender_leaf: None, + total_spent: None, }, )] .into_iter() diff --git a/validator_worker/src/sentry_interface.rs b/validator_worker/src/sentry_interface.rs index 3ec364ab9..4337c3a6c 100644 --- a/validator_worker/src/sentry_interface.rs +++ b/validator_worker/src/sentry_interface.rs @@ -501,7 +501,7 @@ mod test { let server = MockServer::start().await; let test_spender = Spender { total_deposited: UnifiedNum::from(100_000_000), - spender_leaf: None, + total_spent: None, }; let mut all_spenders = HashMap::new(); all_spenders.insert(ADDRESSES["user"], test_spender.clone());