Struct ElectrumServer

Source
pub struct ElectrumServer<Blockchain: BlockchainInterface> {
    chain: Arc<Blockchain>,
    address_cache: Arc<AddressCache<KvDatabase>>,
    clients: HashMap<u32, Arc<Client>>,
    message_receiver: UnboundedReceiver<Message>,
    message_transmitter: UnboundedSender<Message>,
    client_addresses: HashMap<Hash, Arc<Client>>,
    block_filters: Option<Arc<NetworkFilters<FlatFiltersStore>>>,
    node_interface: NodeInterface,
    addresses_to_scan: Vec<ScriptBuf>,
    last_rebroadcast: Option<Instant>,
}

Fields§

§chain: Arc<Blockchain>

The blockchain backend we are using. This will be used to query blockchain information and broadcast transactions.

§address_cache: Arc<AddressCache<KvDatabase>>

The address cache is used to store addresses and transactions, like a watch-only wallet, but it is adapted to the electrum protocol.

§clients: HashMap<u32, Arc<Client>>

The clients are the clients connected to our server, we keep track of them using a unique id.

§message_receiver: UnboundedReceiver<Message>

The message_receiver receive messages and handles them.

§message_transmitter: UnboundedSender<Message>

The message_transmitter is used to send requests from clients or notifications like new or dropped clients

§client_addresses: HashMap<Hash, Arc<Client>>

The client_addresses is used to keep track of the addresses of each client. We keep the script_hash and which client has it, so we can notify the clients when a new transaction is received.

§block_filters: Option<Arc<NetworkFilters<FlatFiltersStore>>>

A Arc-ed copy of the block filters backend that we can use to check if a block contains a transaction that we are interested in.

§node_interface: NodeInterface

An interface to a running node, used to broadcast transactions and request blocks.

§addresses_to_scan: Vec<ScriptBuf>

A list of addresses that we’ve just learned about and need to rescan for transactions.

We accumulate those addresses here and then periodically scan, since a wallet will often send multiple addresses, but in different requests.

§last_rebroadcast: Option<Instant>

Last time we’ve re-broadcasted our transactions. We want to do this every hour, to make sure our transactions don’t get stuck in the mempool if they are not getting confirmed for some reason. We keep track of this time to know when to re-broadcast them.

Implementations§

Source§

impl<Blockchain: BlockchainInterface> ElectrumServer<Blockchain>

Source

pub fn new( address_cache: Arc<AddressCache<KvDatabase>>, chain: Arc<Blockchain>, block_filters: Option<Arc<NetworkFilters<FlatFiltersStore>>>, node_interface: NodeInterface, ) -> Result<ElectrumServer<Blockchain>, Box<dyn Error>>

Source

pub fn get_notifier(&self) -> UnboundedSender<Message>

Notifier to send messages to the main loop

Source

async fn handle_client_request( &mut self, client: Arc<Client>, request: Request, ) -> Result<Value, Error>

Handle a request from a client. All methods are defined in the electrum protocol.

Source

pub async fn rebroadcast_mempool_transactions(&self)

Source

pub async fn main_loop(self) -> Result<(), Error>

Source

async fn rescan_for_addresses( &mut self, addresses: Vec<ScriptBuf>, ) -> Result<(), Error>

If a user adds a new address that we didn’t have cached, this method will look for historical transactions for it.

Usually, we’ll rely on compact block filters to speed things up. If we don’t have compact block filters, we may rescan using the older, more bandwidth-intensive method of actually downloading blocks.

Source

async fn rescan_with_block_filters( &mut self, cfilters: Arc<NetworkFilters<FlatFiltersStore>>, start_height: Option<u32>, stop_height: Option<u32>, addresses: Vec<ScriptBuf>, ) -> Result<(), Error>

If we have compact block filters enabled, this method will use them to find blocks of interest and download for our wallet to learn about new transactions, once a new address is added by subscription.

Source

fn process_history(transactions: &[CachedTransaction]) -> Vec<Value>

Source

fn handle_block(&self, block: Block, height: u32)

Source

async fn handle_message(&mut self, message: Message) -> Result<(), Error>

Handles each kind of Message

Source

fn wallet_notify(&self, transactions: &[(Transaction, TxOut)])

Auto Trait Implementations§

§

impl<Blockchain> Freeze for ElectrumServer<Blockchain>

§

impl<Blockchain> RefUnwindSafe for ElectrumServer<Blockchain>
where Blockchain: RefUnwindSafe,

§

impl<Blockchain> Send for ElectrumServer<Blockchain>
where Blockchain: Sync + Send,

§

impl<Blockchain> Sync for ElectrumServer<Blockchain>
where Blockchain: Sync + Send,

§

impl<Blockchain> Unpin for ElectrumServer<Blockchain>

§

impl<Blockchain> UnwindSafe for ElectrumServer<Blockchain>
where Blockchain: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more