use ark::lightning::{Bolt11Invoice, PaymentHash, Preimage};
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 PeakAddressRequest {
pub index: 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 LightningStatusRequest {
pub filter: Option<String>,
pub preimage: Option<String>,
}
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct LightningStatusResponse {
#[cfg_attr(feature = "utoipa", schema(value_type = String))]
pub payment_hash: PaymentHash,
#[cfg_attr(feature = "utoipa", schema(value_type = String))]
pub payment_preimage: Preimage,
#[cfg_attr(feature = "utoipa", schema(value_type = String))]
pub invoice: Bolt11Invoice,
pub preimage_revealed_at: Option<chrono::DateTime<chrono::Utc>>,
}
#[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,
#[cfg_attr(feature = "utoipa", schema(value_type = String))]
pub preimage: Option<Preimage>,
}
#[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 vtxo: String,
pub history: Option<bool>,
pub transactions: Option<bool>,
}
#[derive(Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct ExitListRequest {
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)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct PendingRoundInfo {
pub id: u32,
pub kind: String,
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,
kind: "WaitingToStart".to_string(),
round_seq: None,
attempt_seq: None,
round_txid: None,
}
},
bark::round::RoundFlowState::Ongoing { round_seq, attempt_seq, state: attempt_state } => {
let kind = match attempt_state {
bark::round::AttemptState::AwaitingAttempt => "AttemptStarted",
bark::round::AttemptState::AwaitingUnsignedVtxoTree { .. } => "PaymentSubmitted",
bark::round::AttemptState::AwaitingRoundProposal { .. } => "VtxoTreeSigned",
bark::round::AttemptState::AwaitingFinishedRound { .. } => "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,
kind: kind.to_string(),
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,
kind: "PendingConfirmation".to_string(),
round_seq: None,
attempt_seq: None,
round_txid: round_txid,
}
} else {
PendingRoundInfo {
id: state.id.0,
kind: "RoundConfirmed".to_string(),
round_seq: None,
attempt_seq: None,
round_txid: None,
}
}
},
bark::round::RoundFlowState::Failed { .. } => {
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,
kind: "RoundCancelled".to_string(),
round_seq: None,
attempt_seq: None,
round_txid: round_txid,
}
} else {
PendingRoundInfo {
id: state.id.0,
kind: "RoundAbandoned".to_string(),
round_seq: None,
attempt_seq: None,
round_txid: None,
}
}
},
}
}
}