bpwallet/indexers/
mod.rs

1// Modern, minimalistic & standard-compliant cold wallet library.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Written in 2020-2024 by
6//     Dr Maxim Orlovsky <orlovsky@lnp-bp.org>
7//
8// Copyright (C) 2020-2024 LNP/BP Standards Association. All rights reserved.
9// Copyright (C) 2020-2024 Dr Maxim Orlovsky. All rights reserved.
10//
11// Licensed under the Apache License, Version 2.0 (the "License");
12// you may not use this file except in compliance with the License.
13// You may obtain a copy of the License at
14//
15//     http://www.apache.org/licenses/LICENSE-2.0
16//
17// Unless required by applicable law or agreed to in writing, software
18// distributed under the License is distributed on an "AS IS" BASIS,
19// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20// See the License for the specific language governing permissions and
21// limitations under the License.
22
23#[cfg(feature = "electrum")]
24pub mod electrum;
25#[cfg(feature = "esplora")]
26pub mod esplora;
27#[cfg(feature = "mempool")]
28pub mod mempool;
29#[cfg(any(feature = "electrum", feature = "esplora", feature = "mempool"))]
30mod any;
31
32#[cfg(any(feature = "electrum", feature = "esplora", feature = "mempool"))]
33pub use any::{AnyIndexer, AnyIndexerError};
34use bpstd::{Network, Tx};
35use descriptors::Descriptor;
36
37use crate::{Layer2, MayError, TxStatus, Txid, WalletCache, WalletDescr};
38
39#[cfg(any(feature = "electrum", feature = "esplora"))]
40const BATCH_SIZE: usize = 10;
41
42pub trait Indexer {
43    type Error;
44
45    fn network(&self) -> Result<Network, Self::Error>;
46
47    fn create<K, D: Descriptor<K>, L2: Layer2>(
48        &self,
49        descr: &WalletDescr<K, D, L2::Descr>,
50    ) -> MayError<WalletCache<L2::Cache>, Vec<Self::Error>>;
51
52    fn update<K, D: Descriptor<K>, L2: Layer2>(
53        &self,
54        descr: &WalletDescr<K, D, L2::Descr>,
55        cache: &mut WalletCache<L2::Cache>,
56    ) -> MayError<usize, Vec<Self::Error>>;
57
58    fn broadcast(&self, tx: &Tx) -> Result<(), Self::Error>;
59
60    fn status(&self, txid: Txid) -> Result<TxStatus, Self::Error>;
61}