ree_types/
exchange_interfaces.rs1use crate::{CoinBalance, IntentionSet, Pubkey, Txid, Utxo};
2use alloc::borrow::Cow;
3use candid::CandidType;
4use ic_stable_structures::{Storable, storable::Bound};
5use serde::{Deserialize, Serialize};
6
7#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
8pub struct PoolBasic {
9 pub name: String,
10 pub address: String,
11}
12
13#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
14pub struct PoolInfo {
15 pub key: Pubkey,
16 pub key_derivation_path: Vec<Vec<u8>>,
17 pub name: String,
18 pub address: String,
19 pub nonce: u64,
20 pub coin_reserved: Vec<CoinBalance>,
21 pub btc_reserved: u64,
22 pub utxos: Vec<Utxo>,
23 pub attributes: String,
24}
25
26pub type GetPoolListResponse = Vec<PoolBasic>;
27
28#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
29pub struct GetPoolInfoArgs {
30 pub pool_address: String,
31}
32
33pub type GetPoolInfoResponse = Option<PoolInfo>;
34
35#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
36pub struct ExecuteTxArgs {
37 pub psbt_hex: String,
38 pub txid: Txid,
39 pub intention_set: IntentionSet,
40 pub intention_index: u32,
41 pub zero_confirmed_tx_queue_length: u32,
42}
43
44impl ExecuteTxArgs {
45 pub fn psbt(&self) -> Result<bitcoin::Psbt, String> {
46 let raw = hex::decode(&self.psbt_hex).map_err(|_| "invalid psbt".to_string())?;
47 bitcoin::Psbt::deserialize(raw.as_slice()).map_err(|_| "invalid psbt".to_string())
48 }
49}
50
51pub type ExecuteTxResponse = Result<String, String>;
52
53#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
54pub struct RollbackTxArgs {
55 pub txid: Txid,
56 pub reason_code: String,
57}
58
59pub type RollbackTxResponse = Result<(), String>;
60
61#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
63pub struct NewBlockInfo {
64 pub block_height: u32,
65 pub block_hash: String,
66 pub block_timestamp: u64,
68 pub confirmed_txids: Vec<Txid>,
69}
70
71pub type NewBlockArgs = NewBlockInfo;
72
73pub type NewBlockResponse = Result<(), String>;
74
75impl Storable for NewBlockInfo {
76 fn to_bytes(&self) -> Cow<'_, [u8]> {
77 let bytes = bincode::serialize(self).unwrap();
78 Cow::Owned(bytes)
79 }
80
81 fn into_bytes(self) -> Vec<u8> {
82 bincode::serialize(&self).unwrap()
83 }
84
85 fn from_bytes(bytes: Cow<'_, [u8]>) -> Self {
86 bincode::deserialize(bytes.as_ref()).unwrap()
87 }
88
89 const BOUND: Bound = Bound::Unbounded;
90}