Skip to main content

bark_json/
web.rs

1
2use bitcoin::{Amount, FeeRate, Txid};
3use bitcoin::consensus::encode::serialize_hex;
4use bitcoin::secp256k1::PublicKey;
5use serde::{Deserialize, Serialize};
6
7use ark::VtxoId;
8use ark::offboard::OffboardRequest;
9use ark::tree::signed::UnlockHash;
10use ark::vtxo::VtxoPolicyKind;
11
12#[cfg(feature = "utoipa")]
13use utoipa::ToSchema;
14
15use crate::cli::RoundStatus;
16
17
18/// Query parameters for filtering wallet history by payment method.
19///
20/// Both fields are optional but must be supplied together: omit both to get the
21/// full history, or provide both to filter by a single payment method. The pair
22/// mirrors the serialized form of a payment method (its `type` tag and `value`).
23#[derive(Default, Serialize, Deserialize)]
24#[cfg_attr(feature = "utoipa", derive(ToSchema))]
25pub struct HistoryQuery {
26	/// The payment method type tag to filter by, e.g. `ark`, `bitcoin`,
27	/// `output-script`, `invoice`, `offer`, `lightning-address`, `lnurl` or
28	/// `custom`. Must be provided together with `value`.
29	#[serde(rename = "type")]
30	pub method_type: Option<String>,
31	/// The payment method value to filter by, e.g. the destination address or
32	/// invoice. Must be provided together with `type`.
33	pub value: Option<String>,
34}
35
36/// Query parameters for fee estimates that only require an amount.
37#[derive(Serialize, Deserialize)]
38#[cfg_attr(feature = "utoipa", derive(ToSchema))]
39pub struct FeeEstimateQuery {
40	/// The amount in satoshis to estimate fees for
41	pub amount_sat: u64,
42}
43
44/// Query parameters for send-onchain fee estimates.
45#[derive(Serialize, Deserialize)]
46#[cfg_attr(feature = "utoipa", derive(ToSchema))]
47pub struct SendOnchainFeeEstimateQuery {
48	/// The amount in satoshis to send
49	pub amount_sat: u64,
50	/// The destination Bitcoin address
51	pub address: String,
52}
53
54/// Query parameters for offboard-all fee estimates.
55#[derive(Serialize, Deserialize)]
56#[cfg_attr(feature = "utoipa", derive(ToSchema))]
57pub struct OffboardAllFeeEstimateQuery {
58	/// The destination Bitcoin address
59	pub address: String,
60}
61
62/// Request body for estimating the fee of offboarding a specific set of VTXOs.
63#[derive(Serialize, Deserialize)]
64#[cfg_attr(feature = "utoipa", derive(ToSchema))]
65pub struct OffboardFeeEstimateRequest {
66	/// The destination Bitcoin address. The fee depends on its script type.
67	pub address: String,
68	/// The IDs of the VTXOs to offboard. Each is offboarded in full.
69	pub vtxos: Vec<String>,
70}
71
72/// A fee estimate for an Ark wallet operation.
73#[derive(Serialize, Deserialize)]
74#[cfg_attr(feature = "utoipa", derive(ToSchema))]
75pub struct FeeEstimateResponse {
76	/// The total amount including fees (in satoshis)
77	#[serde(rename = "gross_amount_sat", with = "bitcoin::amount::serde::as_sat")]
78	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
79	pub gross_amount: Amount,
80	/// The fee portion (in satoshis)
81	#[serde(rename = "fee_sat", with = "bitcoin::amount::serde::as_sat")]
82	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
83	pub fee: Amount,
84	/// The amount excluding fees (in satoshis). For sends, this is the amount
85	/// the recipient receives. For receives, this is the amount the user gets.
86	#[serde(rename = "net_amount_sat", with = "bitcoin::amount::serde::as_sat")]
87	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
88	pub net_amount: Amount,
89	/// The VTXOs that would be spent for this operation
90	#[cfg_attr(feature = "utoipa", schema(value_type = Vec<String>))]
91	pub vtxos_spent: Vec<VtxoId>,
92}
93
94impl From<bark::FeeEstimate> for FeeEstimateResponse {
95	fn from(estimate: bark::FeeEstimate) -> Self {
96		FeeEstimateResponse {
97			gross_amount: estimate.gross_amount,
98			fee: estimate.fee,
99			net_amount: estimate.net_amount,
100			vtxos_spent: estimate.vtxos_spent,
101		}
102	}
103}
104
105/// Mempool fee rates for on-chain transactions.
106#[derive(Serialize, Deserialize)]
107#[cfg_attr(feature = "utoipa", derive(ToSchema))]
108pub struct OnchainFeeRatesResponse {
109	/// Fee rate targeting ~1 block confirmation (sat/vB)
110	pub fast_sat_per_vb: u64,
111	/// Fee rate targeting ~3 block confirmation (sat/vB)
112	pub regular_sat_per_vb: u64,
113	/// Fee rate targeting ~6 block confirmation (sat/vB)
114	pub slow_sat_per_vb: u64,
115}
116
117
118#[derive(Serialize, Deserialize)]
119#[cfg_attr(feature = "utoipa", derive(ToSchema))]
120pub struct TipResponse {
121	pub tip_height: u32,
122}
123
124#[derive(Serialize, Deserialize)]
125#[cfg_attr(feature = "utoipa", derive(ToSchema))]
126pub struct MailboxSyncResponse {
127	/// The mailbox checkpoint (tip) the wallet has consumed up to after
128	/// the sync. Monotonically non-decreasing across successful syncs.
129	pub checkpoint: u64,
130}
131
132#[derive(Serialize, Deserialize)]
133#[cfg_attr(feature = "utoipa", derive(ToSchema))]
134pub struct CreateWalletRequest {
135	/// The Ark server to use for the wallet.
136	/// Optional when a config.toml already exists in the datadir.
137	pub ark_server: Option<String>,
138	/// An access token for a private Ark server.
139	///
140	/// **Deprecated**: access tokens are no longer enforced by the server;
141	/// this field will be removed in a future release.
142	#[deprecated(
143		since = "0.2.4",
144		note = "access tokens are not enforced by the server; this field will be removed",
145	)]
146	pub ark_server_access_token: Option<String>,
147	/// The chain source to use for the wallet.
148	/// Optional when a config.toml already exists in the datadir.
149	pub chain_source: Option<ChainSourceConfig>,
150	/// The optional mnemonic to use for the wallet
151	pub mnemonic: Option<String>,
152	/// The network to use for the wallet
153	pub network: BarkNetwork,
154	/// An optional birthday height to start syncing the wallet from
155	pub birthday_height: Option<u32>,
156}
157
158/// Networks bark can be used on
159#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
160#[serde(rename_all = "kebab-case")]
161#[cfg_attr(feature = "utoipa", derive(ToSchema))]
162pub enum BarkNetwork {
163	/// Bitcoin's mainnet
164	Mainnet,
165	/// The official Bitcoin Core signet
166	Signet,
167	/// Mutinynet
168	Mutinynet,
169	/// Any regtest network
170	Regtest,
171}
172
173#[derive(Serialize, Deserialize)]
174#[serde(rename_all = "kebab-case")]
175#[cfg_attr(feature = "utoipa", derive(ToSchema))]
176pub enum ChainSourceConfig {
177	/// Use a bitcoind RPC server
178	Bitcoind {
179		bitcoind: String,
180		bitcoind_auth: BitcoindAuth,
181	},
182	/// Use an Esplora HTTP server
183	Esplora {
184		url: String,
185	},
186}
187
188#[derive(Serialize, Deserialize)]
189#[serde(rename_all = "kebab-case")]
190#[cfg_attr(feature = "utoipa", derive(ToSchema))]
191pub enum BitcoindAuth {
192	/// Use a cookie file for authentication
193	Cookie {
194		cookie: String,
195	},
196	/// Use a username and password for authentication
197	UserPass {
198		user: String,
199		pass: String,
200	},
201}
202
203#[derive(Serialize, Deserialize)]
204#[cfg_attr(feature = "utoipa", derive(ToSchema))]
205pub struct CreateWalletResponse {
206	pub fingerprint: String,
207}
208
209#[derive(Serialize, Deserialize)]
210#[cfg_attr(feature = "utoipa", derive(ToSchema))]
211pub struct ConnectedResponse {
212	/// Whether the wallet is currently connected to its Ark server
213	pub connected: bool,
214}
215
216#[derive(Serialize, Deserialize)]
217#[cfg_attr(feature = "utoipa", derive(ToSchema))]
218pub struct MnemonicResponse {
219	/// The BIP-39 mnemonic phrase backing the wallet.
220	pub mnemonic: String,
221}
222
223#[derive(Serialize, Deserialize)]
224#[cfg_attr(feature = "utoipa", derive(ToSchema))]
225pub struct ArkAddressResponse {
226	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
227	pub address: String,
228}
229
230/// Request to build a BIP 321 unified payment URI.
231///
232/// An Ark address is always included. A BOLT11 invoice is only included when
233/// `amount_sat` is given (an amount is required to create one). An on-chain
234/// address is included only when `onchain` is `true`.
235#[derive(Serialize, Deserialize)]
236#[cfg_attr(feature = "utoipa", derive(ToSchema))]
237pub struct Bip321UriRequest {
238	/// Optional amount (in satoshis) to request. When set, it is embedded in
239	/// the URI and used to create the BOLT11 invoice. Any server-configured
240	/// [LightningReceiveFees](crate::cli::fees::LightningReceiveFees) are
241	/// deducted from the amount the client ultimately receives over Lightning.
242	#[serde(default, skip_serializing_if = "Option::is_none")]
243	pub amount_sat: Option<u64>,
244	/// Whether to include a fresh on-chain address as a payment destination.
245	/// Defaults to `false`.
246	#[serde(default, skip_serializing_if = "Option::is_none")]
247	pub onchain: Option<bool>,
248	/// Optional label describing the payment, recorded in the URI's `label`.
249	#[serde(default, skip_serializing_if = "Option::is_none")]
250	pub label: Option<String>,
251	/// Optional message describing the payment, recorded in the URI's `message`.
252	#[serde(default, skip_serializing_if = "Option::is_none")]
253	pub message: Option<String>,
254}
255
256/// Query parameters for building a BIP 321 URI.
257#[derive(Serialize, Deserialize)]
258#[cfg_attr(feature = "utoipa", derive(ToSchema))]
259pub struct Bip321UriQuery {
260	/// Whether to upper-case the returned `bip321` URI so QR encoders can use
261	/// the compact alphanumeric mode. Defaults to `false`.
262	/// Requesting an upper-case URI fails when it carries case-sensitive data
263	/// (a label or message with lowercase characters, or base58 address) that
264	/// cannot be upper-cased.
265	pub uppercase: Option<bool>,
266}
267
268/// A BIP 321 unified payment URI together with its individual destinations.
269///
270/// The `bip321` field is the combined `bitcoin:` URI; the other fields expose
271/// each generated destination separately for convenience. A field is `null`
272/// when that destination was not requested or could not be produced.
273#[derive(Serialize, Deserialize)]
274#[cfg_attr(feature = "utoipa", derive(ToSchema))]
275pub struct Bip321UriResponse {
276	/// The generated Ark address, if any.
277	#[serde(skip_serializing_if = "Option::is_none")]
278	pub ark: Option<String>,
279	/// The generated BOLT11 invoice, included only when an amount was given.
280	#[serde(skip_serializing_if = "Option::is_none")]
281	pub bolt11: Option<String>,
282	/// The generated on-chain address, included only when `onchain` was set.
283	#[serde(skip_serializing_if = "Option::is_none")]
284	pub onchain: Option<String>,
285	/// The combined BIP 321 `bitcoin:` URI.
286	pub bip321: String,
287}
288
289/// Response for the encoded-VTXO endpoint.
290///
291/// Wraps the hex-encoded VTXO in a named field so clients can easily
292/// extract it.
293#[derive(Serialize, Deserialize)]
294#[cfg_attr(feature = "utoipa", derive(ToSchema))]
295pub struct EncodedVtxoResponse {
296	/// Hex-encoded serialized VTXO.
297	pub encoded: crate::primitives::EncodedVtxo,
298}
299
300#[derive(Serialize, Deserialize)]
301#[cfg_attr(feature = "utoipa", derive(ToSchema))]
302pub struct VtxosQuery {
303	/// Return all VTXOs regardless of their state (including spent ones)
304	pub all: Option<bool>,
305}
306
307#[derive(Serialize, Deserialize)]
308#[cfg_attr(feature = "utoipa", derive(ToSchema))]
309pub struct RefreshRequest {
310	/// List of VTXO IDs to refresh. The sum of the VTXOs being refreshed must be
311	/// >= [P2TR_DUST](bitcoin_ext::P2TR_DUST). Keep in mind that fees set out in
312	/// [RefreshFees](crate::cli::fees::RefreshFees) will be deducted from the newly created VTXO, this
313	/// value must also be >= [P2TR_DUST](bitcoin_ext::P2TR_DUST).
314	pub vtxos: Vec<String>,
315}
316
317#[derive(Serialize, Deserialize)]
318#[cfg_attr(feature = "utoipa", derive(ToSchema))]
319pub struct DelegatedRefreshRequest {
320	/// List of VTXO IDs to refresh. The sum of the VTXOs being refreshed must be
321	/// >= [P2TR_DUST](bitcoin_ext::P2TR_DUST). Keep in mind that fees set out in
322	/// [RefreshFees](crate::cli::fees::RefreshFees) will be deducted from the newly created VTXO, this
323	/// value must also be >= [P2TR_DUST](bitcoin_ext::P2TR_DUST).
324	pub vtxos: Vec<String>,
325	/// Optional block height to schedule the refresh at. When set, the refresh fee is priced at
326	/// that height and the server includes the participation in the first round once the chain
327	/// tip reaches it; when omitted, the participation is eligible for the next round.
328	pub height: Option<u32>,
329}
330
331#[derive(Serialize, Deserialize)]
332#[cfg_attr(feature = "utoipa", derive(ToSchema))]
333pub struct BoardRequest {
334	/// An amount of onchain funds to board (in satoshis). For a board operation to be successful,
335	/// this value, with any server-configured [BoardFees](crate::cli::fees::BoardFees) deducted, must be
336	/// >= [P2TR_DUST](bitcoin_ext::P2TR_DUST).
337	pub amount_sat: u64,
338}
339
340#[derive(Serialize, Deserialize)]
341#[cfg_attr(feature = "utoipa", derive(ToSchema))]
342pub struct SendRequest {
343	/// The destination can be an Ark address, a BOLT11-invoice, LNURL or a lightning address
344	pub destination: String,
345	/// The amount to send (in satoshis). Optional for bolt11 invoices. Depending on the
346	/// `destination`, the wallet must contain this amount plus any fees configured by the server in
347	/// [FeeSchedule](crate::cli::fees::FeeSchedule).
348	pub amount_sat: Option<u64>,
349	/// An optional comment, only supported when paying to lightning addresses
350	pub comment: Option<String>,
351}
352
353#[derive(Serialize, Deserialize)]
354#[cfg_attr(feature = "utoipa", derive(ToSchema))]
355pub struct SendResponse {
356	/// Success message
357	pub message: String,
358}
359
360#[derive(Serialize, Deserialize)]
361#[cfg_attr(feature = "utoipa", derive(ToSchema))]
362pub struct SendOnchainRequest {
363	/// The destination Bitcoin address
364	pub destination: String,
365	/// The amount (in satoshis) to be received by `destination` onchain. Must be
366	/// >= [P2TR_DUST](bitcoin_ext::P2TR_DUST). Server-configured fees laid out in
367	/// [OffboardFees](crate::cli::fees::OffboardFees) will be added on top of this amount.
368	pub amount_sat: u64,
369}
370
371#[derive(Serialize, Deserialize)]
372#[cfg_attr(feature = "utoipa", derive(ToSchema))]
373pub struct OffboardVtxosRequest {
374	/// Optional Bitcoin address to send to. If not provided, uses the onchain wallet's address
375	pub address: Option<String>,
376	/// List of VTXO IDs to offboard. The sum of the VTXOs being refreshed must be
377	/// >= [P2TR_DUST](bitcoin_ext::P2TR_DUST) after the server-configured
378	/// [OffboardFees](crate::cli::fees::OffboardFees) are deducted.
379	pub vtxos: Vec<String>,
380}
381
382#[derive(Serialize, Deserialize)]
383#[cfg_attr(feature = "utoipa", derive(ToSchema))]
384pub struct OffboardAllRequest {
385	/// Optional Bitcoin address to send to. If not provided, uses the onchain wallet's address
386	pub address: Option<String>,
387}
388
389#[derive(Serialize, Deserialize)]
390#[cfg_attr(feature = "utoipa", derive(ToSchema))]
391pub struct ImportVtxoRequest {
392	/// Hex-encoded VTXOs to import
393	pub vtxos: Vec<String>,
394}
395
396#[derive(Serialize, Deserialize)]
397#[cfg_attr(feature = "utoipa", derive(ToSchema))]
398pub struct LightningInvoiceRequest {
399	/// The amount to create invoice for (in satoshis). This is the amount the payee will pay but
400	/// the final amount received by the client will have any server-configured
401	/// [LightningReceiveFees](crate::cli::fees::LightningReceiveFees) deducted.
402	pub amount_sat: u64,
403	/// Optional description embedded in the invoice as its memo.
404	#[serde(default, skip_serializing_if = "Option::is_none")]
405	pub description: Option<String>,
406}
407
408#[derive(Serialize, Deserialize)]
409#[cfg_attr(feature = "utoipa", derive(ToSchema))]
410pub struct LightningInvoiceForAddressRequest {
411	/// The amount to create invoice for (in satoshis).
412	pub amount_sat: u64,
413	/// Ark address that will receive the claimed VTXO.
414	pub address: String,
415	/// Optional description embedded in the invoice as its memo.
416	#[serde(default, skip_serializing_if = "Option::is_none")]
417	pub description: Option<String>,
418}
419
420#[derive(Serialize, Deserialize)]
421#[cfg_attr(feature = "utoipa", derive(ToSchema))]
422pub struct LightningPayRequest {
423	/// The invoice, offer, or lightning address to pay
424	pub destination: String,
425	/// The amount to send (in satoshis). Optional for bolt11 invoices with amount. This must be
426	/// higher than the minimum fee laid out in server-configured
427	/// [LightningSendFees](crate::cli::fees::LightningSendFees). The wallet must also contain enough
428	/// funds to cover the amount plus any fees.
429	pub amount_sat: Option<u64>,
430	/// An optional comment, only supported when paying to lightning addresses
431	pub comment: Option<String>,
432}
433
434#[derive(Serialize, Deserialize)]
435#[cfg_attr(feature = "utoipa", derive(ToSchema))]
436pub struct LightningPayResponse {
437	/// Success message
438	pub message: String,
439}
440
441#[derive(Serialize, Deserialize)]
442#[cfg_attr(feature = "utoipa", derive(ToSchema))]
443pub struct OnchainSendRequest {
444	/// The destination Bitcoin address
445	pub destination: String,
446	/// The amount to send (in satoshis)
447	pub amount_sat: u64,
448}
449
450#[derive(Serialize, Deserialize)]
451#[cfg_attr(feature = "utoipa", derive(ToSchema))]
452pub struct OnchainSendManyRequest {
453	/// List of destinations in format "address:amount"
454	pub destinations: Vec<String>,
455	/// Sends the transaction immediately instead of waiting
456	pub immediate: Option<bool>,
457}
458
459#[derive(Serialize, Deserialize)]
460#[cfg_attr(feature = "utoipa", derive(ToSchema))]
461pub struct OnchainDrainRequest {
462	/// The destination Bitcoin address
463	pub destination: String,
464}
465
466#[derive(Serialize, Deserialize)]
467#[cfg_attr(feature = "utoipa", derive(ToSchema))]
468pub struct ExitStatusRequest {
469	/// Whether to include the detailed history of the exit process
470	pub history: Option<bool>,
471	/// Whether to include the exit transactions and their CPFP children
472	pub transactions: Option<bool>,
473}
474
475#[derive(Serialize, Deserialize)]
476#[cfg_attr(feature = "utoipa", derive(ToSchema))]
477pub struct ExitStartRequest {
478	/// The ID of VTXOs to unilaterally exit
479	pub vtxos: Vec<String>,
480}
481
482#[derive(Serialize, Deserialize)]
483#[cfg_attr(feature = "utoipa", derive(ToSchema))]
484pub struct ExitStartResponse {
485	pub message: String,
486}
487
488#[derive(Serialize, Deserialize)]
489#[cfg_attr(feature = "utoipa", derive(ToSchema))]
490pub struct ExitProgressRequest {
491	/// Wait until the exit is completed
492	pub wait: Option<bool>,
493	/// Sets the desired fee-rate in sats/kvB to use broadcasting exit transactions
494	pub fee_rate: Option<u64>,
495}
496
497#[derive(Serialize, Deserialize)]
498#[cfg_attr(feature = "utoipa", derive(ToSchema))]
499pub struct ExitClaimAllRequest {
500	/// The destination Bitcoin address
501	pub destination: String,
502	/// Sets the desired fee-rate in sats/kvB to use broadcasting exit transactions
503	pub fee_rate: Option<u64>,
504}
505
506#[derive(Serialize, Deserialize)]
507#[cfg_attr(feature = "utoipa", derive(ToSchema))]
508pub struct ExitClaimVtxosRequest {
509	/// The destination Bitcoin address
510	pub destination: String,
511	/// The ID of an exited VTXO to be claimed
512	pub vtxos: Vec<String>,
513	/// Sets the desired fee-rate in sats/kvB to use broadcasting exit transactions
514	pub fee_rate: Option<u64>,
515}
516
517#[derive(Serialize, Deserialize)]
518#[cfg_attr(feature = "utoipa", derive(ToSchema))]
519pub struct ExitClaimResponse {
520	pub message: String,
521}
522
523#[derive(Serialize, Deserialize)]
524#[cfg_attr(feature = "utoipa", derive(ToSchema))]
525pub struct ExitCancelResponse {
526	pub message: String,
527}
528
529
530#[derive(Serialize, Deserialize)]
531#[cfg_attr(feature = "utoipa", derive(ToSchema))]
532pub struct VtxoRequestInfo {
533	#[serde(rename = "amount_sat", with = "bitcoin::amount::serde::as_sat")]
534	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
535	pub amount: Amount,
536	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
537	pub policy_type: VtxoPolicyKind,
538	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
539	pub user_pubkey: PublicKey,
540}
541
542impl<'a> From<&'a ark::VtxoRequest> for VtxoRequestInfo {
543	fn from(v: &'a ark::VtxoRequest) -> Self {
544		Self {
545			amount: v.amount,
546			policy_type: v.policy.policy_type(),
547			user_pubkey: v.policy.user_pubkey(),
548		}
549	}
550}
551
552#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
553#[cfg_attr(feature = "utoipa", derive(ToSchema))]
554pub struct OffboardRequestInfo {
555	/// hexadecimal representation of the output script
556	pub script_pubkey_hex: String,
557	/// opcode representation of the output script
558	pub script_pubkey_asm: String,
559	/// The target amount in sats.
560	#[serde(rename = "net_amount_sat", with = "bitcoin::amount::serde::as_sat")]
561	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
562	pub net_amount: Amount,
563	/// Determines whether fees should be added onto the given amount or deducted from it.
564	pub deduct_fees_from_gross_amount: bool,
565	/// What fee rate was used when calculating the fee for the offboard.
566	#[serde(rename = "fee_rate_kwu")]
567	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
568	pub fee_rate: FeeRate,
569}
570
571impl<'a> From<&'a OffboardRequest> for OffboardRequestInfo {
572	fn from(v: &'a OffboardRequest) -> Self {
573		Self {
574			script_pubkey_hex: v.script_pubkey.to_hex_string(),
575			script_pubkey_asm: v.script_pubkey.to_asm_string(),
576			net_amount: v.net_amount,
577			deduct_fees_from_gross_amount: v.deduct_fees_from_gross_amount,
578			fee_rate: v.fee_rate,
579		}
580	}
581}
582
583#[derive(Serialize, Deserialize)]
584#[cfg_attr(feature = "utoipa", derive(ToSchema))]
585pub struct RoundParticipationInfo {
586	#[cfg_attr(feature = "utoipa", schema(value_type = Vec<String>))]
587	pub inputs: Vec<VtxoId>,
588	pub outputs: Vec<VtxoRequestInfo>,
589}
590
591impl<'a> From<&'a bark::round::RoundParticipation> for RoundParticipationInfo {
592	fn from(v: &'a bark::round::RoundParticipation) -> Self {
593		Self {
594			inputs: v.inputs.iter().map(|v| v.id()).collect(),
595			outputs: v.outputs.iter().map(Into::into).collect(),
596		}
597	}
598}
599
600#[derive(Serialize, Deserialize)]
601#[cfg_attr(feature = "utoipa", derive(ToSchema))]
602pub struct PendingRoundInfo {
603	/// Unique identifier for the round
604	pub id: u32,
605	/// the current status of the round
606	pub status: RoundStatus,
607	/// the round participation details
608	pub participation: RoundParticipationInfo,
609	#[cfg_attr(feature = "utoipa", schema(value_type = String, nullable = true))]
610	pub unlock_hash: Option<UnlockHash>,
611	/// The round transaction id, if already assigned
612	#[cfg_attr(feature = "utoipa", schema(value_type = String, nullable = true))]
613	pub funding_txid: Option<Txid>,
614	pub funding_tx_hex: Option<String>,
615}
616
617impl PendingRoundInfo {
618	pub fn new<G>(
619		state: &bark::persist::models::StoredRoundState<G>,
620		sync_result: anyhow::Result<bark::round::RoundStatus>,
621	) -> Self {
622		let funding_tx = state.state().funding_tx();
623		Self {
624			id: state.id().0,
625			status: match sync_result {
626				Ok(status) => status.into(),
627				Err(e) => RoundStatus::SyncError {
628					error: format!("{:#}", e),
629				},
630			},
631			participation: state.state().participation().into(),
632			unlock_hash: state.state().unlock_hash(),
633			funding_txid: funding_tx.map(|t| t.compute_txid()),
634			funding_tx_hex: funding_tx.map(|t| serialize_hex(t)),
635		}
636	}
637}
638
639#[derive(Serialize, Deserialize)]
640#[cfg_attr(feature = "utoipa", derive(ToSchema))]
641pub struct WalletExistsResponse {
642	pub fingerprint: Option<String>,
643}
644
645#[derive(Serialize, Deserialize)]
646#[cfg_attr(feature = "utoipa", derive(ToSchema))]
647pub struct WalletDeleteRequest {
648	pub dangerous: bool,
649	pub fingerprint: String,
650}
651
652#[derive(Serialize, Deserialize)]
653#[cfg_attr(feature = "utoipa", derive(ToSchema))]
654pub struct WalletDeleteResponse {
655	pub deleted: bool,
656	pub message: String,
657}