Skip to main content

bitcoind_client/
types.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4use bitcoin::bip158;
5use corepc_types::bitcoin;
6use corepc_types::v19::GetBlockFilterError;
7use serde::{Deserialize, Serialize};
8
9/// Response to `getblockfilter`.
10#[derive(Debug, Clone, PartialEq, Deserialize)]
11pub(crate) struct GetBlockFilterResponse {
12    /// `bip158` block filter (hex).
13    pub filter: String,
14    /// `bip158` filter header.
15    pub header: bip158::FilterHeader,
16}
17
18impl GetBlockFilterResponse {
19    /// Into model.
20    pub fn into_model(self) -> Result<GetBlockFilter, GetBlockFilterError> {
21        use bitcoin::hex::FromHex;
22        let GetBlockFilterResponse { filter, header } = self;
23        let data = <Vec<u8> as FromHex>::from_hex(&filter).map_err(GetBlockFilterError::Filter)?;
24        let filter = bip158::BlockFilter::new(&data);
25
26        Ok(GetBlockFilter { filter, header })
27    }
28}
29
30/// Response to `getblockfilter`.
31#[derive(Debug, Clone, PartialEq)]
32pub struct GetBlockFilter {
33    /// `bip158` block filter.
34    pub filter: bip158::BlockFilter,
35    /// `bip158` filter header.
36    pub header: bip158::FilterHeader,
37}
38
39/// Request of `importdescriptors`.
40#[derive(Debug, Clone, Serialize, Default)]
41pub struct ImportDescriptorsRequest {
42    /// (required) Descriptor to import.
43    pub desc: String,
44    /// Set this descriptor to be the active descriptor for the corresponding output type.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub active: Option<bool>,
47    /// If a ranged descriptor is used, this specifies the range (in the form \[begin,end\]) to import.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub range: Option<(usize, usize)>,
50    /// The next index from which to generate addresses.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub next_index: Option<usize>,
53    /// (required) Time from which to start rescanning the blockchain for this descriptor, in UNIX epoch time.
54    // Use the string "now" to substitute the current synced blockchain time.
55    pub timestamp: u64,
56    /// Whether matching outputs should be treated as not incoming payments (e.g. change).
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub internal: Option<bool>,
59    /// Label to assign to the address, only allowed with `internal = false`. Disabled for ranged descriptors.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub label: Option<String>,
62}
63
64/// Response of `importdescriptors`.
65#[derive(Debug, Clone, Deserialize)]
66pub struct ImportDescriptorsResponse {
67    /// Whether the import was successful.
68    pub success: bool,
69    /// Warnings.
70    #[serde(default)]
71    pub warnings: Option<Vec<String>>,
72    /// Error.
73    pub error: Option<ImportDescriptorsError>,
74}
75
76/// Error for `importdescriptors`.
77#[derive(Debug, Clone, Deserialize)]
78pub struct ImportDescriptorsError {
79    /// error code.
80    pub code: i32,
81    /// error message.
82    pub message: String,
83}