From 15abbcc8de381738d6ba3923dcb8857e4e4f60a3 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 27 Jun 2023 16:27:34 +0200 Subject: [PATCH] Add new PendingTx variant --- .../external-staking/src/multitest.rs | 6 +- contracts/provider/vault/src/multitest.rs | 6 +- packages/sync/src/txs.rs | 62 +++++++------------ 3 files changed, 26 insertions(+), 48 deletions(-) diff --git a/contracts/provider/external-staking/src/multitest.rs b/contracts/provider/external-staking/src/multitest.rs index 2442f1f2..87c43f77 100644 --- a/contracts/provider/external-staking/src/multitest.rs +++ b/contracts/provider/external-staking/src/multitest.rs @@ -309,11 +309,7 @@ fn staking() { #[track_caller] fn get_last_external_staking_pending_tx_id(contract: &ExternalStakingContractProxy) -> Option { let txs = contract.all_pending_txs_desc(None, None).unwrap().txs; - txs.first().map(|tx| match tx { - Tx::InFlightStaking { id, .. } => *id, - Tx::InFlightRemoteStaking { id, .. } => *id, - Tx::InFlightRemoteUnstaking { id, .. } => *id, - }) + txs.first().map(Tx::id) } #[test] diff --git a/contracts/provider/vault/src/multitest.rs b/contracts/provider/vault/src/multitest.rs index a27f590c..858d45d4 100644 --- a/contracts/provider/vault/src/multitest.rs +++ b/contracts/provider/vault/src/multitest.rs @@ -451,11 +451,7 @@ fn stake_local() { #[track_caller] fn get_last_pending_tx_id(vault: &VaultContractProxy) -> Option { let txs = vault.all_pending_txs_desc(None, None).unwrap().txs; - txs.first().map(|tx| match tx { - Tx::InFlightStaking { id, .. } => *id, - Tx::InFlightRemoteStaking { id, .. } => *id, - Tx::InFlightRemoteUnstaking { id, .. } => *id, - }) + txs.first().map(Tx::id) } #[test] diff --git a/packages/sync/src/txs.rs b/packages/sync/src/txs.rs index de9df59d..ca3410ee 100644 --- a/packages/sync/src/txs.rs +++ b/packages/sync/src/txs.rs @@ -37,47 +37,33 @@ pub enum Tx { user: Addr, /// Remote validator validator: String, - }, // TODO - // InFlightSlashing + }, + /// This is stored on the provider side when releasing funds + InFlightTransferFunds { + id: u64, + /// Amount of rewards being withdrawn + amount: Uint128, + /// The staker sending the funds + staker: Addr, + /// The validator whose rewards they come from (to revert) + validator: String, + }, // InFlightSlashing } -// Implement display for Tx -impl std::fmt::Display for Tx { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { +impl Tx { + pub fn id(&self) -> u64 { match self { - Tx::InFlightStaking { - id, - amount, - slashable, - user, - lienholder, - } => { - write!(f, "InFlightStaking {{ id: {}, amount: {}, slashable: {}, user: {}, lienholder: {} }}", id, amount, slashable, user, lienholder) - } - Tx::InFlightRemoteStaking { - id, - amount, - user, - validator, - } => { - write!( - f, - "InFlightRemoteStaking {{ id: {}, amount: {}, user: {}, validator: {} }}", - id, amount, user, validator - ) - } - Tx::InFlightRemoteUnstaking { - id, - amount, - user, - validator, - } => { - write!( - f, - "InFlightRemoteUnstaking {{ id: {}, amount: {}, user: {}, validator: {} }}", - id, amount, user, validator - ) - } + Tx::InFlightStaking { id, .. } => *id, + Tx::InFlightRemoteStaking { id, .. } => *id, + Tx::InFlightRemoteUnstaking { id, .. } => *id, + Tx::InFlightTransferFunds { id, .. } => *id, } } } + +// Use Debug output for display as well (simplify the previous hand-coding of that) +impl std::fmt::Display for Tx { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +}