1
2use ark::Vtxo;
3use bitcoin::Amount;
4
5use crate::vtxo_state::VtxoState;
6
7#[derive(Debug, Deserialize, Serialize)]
8pub enum MovementKind {
9 Board,
10 Round,
11 Offboard,
12 Exit,
13 ArkoorSend,
14 ArkoorReceive,
15 LightningSend,
16 LightningSendRevocation,
17 LightningReceive,
18}
19
20impl MovementKind {
21 pub fn from_str(s: &str) -> anyhow::Result<Self> {
22 match s {
23 "onboard" => Ok(MovementKind::Board),
24 "round" => Ok(MovementKind::Round),
25 "offboard" => Ok(MovementKind::Offboard),
26 "arkoor-send" => Ok(MovementKind::ArkoorSend),
27 "arkoor-receive" => Ok(MovementKind::ArkoorReceive),
28 "lightning-send" => Ok(MovementKind::LightningSend),
29 "lightning-send-revocation" => Ok(MovementKind::LightningSendRevocation),
30 "lightning-receive" => Ok(MovementKind::LightningReceive),
31 "exit" => Ok(MovementKind::Exit),
32 _ => bail!("Invalid movement kind: {}", s),
33 }
34 }
35
36 pub fn as_str(&self) -> &str {
37 match self {
38 MovementKind::Board => "onboard",
39 MovementKind::Round => "round",
40 MovementKind::Offboard => "offboard",
41 MovementKind::ArkoorSend => "arkoor-send",
42 MovementKind::ArkoorReceive => "arkoor-receive",
43 MovementKind::LightningSend => "lightning-send",
44 MovementKind::LightningSendRevocation => "lightning-send-revocation",
45 MovementKind::LightningReceive => "lightning-receive",
46 MovementKind::Exit => "exit",
47 }
48 }
49}
50
51#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
52pub struct MovementRecipient {
53 pub recipient: String,
55 #[serde(rename = "amount_sat", with = "bitcoin::amount::serde::as_sat")]
57 pub amount: Amount
58}
59
60#[derive(Debug)]
63pub struct Movement {
64 pub id: u32,
65 pub kind: MovementKind,
67 pub fees: Amount,
69 pub spends: Vec<Vtxo>,
71 pub receives: Vec<Vtxo>,
73 pub recipients: Vec<MovementRecipient>,
75 pub created_at: String,
77}
78
79pub struct MovementArgs<'a> {
81 pub kind: MovementKind,
83 pub spends: &'a [&'a Vtxo],
87 pub receives: &'a [(&'a Vtxo, VtxoState)],
89 pub recipients: &'a [(&'a str, Amount)],
91 pub fees: Option<Amount>
93}