Browse Source

Merge #468

468: Rename `MustRefund` Cfd state to `PendingRefund` r=klochowicz a=klochowicz

For consistency with PendingClose, PendingCommit, PendingCet - it's analogous to
them, but applies to refund transaction.

Co-authored-by: Mariusz Klochowicz <mariusz@klochowicz.com>
burn-down-handle
bors[bot] 3 years ago
committed by GitHub
parent
commit
11cdc2fc33
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      daemon/src/cfd_actors.rs
  2. 26
      daemon/src/model/cfd.rs
  3. 2
      daemon/src/monitor.rs
  4. 2
      daemon/src/oracle.rs
  5. 10
      daemon/src/to_sse_event.rs
  6. 8
      frontend/src/components/Types.tsx

2
daemon/src/cfd_actors.rs

@ -88,7 +88,7 @@ where
if let CfdState::OpenCommitted { .. } = cfd.state { if let CfdState::OpenCommitted { .. } = cfd.state {
try_cet_publication(&mut cfd, conn, wallet, update_sender).await?; try_cet_publication(&mut cfd, conn, wallet, update_sender).await?;
} else if let CfdState::MustRefund { .. } = cfd.state { } else if let CfdState::PendingRefund { .. } = cfd.state {
let signed_refund_tx = cfd.refund_tx()?; let signed_refund_tx = cfd.refund_tx()?;
let txid = wallet let txid = wallet
.send(wallet::TryBroadcastTransaction { .send(wallet::TryBroadcastTransaction {

26
daemon/src/model/cfd.rs

@ -276,7 +276,7 @@ pub enum CfdState {
// TODO: Can be extended with CetStatus // TODO: Can be extended with CetStatus
/// The CFD contract's refund transaction was published but it not final yet /// The CFD contract's refund transaction was published but it not final yet
MustRefund { common: CfdStateCommon, dlc: Dlc }, PendingRefund { common: CfdStateCommon, dlc: Dlc },
/// The Cfd was refunded and the refund transaction reached finality /// The Cfd was refunded and the refund transaction reached finality
/// ///
@ -328,7 +328,7 @@ impl CfdState {
} }
pub fn must_refund(dlc: Dlc) -> Self { pub fn must_refund(dlc: Dlc) -> Self {
Self::MustRefund { Self::PendingRefund {
common: CfdStateCommon::default(), common: CfdStateCommon::default(),
dlc, dlc,
} }
@ -455,7 +455,7 @@ impl CfdState {
CfdState::PendingOpen { common, .. } => common, CfdState::PendingOpen { common, .. } => common,
CfdState::Open { common, .. } => common, CfdState::Open { common, .. } => common,
CfdState::OpenCommitted { common, .. } => common, CfdState::OpenCommitted { common, .. } => common,
CfdState::MustRefund { common, .. } => common, CfdState::PendingRefund { common, .. } => common,
CfdState::Refunded { common, .. } => common, CfdState::Refunded { common, .. } => common,
CfdState::SetupFailed { common, .. } => common, CfdState::SetupFailed { common, .. } => common,
CfdState::PendingCommit { common, .. } => common, CfdState::PendingCommit { common, .. } => common,
@ -511,7 +511,7 @@ impl fmt::Display for CfdState {
CfdState::OpenCommitted { .. } => { CfdState::OpenCommitted { .. } => {
write!(f, "Open Committed") write!(f, "Open Committed")
} }
CfdState::MustRefund { .. } => { CfdState::PendingRefund { .. } => {
write!(f, "Must Refund") write!(f, "Must Refund")
} }
CfdState::Refunded { .. } => { CfdState::Refunded { .. } => {
@ -835,11 +835,11 @@ impl Cfd {
let dlc = if let OpenCommitted { dlc, .. } = self.state.clone() { let dlc = if let OpenCommitted { dlc, .. } = self.state.clone() {
dlc dlc
} else if let Open { dlc, .. } | PendingOpen { dlc, .. } = self.state.clone() { } else if let Open { dlc, .. } | PendingOpen { dlc, .. } = self.state.clone() {
tracing::debug!(%order_id, "Was in unexpected state {}, jumping ahead to MustRefund", self.state); tracing::debug!(%order_id, "Was in unexpected state {}, jumping ahead to PendingRefund", self.state);
dlc dlc
} else { } else {
bail!( bail!(
"Cannot transition to MustRefund because of unexpected state {}", "Cannot transition to PendingRefund because of unexpected state {}",
self.state self.state
) )
}; };
@ -983,10 +983,10 @@ impl Cfd {
} }
pub fn refund_tx(&self) -> Result<Transaction> { pub fn refund_tx(&self) -> Result<Transaction> {
let dlc = if let CfdState::MustRefund { dlc, .. } = self.state.clone() { let dlc = if let CfdState::PendingRefund { dlc, .. } = self.state.clone() {
dlc dlc
} else { } else {
bail!("Refund transaction can only be constructed when in state MustRefund, but we are currently in {}", self.state.clone()) bail!("Refund transaction can only be constructed when in state PendingRefund, but we are currently in {}", self.state.clone())
}; };
let sig_hash = spending_tx_sighash( let sig_hash = spending_tx_sighash(
@ -1132,7 +1132,7 @@ impl Cfd {
} }
pub fn is_must_refund(&self) -> bool { pub fn is_must_refund(&self) -> bool {
matches!(self.state.clone(), CfdState::MustRefund { .. }) matches!(self.state.clone(), CfdState::PendingRefund { .. })
} }
pub fn is_pending_commit(&self) -> bool { pub fn is_pending_commit(&self) -> bool {
@ -1171,7 +1171,7 @@ impl Cfd {
| CfdState::Rejected { .. } | CfdState::Rejected { .. }
| CfdState::ContractSetup { .. } | CfdState::ContractSetup { .. }
| CfdState::Closed { .. } | CfdState::Closed { .. }
| CfdState::MustRefund { .. } | CfdState::PendingRefund { .. }
| CfdState::Refunded { .. } | CfdState::Refunded { .. }
| CfdState::SetupFailed { .. } => None, | CfdState::SetupFailed { .. } => None,
} }
@ -1211,7 +1211,7 @@ impl Cfd {
| CfdState::PendingCommit { .. } | CfdState::PendingCommit { .. }
| CfdState::Closed { .. } | CfdState::Closed { .. }
| CfdState::OpenCommitted { .. } | CfdState::OpenCommitted { .. }
| CfdState::MustRefund { .. } | CfdState::PendingRefund { .. }
| CfdState::Refunded { .. } | CfdState::Refunded { .. }
| CfdState::SetupFailed { .. } => None, | CfdState::SetupFailed { .. } => None,
} }
@ -1239,7 +1239,7 @@ impl Cfd {
| CfdState::PendingCet { .. } | CfdState::PendingCet { .. }
| CfdState::Closed { .. } | CfdState::Closed { .. }
| CfdState::OpenCommitted { .. } | CfdState::OpenCommitted { .. }
| CfdState::MustRefund { .. } | CfdState::PendingRefund { .. }
| CfdState::Refunded { .. } | CfdState::Refunded { .. }
| CfdState::SetupFailed { .. } => None, | CfdState::SetupFailed { .. } => None,
} }
@ -1252,7 +1252,7 @@ impl Cfd {
/// undecided /// undecided
pub fn payout(&self) -> Option<Amount> { pub fn payout(&self) -> Option<Amount> {
// early exit in case of refund scenario // early exit in case of refund scenario
if let CfdState::MustRefund { dlc, .. } | CfdState::Refunded { dlc, .. } = if let CfdState::PendingRefund { dlc, .. } | CfdState::Refunded { dlc, .. } =
self.state.clone() self.state.clone()
{ {
return Some(dlc.refund_amount(self.role())); return Some(dlc.refund_amount(self.role()));

2
daemon/src/monitor.rs

@ -132,7 +132,7 @@ impl Actor<bdk::electrum_client::Client> {
actor.monitor_commit_refund_timelock(&params, cfd.order.id); actor.monitor_commit_refund_timelock(&params, cfd.order.id);
actor.monitor_refund_finality(&params,cfd.order.id); actor.monitor_refund_finality(&params,cfd.order.id);
} }
CfdState::MustRefund { dlc, .. } => { CfdState::PendingRefund { dlc, .. } => {
let params = MonitorParams::from_dlc_and_timelocks(dlc.clone(), cfd.refund_timelock_in_blocks()); let params = MonitorParams::from_dlc_and_timelocks(dlc.clone(), cfd.refund_timelock_in_blocks());
actor.cfds.insert(cfd.order.id, params.clone()); actor.cfds.insert(cfd.order.id, params.clone());

2
daemon/src/oracle.rs

@ -86,7 +86,7 @@ impl Actor {
// Final states // Final states
| CfdState::Closed { .. } | CfdState::Closed { .. }
| CfdState::MustRefund { .. } | CfdState::PendingRefund { .. }
| CfdState::Refunded { .. } | CfdState::Refunded { .. }
| CfdState::SetupFailed { .. } => () | CfdState::SetupFailed { .. } => ()
} }

10
daemon/src/to_sse_event.rs

@ -208,7 +208,7 @@ pub enum CfdState {
IncomingRollOverProposal, IncomingRollOverProposal,
OutgoingRollOverProposal, OutgoingRollOverProposal,
Closed, Closed,
MustRefund, PendingRefund,
Refunded, Refunded,
SetupFailed, SetupFailed,
} }
@ -405,7 +405,7 @@ fn to_cfd_state(
model::cfd::CfdState::PendingOpen { .. } => CfdState::PendingOpen, model::cfd::CfdState::PendingOpen { .. } => CfdState::PendingOpen,
model::cfd::CfdState::Open { .. } => CfdState::Open, model::cfd::CfdState::Open { .. } => CfdState::Open,
model::cfd::CfdState::OpenCommitted { .. } => CfdState::OpenCommitted, model::cfd::CfdState::OpenCommitted { .. } => CfdState::OpenCommitted,
model::cfd::CfdState::MustRefund { .. } => CfdState::MustRefund, model::cfd::CfdState::PendingRefund { .. } => CfdState::PendingRefund,
model::cfd::CfdState::Refunded { .. } => CfdState::Refunded, model::cfd::CfdState::Refunded { .. } => CfdState::Refunded,
model::cfd::CfdState::SetupFailed { .. } => CfdState::SetupFailed, model::cfd::CfdState::SetupFailed { .. } => CfdState::SetupFailed,
model::cfd::CfdState::PendingCommit { .. } => CfdState::PendingCommit, model::cfd::CfdState::PendingCommit { .. } => CfdState::PendingCommit,
@ -454,7 +454,7 @@ fn to_tx_url_list(state: model::cfd::CfdState, network: Network) -> Vec<TxUrl> {
} => { } => {
vec![tx_ub.collaborative_close(collaborative_close.tx.txid())] vec![tx_ub.collaborative_close(collaborative_close.tx.txid())]
} }
MustRefund { dlc, .. } => vec![tx_ub.lock(&dlc), tx_ub.commit(&dlc), tx_ub.refund(&dlc)], PendingRefund { dlc, .. } => vec![tx_ub.lock(&dlc), tx_ub.commit(&dlc), tx_ub.refund(&dlc)],
Refunded { dlc, .. } => vec![tx_ub.refund(&dlc)], Refunded { dlc, .. } => vec![tx_ub.refund(&dlc)],
OutgoingOrderRequest { .. } OutgoingOrderRequest { .. }
| IncomingOrderRequest { .. } | IncomingOrderRequest { .. }
@ -538,8 +538,8 @@ mod tests {
assert_eq!(json, "\"Open\""); assert_eq!(json, "\"Open\"");
let json = serde_json::to_string(&CfdState::OpenCommitted).unwrap(); let json = serde_json::to_string(&CfdState::OpenCommitted).unwrap();
assert_eq!(json, "\"OpenCommitted\""); assert_eq!(json, "\"OpenCommitted\"");
let json = serde_json::to_string(&CfdState::MustRefund).unwrap(); let json = serde_json::to_string(&CfdState::PendingRefund).unwrap();
assert_eq!(json, "\"MustRefund\""); assert_eq!(json, "\"PendingRefund\"");
let json = serde_json::to_string(&CfdState::Refunded).unwrap(); let json = serde_json::to_string(&CfdState::Refunded).unwrap();
assert_eq!(json, "\"Refunded\""); assert_eq!(json, "\"Refunded\"");
let json = serde_json::to_string(&CfdState::SetupFailed).unwrap(); let json = serde_json::to_string(&CfdState::SetupFailed).unwrap();

8
frontend/src/components/Types.tsx

@ -95,7 +95,7 @@ export class State {
return "Rollover Proposed"; return "Rollover Proposed";
case StateKey.OUTGOING_ROLL_OVER_PROPOSAL: case StateKey.OUTGOING_ROLL_OVER_PROPOSAL:
return "Rollover Proposed"; return "Rollover Proposed";
case StateKey.MUST_REFUND: case StateKey.PENDING_REFUND:
return "Refunding"; return "Refunding";
case StateKey.REFUNDED: case StateKey.REFUNDED:
return "Refunded"; return "Refunded";
@ -124,7 +124,7 @@ export class State {
case StateKey.PENDING_COMMIT: case StateKey.PENDING_COMMIT:
case StateKey.OPEN_COMMITTED: case StateKey.OPEN_COMMITTED:
case StateKey.MUST_REFUND: case StateKey.PENDING_REFUND:
case StateKey.PENDING_CET: case StateKey.PENDING_CET:
case StateKey.PENDING_CLOSE: case StateKey.PENDING_CLOSE:
return orange; return orange;
@ -158,7 +158,7 @@ export class State {
case StateKey.OPEN: case StateKey.OPEN:
case StateKey.PENDING_COMMIT: case StateKey.PENDING_COMMIT:
case StateKey.OPEN_COMMITTED: case StateKey.OPEN_COMMITTED:
case StateKey.MUST_REFUND: case StateKey.PENDING_REFUND:
case StateKey.OUTGOING_SETTLEMENT_PROPOSAL: case StateKey.OUTGOING_SETTLEMENT_PROPOSAL:
case StateKey.OUTGOING_ROLL_OVER_PROPOSAL: case StateKey.OUTGOING_ROLL_OVER_PROPOSAL:
case StateKey.PENDING_CET: case StateKey.PENDING_CET:
@ -208,7 +208,7 @@ const enum StateKey {
INCOMING_SETTLEMENT_PROPOSAL = "IncomingSettlementProposal", INCOMING_SETTLEMENT_PROPOSAL = "IncomingSettlementProposal",
OUTGOING_ROLL_OVER_PROPOSAL = "OutgoingRollOverProposal", OUTGOING_ROLL_OVER_PROPOSAL = "OutgoingRollOverProposal",
INCOMING_ROLL_OVER_PROPOSAL = "IncomingRollOverProposal", INCOMING_ROLL_OVER_PROPOSAL = "IncomingRollOverProposal",
MUST_REFUND = "MustRefund", PENDING_REFUND = "PendingRefund",
REFUNDED = "Refunded", REFUNDED = "Refunded",
SETUP_FAILED = "SetupFailed", SETUP_FAILED = "SetupFailed",
CLOSED = "Closed", CLOSED = "Closed",

Loading…
Cancel
Save