use serde::{Deserialize, Serialize};
#[cfg(feature = "utoipa")]
use utoipa::ToSchema;
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct TipResponse {
pub tip_height: u32,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ConnectedResponse {
pub connected: bool,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ArkAddressResponse {
#[cfg_attr(feature = "utoipa", schema(value_type = String))]
pub address: String,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct VtxosQuery {
pub all: Option<bool>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct RefreshRequest {
pub vtxos: Vec<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct BoardRequest {
pub amount_sat: u64,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct SendRequest {
pub destination: String,
pub amount_sat: Option<u64>,
pub comment: Option<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct SendResponse {
pub message: String,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct SendOnchainRequest {
pub destination: String,
pub amount_sat: u64,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OffboardVtxosRequest {
pub address: Option<String>,
pub vtxos: Vec<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OffboardAllRequest {
pub address: Option<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct LightningInvoiceRequest {
pub amount_sat: u64,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct LightningPayRequest {
pub destination: String,
pub amount_sat: Option<u64>,
pub comment: Option<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct LightningPayResponse {
pub message: String,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OnchainSendRequest {
pub destination: String,
pub amount_sat: u64,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OnchainSendManyRequest {
pub destinations: Vec<String>,
pub immediate: Option<bool>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OnchainDrainRequest {
pub destination: String,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitStatusRequest {
pub history: Option<bool>,
pub transactions: Option<bool>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitStartRequest {
pub vtxos: Vec<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitStartResponse {
pub message: String,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitProgressRequest {
pub wait: Option<bool>,
pub fee_rate: Option<u64>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitClaimAllRequest {
pub destination: String,
pub fee_rate: Option<u64>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitClaimVtxosRequest {
pub destination: String,
pub vtxos: Vec<String>,
pub fee_rate: Option<u64>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitClaimResponse {
pub message: String,
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub enum PendingRoundStatus {
WaitingToStart,
AttemptStarted,
PaymentSubmitted,
VtxoTreeSigned,
ForfeitSigned,
PendingConfirmation,
Confirmed,
Failed,
Canceled,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct PendingRoundInfo {
pub id: u32,
pub status: PendingRoundStatus,
pub round_seq: Option<u64>,
pub attempt_seq: Option<usize>,
#[cfg_attr(feature = "utoipa", schema(value_type = String, nullable = true))]
pub round_txid: Option<ark::rounds::RoundId>,
}
impl From<bark::persist::StoredRoundState> for PendingRoundInfo {
fn from(state: bark::persist::StoredRoundState) -> Self {
match state.state.flow() {
bark::round::RoundFlowState::WaitingToStart => {
PendingRoundInfo {
id: state.id.0,
status: PendingRoundStatus::WaitingToStart,
round_seq: None,
attempt_seq: None,
round_txid: None,
}
},
bark::round::RoundFlowState::Ongoing { round_seq, attempt_seq, state: attempt_state } => {
let status = match attempt_state {
bark::round::AttemptState::AwaitingAttempt => PendingRoundStatus::AttemptStarted,
bark::round::AttemptState::AwaitingUnsignedVtxoTree { .. } => PendingRoundStatus::PaymentSubmitted,
bark::round::AttemptState::AwaitingRoundProposal { .. } => PendingRoundStatus::VtxoTreeSigned,
bark::round::AttemptState::AwaitingFinishedRound { .. } => PendingRoundStatus::ForfeitSigned,
};
let round_txid = state.state.unconfirmed_rounds().first()
.map(|r| r.funding_txid())
.map(|txid| ark::rounds::RoundId::from(txid));
PendingRoundInfo {
id: state.id.0,
status,
round_seq: Some(round_seq.inner() as u64),
attempt_seq: Some(*attempt_seq),
round_txid: round_txid,
}
},
bark::round::RoundFlowState::Success => {
if !state.state.unconfirmed_rounds().is_empty() {
let round_txid = state.state.unconfirmed_rounds().first()
.map(|r| r.funding_txid())
.map(|txid| ark::rounds::RoundId::from(txid));
PendingRoundInfo {
id: state.id.0,
status: PendingRoundStatus::PendingConfirmation,
round_seq: None,
attempt_seq: None,
round_txid: round_txid,
}
} else {
PendingRoundInfo {
id: state.id.0,
status: PendingRoundStatus::Confirmed,
round_seq: None,
attempt_seq: None,
round_txid: None,
}
}
},
bark::round::RoundFlowState::Failed { .. } => {
let round_txid = state.state.unconfirmed_rounds().first()
.map(|r| r.funding_txid())
.map(|txid| ark::rounds::RoundId::from(txid));
PendingRoundInfo {
id: state.id.0,
status: PendingRoundStatus::Failed,
round_seq: None,
attempt_seq: None,
round_txid: round_txid,
}
},
bark::round::RoundFlowState::Canceled => {
PendingRoundInfo {
id: state.id.0,
status: PendingRoundStatus::Canceled,
round_seq: None,
attempt_seq: None,
round_txid: None,
}
},
}
}
}