breez_sdk_liquid/payjoin/
model.rs1use lwk_wollet::{
2 elements::{
3 confidential::{AssetBlindingFactor, ValueBlindingFactor},
4 script::Script,
5 Address, AssetId, Txid,
6 },
7 WalletTxOut,
8};
9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Serialize, Deserialize)]
12#[serde(rename_all = "snake_case")]
13#[allow(clippy::large_enum_variant)]
14pub(crate) enum Request {
15 AcceptedAssets(AcceptedAssetsRequest),
16 Start(StartRequest),
17 Sign(SignRequest),
18}
19
20#[derive(Debug, Serialize, Deserialize)]
21#[serde(rename_all = "snake_case")]
22#[allow(clippy::large_enum_variant)]
23pub(crate) enum Response {
24 AcceptedAssets(AcceptedAssetsResponse),
25 Start(StartResponse),
26 Sign(SignResponse),
27}
28
29#[derive(Debug, Serialize, Deserialize)]
30pub(crate) struct AcceptedAssetsRequest {}
31
32#[derive(Debug, Serialize, Deserialize)]
33pub(crate) struct AcceptedAssetsResponse {
34 pub accepted_asset: Vec<AcceptedAsset>,
35}
36
37#[derive(Clone, Debug, Serialize, Deserialize)]
38pub struct AcceptedAsset {
39 pub asset_id: String,
40}
41
42#[derive(Debug, Clone)]
43pub(crate) struct Recipient {
44 pub address: Address,
45 pub asset_id: AssetId,
46 pub amount: u64,
47}
48
49#[derive(Debug, Copy, Clone, PartialEq, Eq)]
50pub(crate) struct InOut {
51 pub asset_id: AssetId,
52 pub value: u64,
53}
54
55#[derive(Debug, Serialize, Deserialize, Clone)]
56pub(crate) struct Utxo {
57 pub txid: Txid,
58 pub vout: u32,
59 pub script_pub_key: Script,
60 pub asset_id: AssetId,
61 pub value: u64,
62 pub asset_bf: AssetBlindingFactor,
63 pub value_bf: ValueBlindingFactor,
64}
65
66impl From<&WalletTxOut> for Utxo {
67 fn from(tx_out: &WalletTxOut) -> Self {
68 Self {
69 txid: tx_out.outpoint.txid,
70 vout: tx_out.outpoint.vout,
71 script_pub_key: tx_out.script_pubkey.clone(),
72 asset_id: tx_out.unblinded.asset,
73 value: tx_out.unblinded.value,
74 asset_bf: tx_out.unblinded.asset_bf,
75 value_bf: tx_out.unblinded.value_bf,
76 }
77 }
78}
79
80#[derive(Debug, Serialize, Deserialize, Clone)]
81pub(crate) struct StartRequest {
82 pub asset_id: String,
83 pub user_agent: String,
84 pub api_key: Option<String>,
85}
86
87#[derive(Debug, Serialize, Deserialize, Clone)]
88pub(crate) struct StartResponse {
89 pub order_id: String,
90 pub expires_at: u64,
91 pub price: f64,
92 pub fixed_fee: u64,
93 pub fee_address: Address,
94 pub change_address: Address,
95 pub utxos: Vec<Utxo>,
96}
97
98#[derive(Debug, Serialize, Deserialize)]
99pub(crate) struct SignRequest {
100 pub order_id: String,
101 pub pset: String,
102}
103
104#[derive(Debug, Serialize, Deserialize)]
105pub(crate) struct SignResponse {
106 pub pset: String,
107}