Skip to content

Commit

Permalink
Add new PendingTx variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jun 27, 2023
1 parent 22809db commit 15abbcc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
6 changes: 1 addition & 5 deletions contracts/provider/external-staking/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,7 @@ fn staking() {
#[track_caller]
fn get_last_external_staking_pending_tx_id(contract: &ExternalStakingContractProxy) -> Option<u64> {
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]
Expand Down
6 changes: 1 addition & 5 deletions contracts/provider/vault/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,7 @@ fn stake_local() {
#[track_caller]
fn get_last_pending_tx_id(vault: &VaultContractProxy) -> Option<u64> {
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]
Expand Down
62 changes: 24 additions & 38 deletions packages/sync/src/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 15abbcc

Please sign in to comment.