From 895c6b0808b91665c54c29519d569d589776b81a Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Mon, 17 Aug 2020 10:53:38 +0200 Subject: [PATCH] [blockchain] impl OnlineBlockchain for types wrapped in Arc --- src/blockchain/mod.rs | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/blockchain/mod.rs b/src/blockchain/mod.rs index a38f38b5..6a602bfd 100644 --- a/src/blockchain/mod.rs +++ b/src/blockchain/mod.rs @@ -1,5 +1,7 @@ use std::collections::HashSet; +use std::ops::Deref; use std::sync::mpsc::{channel, Receiver, Sender}; +use std::sync::Arc; use bitcoin::{Transaction, Txid}; @@ -120,3 +122,52 @@ impl Progress for LogProgress { Ok(()) } } + +impl Blockchain for Arc { + fn is_online(&self) -> bool { + self.deref().is_online() + } + + fn offline() -> Self { + Arc::new(T::offline()) + } +} + +#[maybe_async] +impl OnlineBlockchain for Arc { + fn get_capabilities(&self) -> HashSet { + maybe_await!(self.deref().get_capabilities()) + } + + fn setup( + &self, + stop_gap: Option, + database: &mut D, + progress_update: P, + ) -> Result<(), Error> { + maybe_await!(self.deref().setup(stop_gap, database, progress_update)) + } + + fn sync( + &self, + stop_gap: Option, + database: &mut D, + progress_update: P, + ) -> Result<(), Error> { + maybe_await!(self.deref().sync(stop_gap, database, progress_update)) + } + + fn get_tx(&self, txid: &Txid) -> Result, Error> { + maybe_await!(self.deref().get_tx(txid)) + } + fn broadcast(&self, tx: &Transaction) -> Result<(), Error> { + maybe_await!(self.deref().broadcast(tx)) + } + + fn get_height(&self) -> Result { + maybe_await!(self.deref().get_height()) + } + fn estimate_fee(&self, target: usize) -> Result { + maybe_await!(self.deref().estimate_fee(target)) + } +}