Skip to main content

electrum_client/
api.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Electrum APIs
4
5use std::borrow::Borrow;
6use std::convert::TryInto;
7use std::ops::Deref;
8
9use bitcoin::consensus::encode::{deserialize, serialize};
10use bitcoin::{block, Script, Transaction, Txid};
11
12use crate::batch::Batch;
13use crate::raw_client::{CLIENT_NAME, PROTOCOL_VERSION_MAX, PROTOCOL_VERSION_MIN};
14use crate::types::*;
15
16impl<E: Deref> ElectrumApi for E
17where
18    E::Target: ElectrumApi,
19{
20    fn raw_call(
21        &self,
22        method_name: &str,
23        params: impl IntoIterator<Item = Param>,
24    ) -> Result<serde_json::Value, Error> {
25        (**self).raw_call(method_name, params)
26    }
27
28    fn batch_call(&self, batch: &Batch) -> Result<Vec<serde_json::Value>, Error> {
29        (**self).batch_call(batch)
30    }
31
32    fn block_headers_subscribe_raw(&self) -> Result<RawHeaderNotification, Error> {
33        (**self).block_headers_subscribe_raw()
34    }
35
36    fn block_headers_pop_raw(&self) -> Result<Option<RawHeaderNotification>, Error> {
37        (**self).block_headers_pop_raw()
38    }
39
40    fn block_header_raw(&self, height: usize) -> Result<Vec<u8>, Error> {
41        (**self).block_header_raw(height)
42    }
43
44    fn block_headers(&self, start_height: usize, count: usize) -> Result<GetHeadersRes, Error> {
45        (**self).block_headers(start_height, count)
46    }
47
48    fn estimate_fee(&self, number: usize, mode: Option<EstimationMode>) -> Result<f64, Error> {
49        (**self).estimate_fee(number, mode)
50    }
51
52    fn relay_fee(&self) -> Result<f64, Error> {
53        (**self).relay_fee()
54    }
55
56    fn script_subscribe(&self, script: &Script) -> Result<Option<ScriptStatus>, Error> {
57        (**self).script_subscribe(script)
58    }
59
60    fn batch_script_subscribe<'s, I>(&self, scripts: I) -> Result<Vec<Option<ScriptStatus>>, Error>
61    where
62        I: IntoIterator + Clone,
63        I::Item: Borrow<&'s Script>,
64    {
65        (**self).batch_script_subscribe(scripts)
66    }
67
68    fn script_unsubscribe(&self, script: &Script) -> Result<bool, Error> {
69        (**self).script_unsubscribe(script)
70    }
71
72    fn script_pop(&self, script: &Script) -> Result<Option<ScriptStatus>, Error> {
73        (**self).script_pop(script)
74    }
75
76    fn script_get_balance(&self, script: &Script) -> Result<GetBalanceRes, Error> {
77        (**self).script_get_balance(script)
78    }
79
80    fn batch_script_get_balance<'s, I>(&self, scripts: I) -> Result<Vec<GetBalanceRes>, Error>
81    where
82        I: IntoIterator + Clone,
83        I::Item: Borrow<&'s Script>,
84    {
85        (**self).batch_script_get_balance(scripts)
86    }
87
88    fn script_get_history(&self, script: &Script) -> Result<Vec<GetHistoryRes>, Error> {
89        (**self).script_get_history(script)
90    }
91
92    fn batch_script_get_history<'s, I>(&self, scripts: I) -> Result<Vec<Vec<GetHistoryRes>>, Error>
93    where
94        I: IntoIterator + Clone,
95        I::Item: Borrow<&'s Script>,
96    {
97        (**self).batch_script_get_history(scripts)
98    }
99
100    fn script_list_unspent(&self, script: &Script) -> Result<Vec<ListUnspentRes>, Error> {
101        (**self).script_list_unspent(script)
102    }
103
104    fn batch_script_list_unspent<'s, I>(
105        &self,
106        scripts: I,
107    ) -> Result<Vec<Vec<ListUnspentRes>>, Error>
108    where
109        I: IntoIterator + Clone,
110        I::Item: Borrow<&'s Script>,
111    {
112        (**self).batch_script_list_unspent(scripts)
113    }
114
115    fn transaction_get_raw(&self, txid: &Txid) -> Result<Vec<u8>, Error> {
116        (**self).transaction_get_raw(txid)
117    }
118
119    fn batch_transaction_get_raw<'t, I>(&self, txids: I) -> Result<Vec<Vec<u8>>, Error>
120    where
121        I: IntoIterator + Clone,
122        I::Item: Borrow<&'t Txid>,
123    {
124        (**self).batch_transaction_get_raw(txids)
125    }
126
127    fn batch_block_header_raw<I>(&self, heights: I) -> Result<Vec<Vec<u8>>, Error>
128    where
129        I: IntoIterator + Clone,
130        I::Item: Borrow<u32>,
131    {
132        (**self).batch_block_header_raw(heights)
133    }
134
135    fn batch_estimate_fee<I>(&self, numbers: I) -> Result<Vec<f64>, Error>
136    where
137        I: IntoIterator + Clone,
138        I::Item: Borrow<usize>,
139    {
140        (**self).batch_estimate_fee(numbers)
141    }
142
143    fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<Txid, Error> {
144        (**self).transaction_broadcast_raw(raw_tx)
145    }
146
147    fn transaction_broadcast_package_raw<T: AsRef<[u8]>>(
148        &self,
149        raw_txs: &[T],
150    ) -> Result<BroadcastPackageRes, Error> {
151        (**self).transaction_broadcast_package_raw(raw_txs)
152    }
153
154    fn transaction_get_merkle(&self, txid: &Txid, height: usize) -> Result<GetMerkleRes, Error> {
155        (**self).transaction_get_merkle(txid, height)
156    }
157
158    fn batch_transaction_get_merkle<I>(
159        &self,
160        txids_and_heights: I,
161    ) -> Result<Vec<GetMerkleRes>, Error>
162    where
163        I: IntoIterator + Clone,
164        I::Item: Borrow<(Txid, usize)>,
165    {
166        (**self).batch_transaction_get_merkle(txids_and_heights)
167    }
168
169    fn txid_from_pos(&self, height: usize, tx_pos: usize) -> Result<Txid, Error> {
170        (**self).txid_from_pos(height, tx_pos)
171    }
172
173    fn txid_from_pos_with_merkle(
174        &self,
175        height: usize,
176        tx_pos: usize,
177    ) -> Result<TxidFromPosRes, Error> {
178        (**self).txid_from_pos_with_merkle(height, tx_pos)
179    }
180
181    fn server_features(&self) -> Result<ServerFeaturesRes, Error> {
182        (**self).server_features()
183    }
184
185    fn protocol_version(&self) -> Result<String, Error> {
186        (**self).protocol_version()
187    }
188
189    fn mempool_get_info(&self) -> Result<MempoolInfoRes, Error> {
190        (**self).mempool_get_info()
191    }
192
193    fn ping(&self) -> Result<(), Error> {
194        (**self).ping()
195    }
196
197    fn calls_made(&self) -> Result<usize, Error> {
198        (**self).calls_made()
199    }
200}
201
202/// API calls exposed by an Electrum client
203pub trait ElectrumApi {
204    /// Gets the block header for height `height`.
205    fn block_header(&self, height: usize) -> Result<block::Header, Error> {
206        Ok(deserialize(&self.block_header_raw(height)?)?)
207    }
208
209    /// Subscribes to notifications for new block headers, by sending a `blockchain.headers.subscribe` call.
210    fn block_headers_subscribe(&self) -> Result<HeaderNotification, Error> {
211        self.block_headers_subscribe_raw()?.try_into()
212    }
213
214    /// Tries to pop one queued notification for a new block header that we might have received.
215    /// Returns `None` if there are no items in the queue.
216    fn block_headers_pop(&self) -> Result<Option<HeaderNotification>, Error> {
217        self.block_headers_pop_raw()?
218            .map(|raw| raw.try_into())
219            .transpose()
220    }
221
222    /// Gets the transaction with `txid`. Returns an error if not found.
223    fn transaction_get(&self, txid: &Txid) -> Result<Transaction, Error> {
224        Ok(deserialize(&self.transaction_get_raw(txid)?)?)
225    }
226
227    /// Batch version of [`transaction_get`](#method.transaction_get).
228    ///
229    /// Takes a list of `txids` and returns a list of transactions.
230    fn batch_transaction_get<'t, I>(&self, txids: I) -> Result<Vec<Transaction>, Error>
231    where
232        I: IntoIterator + Clone,
233        I::Item: Borrow<&'t Txid>,
234    {
235        self.batch_transaction_get_raw(txids)?
236            .iter()
237            .map(|s| Ok(deserialize(s)?))
238            .collect()
239    }
240
241    /// Batch version of [`block_header`](#method.block_header).
242    ///
243    /// Takes a list of `heights` of blocks and returns a list of headers.
244    fn batch_block_header<I>(&self, heights: I) -> Result<Vec<block::Header>, Error>
245    where
246        I: IntoIterator + Clone,
247        I::Item: Borrow<u32>,
248    {
249        self.batch_block_header_raw(heights)?
250            .iter()
251            .map(|s| Ok(deserialize(s)?))
252            .collect()
253    }
254
255    /// Broadcasts a transaction to the network.
256    fn transaction_broadcast(&self, tx: &Transaction) -> Result<Txid, Error> {
257        let buffer: Vec<u8> = serialize(tx);
258        self.transaction_broadcast_raw(&buffer)
259    }
260
261    /// Broadcasts a package of transactions to the network.
262    ///
263    /// The package must consist of a child with its parents, where none of the parents
264    /// depend on one another. The package must be topologically sorted, with the child
265    /// being the last element in the array.
266    ///
267    /// This method was added in protocol v1.6 for package relay support.
268    fn transaction_broadcast_package(
269        &self,
270        txs: &[Transaction],
271    ) -> Result<BroadcastPackageRes, Error> {
272        let raw_txs: Vec<Vec<u8>> = txs.iter().map(serialize).collect();
273        self.transaction_broadcast_package_raw(&raw_txs)
274    }
275
276    /// Executes the requested API call returning the raw answer.
277    fn raw_call(
278        &self,
279        method_name: &str,
280        params: impl IntoIterator<Item = Param>,
281    ) -> Result<serde_json::Value, Error>;
282
283    /// Execute a queue of calls stored in a [`Batch`](../batch/struct.Batch.html) struct. Returns
284    /// `Ok()` **only if** all of the calls are successful. The order of the JSON `Value`s returned
285    /// reflects the order in which the calls were made on the `Batch` struct.
286    fn batch_call(&self, batch: &Batch) -> Result<Vec<serde_json::Value>, Error>;
287
288    /// Subscribes to notifications for new block headers, by sending a `blockchain.headers.subscribe` call and
289    /// returns the current tip as raw bytes instead of deserializing them.
290    fn block_headers_subscribe_raw(&self) -> Result<RawHeaderNotification, Error>;
291
292    /// Tries to pop one queued notification for a new block header that we might have received.
293    /// Returns a the header in raw bytes if a notification is found in the queue, None otherwise.
294    fn block_headers_pop_raw(&self) -> Result<Option<RawHeaderNotification>, Error>;
295
296    /// Gets the raw bytes of block header for height `height`.
297    fn block_header_raw(&self, height: usize) -> Result<Vec<u8>, Error>;
298
299    /// Tries to fetch `count` block headers starting from `start_height`.
300    fn block_headers(&self, start_height: usize, count: usize) -> Result<GetHeadersRes, Error>;
301
302    /// Estimates the fee required in **Bitcoin per kilobyte** to confirm a transaction in `number` blocks.
303    ///
304    /// Optionally takes an [`EstimationMode`] parameter to specify the fee estimation mode.
305    /// This parameter was added in protocol v1.6.
306    fn estimate_fee(&self, number: usize, mode: Option<EstimationMode>) -> Result<f64, Error>;
307
308    /// Returns the minimum accepted fee by the server's node in **Bitcoin, not Satoshi**.
309    ///
310    /// **Note:** This method was removed in protocol v1.6+. Use
311    /// [`mempool_get_info`](#method.mempool_get_info) instead, which provides `minrelaytxfee`
312    /// along with additional mempool fee information.
313    fn relay_fee(&self) -> Result<f64, Error>;
314
315    /// Subscribes to notifications for activity on a specific *scriptPubKey*.
316    ///
317    /// Returns a [`ScriptStatus`](../types/type.ScriptStatus.html) when successful that represents
318    /// the current status for the requested script.
319    ///
320    /// Returns [`Error::AlreadySubscribed`](../types/enum.Error.html#variant.AlreadySubscribed) if
321    /// already subscribed to the script.
322    fn script_subscribe(&self, script: &Script) -> Result<Option<ScriptStatus>, Error>;
323
324    /// Batch version of [`script_subscribe`](#method.script_subscribe).
325    ///
326    /// Takes a list of scripts and returns a list of script status responses.
327    ///
328    /// Note you should pass a reference to a collection because otherwise an expensive clone is made
329    fn batch_script_subscribe<'s, I>(&self, scripts: I) -> Result<Vec<Option<ScriptStatus>>, Error>
330    where
331        I: IntoIterator + Clone,
332        I::Item: Borrow<&'s Script>;
333
334    /// Subscribes to notifications for activity on a specific *scriptPubKey*.
335    ///
336    /// Returns a `bool` with the server response when successful.
337    ///
338    /// Returns [`Error::NotSubscribed`](../types/enum.Error.html#variant.NotSubscribed) if
339    /// not subscribed to the script.
340    fn script_unsubscribe(&self, script: &Script) -> Result<bool, Error>;
341
342    /// Tries to pop one queued notification for a the requested script. Returns `None` if there are no items in the queue.
343    fn script_pop(&self, script: &Script) -> Result<Option<ScriptStatus>, Error>;
344
345    /// Returns the balance for a *scriptPubKey*.
346    fn script_get_balance(&self, script: &Script) -> Result<GetBalanceRes, Error>;
347
348    /// Batch version of [`script_get_balance`](#method.script_get_balance).
349    ///
350    /// Takes a list of scripts and returns a list of balance responses.
351    fn batch_script_get_balance<'s, I>(&self, scripts: I) -> Result<Vec<GetBalanceRes>, Error>
352    where
353        I: IntoIterator + Clone,
354        I::Item: Borrow<&'s Script>;
355
356    /// Returns the history for a *scriptPubKey*
357    fn script_get_history(&self, script: &Script) -> Result<Vec<GetHistoryRes>, Error>;
358
359    /// Batch version of [`script_get_history`](#method.script_get_history).
360    ///
361    /// Takes a list of scripts and returns a list of history responses.
362    fn batch_script_get_history<'s, I>(&self, scripts: I) -> Result<Vec<Vec<GetHistoryRes>>, Error>
363    where
364        I: IntoIterator + Clone,
365        I::Item: Borrow<&'s Script>;
366
367    /// Returns the list of unspent outputs for a *scriptPubKey*
368    fn script_list_unspent(&self, script: &Script) -> Result<Vec<ListUnspentRes>, Error>;
369
370    /// Batch version of [`script_list_unspent`](#method.script_list_unspent).
371    ///
372    /// Takes a list of scripts and returns a list of a list of utxos.
373    fn batch_script_list_unspent<'s, I>(
374        &self,
375        scripts: I,
376    ) -> Result<Vec<Vec<ListUnspentRes>>, Error>
377    where
378        I: IntoIterator + Clone,
379        I::Item: Borrow<&'s Script>;
380
381    /// Gets the raw bytes of a transaction with `txid`. Returns an error if not found.
382    fn transaction_get_raw(&self, txid: &Txid) -> Result<Vec<u8>, Error>;
383
384    /// Batch version of [`transaction_get_raw`](#method.transaction_get_raw).
385    ///
386    /// Takes a list of `txids` and returns a list of transactions raw bytes.
387    fn batch_transaction_get_raw<'t, I>(&self, txids: I) -> Result<Vec<Vec<u8>>, Error>
388    where
389        I: IntoIterator + Clone,
390        I::Item: Borrow<&'t Txid>;
391
392    /// Batch version of [`block_header_raw`](#method.block_header_raw).
393    ///
394    /// Takes a list of `heights` of blocks and returns a list of block header raw bytes.
395    fn batch_block_header_raw<I>(&self, heights: I) -> Result<Vec<Vec<u8>>, Error>
396    where
397        I: IntoIterator + Clone,
398        I::Item: Borrow<u32>;
399
400    /// Batch version of [`estimate_fee`](#method.estimate_fee).
401    ///
402    /// Takes a list of `numbers` of blocks and returns a list of fee required in
403    /// **Satoshis per kilobyte** to confirm a transaction in the given number of blocks.
404    fn batch_estimate_fee<I>(&self, numbers: I) -> Result<Vec<f64>, Error>
405    where
406        I: IntoIterator + Clone,
407        I::Item: Borrow<usize>;
408
409    /// Broadcasts the raw bytes of a transaction to the network.
410    fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<Txid, Error>;
411
412    /// Broadcasts a package of raw transactions to the network.
413    ///
414    /// The package must consist of a child with its parents, where none of the parents
415    /// depend on one another. The package must be topologically sorted, with the child
416    /// being the last element in the array.
417    ///
418    /// This method was added in protocol v1.6 for package relay support.
419    fn transaction_broadcast_package_raw<T: AsRef<[u8]>>(
420        &self,
421        raw_txs: &[T],
422    ) -> Result<BroadcastPackageRes, Error>;
423
424    /// Returns the merkle path for the transaction `txid` confirmed in the block at `height`.
425    fn transaction_get_merkle(&self, txid: &Txid, height: usize) -> Result<GetMerkleRes, Error>;
426
427    /// Batch version of [`transaction_get_merkle`](#method.transaction_get_merkle).
428    ///
429    /// Take a list of `(txid, height)`, for transactions with `txid` confirmed in the block at `height`.
430    fn batch_transaction_get_merkle<I>(
431        &self,
432        txids_and_heights: I,
433    ) -> Result<Vec<GetMerkleRes>, Error>
434    where
435        I: IntoIterator + Clone,
436        I::Item: Borrow<(Txid, usize)>;
437
438    /// Returns a transaction hash, given a block `height` and a `tx_pos` in the block.
439    fn txid_from_pos(&self, height: usize, tx_pos: usize) -> Result<Txid, Error>;
440
441    /// Returns a transaction hash and a merkle path, given a block `height` and a `tx_pos` in the
442    /// block.
443    fn txid_from_pos_with_merkle(
444        &self,
445        height: usize,
446        tx_pos: usize,
447    ) -> Result<TxidFromPosRes, Error>;
448
449    /// Returns the capabilities of the server.
450    fn server_features(&self) -> Result<ServerFeaturesRes, Error>;
451
452    /// Returns the negotiated Electrum protocol version.
453    ///
454    /// Clients that already negotiated a protocol version during connection setup
455    /// should return that cached value. Implementors that do not cache it can use
456    /// this default implementation, which retrieves the version with
457    /// `server.version`.
458    fn protocol_version(&self) -> Result<String, Error> {
459        let version_range = vec![
460            PROTOCOL_VERSION_MIN.to_string(),
461            PROTOCOL_VERSION_MAX.to_string(),
462        ];
463        let result = self.raw_call(
464            "server.version",
465            vec![
466                Param::String(CLIENT_NAME.to_string()),
467                Param::StringVec(version_range),
468            ],
469        )?;
470        let response: ServerVersionRes = serde_json::from_value(result)?;
471
472        Ok(response.protocol_version)
473    }
474
475    /// Returns information about the current state of the mempool.
476    ///
477    /// This method was added in protocol v1.6 and replaces `relay_fee` by providing
478    /// `minrelaytxfee` along with additional mempool fee information.
479    fn mempool_get_info(&self) -> Result<MempoolInfoRes, Error>;
480
481    /// Pings the server. This method can also be used as a "dummy" call to trigger the processing
482    /// of incoming block header or script notifications.
483    fn ping(&self) -> Result<(), Error>;
484
485    /// Returns the number of network calls made since the creation of the client.
486    fn calls_made(&self) -> Result<usize, Error>;
487}
488
489#[cfg(test)]
490mod test {
491    use std::{borrow::Cow, sync::Arc};
492
493    use super::ElectrumApi;
494
495    #[derive(Debug, Clone)]
496    struct FakeApi;
497
498    impl ElectrumApi for FakeApi {
499        fn raw_call(
500            &self,
501            _: &str,
502            _: impl IntoIterator<Item = super::Param>,
503        ) -> Result<serde_json::Value, super::Error> {
504            unreachable!()
505        }
506
507        fn batch_call(&self, _: &crate::Batch) -> Result<Vec<serde_json::Value>, super::Error> {
508            unreachable!()
509        }
510
511        fn block_headers_subscribe_raw(
512            &self,
513        ) -> Result<super::RawHeaderNotification, super::Error> {
514            unreachable!()
515        }
516
517        fn block_headers_pop_raw(
518            &self,
519        ) -> Result<Option<super::RawHeaderNotification>, super::Error> {
520            unreachable!()
521        }
522
523        fn block_header_raw(&self, _: usize) -> Result<Vec<u8>, super::Error> {
524            unreachable!()
525        }
526
527        fn block_headers(&self, _: usize, _: usize) -> Result<super::GetHeadersRes, super::Error> {
528            unreachable!()
529        }
530
531        fn estimate_fee(
532            &self,
533            _: usize,
534            _: Option<super::EstimationMode>,
535        ) -> Result<f64, super::Error> {
536            unreachable!()
537        }
538
539        fn relay_fee(&self) -> Result<f64, super::Error> {
540            unreachable!()
541        }
542
543        fn script_subscribe(
544            &self,
545            _: &bitcoin::Script,
546        ) -> Result<Option<super::ScriptStatus>, super::Error> {
547            unreachable!()
548        }
549
550        fn batch_script_subscribe<'s, I>(
551            &self,
552            _: I,
553        ) -> Result<Vec<Option<super::ScriptStatus>>, super::Error>
554        where
555            I: IntoIterator + Clone,
556            I::Item: std::borrow::Borrow<&'s bitcoin::Script>,
557        {
558            unreachable!()
559        }
560
561        fn script_unsubscribe(&self, _: &bitcoin::Script) -> Result<bool, super::Error> {
562            unreachable!()
563        }
564
565        fn script_pop(
566            &self,
567            _: &bitcoin::Script,
568        ) -> Result<Option<super::ScriptStatus>, super::Error> {
569            unreachable!()
570        }
571
572        fn script_get_balance(
573            &self,
574            _: &bitcoin::Script,
575        ) -> Result<super::GetBalanceRes, super::Error> {
576            unreachable!()
577        }
578
579        fn batch_script_get_balance<'s, I>(
580            &self,
581            _: I,
582        ) -> Result<Vec<super::GetBalanceRes>, super::Error>
583        where
584            I: IntoIterator + Clone,
585            I::Item: std::borrow::Borrow<&'s bitcoin::Script>,
586        {
587            unreachable!()
588        }
589
590        fn script_get_history(
591            &self,
592            _: &bitcoin::Script,
593        ) -> Result<Vec<super::GetHistoryRes>, super::Error> {
594            unreachable!()
595        }
596
597        fn batch_script_get_history<'s, I>(
598            &self,
599            _: I,
600        ) -> Result<Vec<Vec<super::GetHistoryRes>>, super::Error>
601        where
602            I: IntoIterator + Clone,
603            I::Item: std::borrow::Borrow<&'s bitcoin::Script>,
604        {
605            unreachable!()
606        }
607
608        fn script_list_unspent(
609            &self,
610            _: &bitcoin::Script,
611        ) -> Result<Vec<super::ListUnspentRes>, super::Error> {
612            unreachable!()
613        }
614
615        fn batch_script_list_unspent<'s, I>(
616            &self,
617            _: I,
618        ) -> Result<Vec<Vec<super::ListUnspentRes>>, super::Error>
619        where
620            I: IntoIterator + Clone,
621            I::Item: std::borrow::Borrow<&'s bitcoin::Script>,
622        {
623            unreachable!()
624        }
625
626        fn transaction_get_raw(&self, _: &bitcoin::Txid) -> Result<Vec<u8>, super::Error> {
627            unreachable!()
628        }
629
630        fn batch_transaction_get_raw<'t, I>(&self, _: I) -> Result<Vec<Vec<u8>>, super::Error>
631        where
632            I: IntoIterator + Clone,
633            I::Item: std::borrow::Borrow<&'t bitcoin::Txid>,
634        {
635            unreachable!()
636        }
637
638        fn batch_block_header_raw<I>(&self, _: I) -> Result<Vec<Vec<u8>>, super::Error>
639        where
640            I: IntoIterator + Clone,
641            I::Item: std::borrow::Borrow<u32>,
642        {
643            unreachable!()
644        }
645
646        fn batch_estimate_fee<I>(&self, _: I) -> Result<Vec<f64>, super::Error>
647        where
648            I: IntoIterator + Clone,
649            I::Item: std::borrow::Borrow<usize>,
650        {
651            unreachable!()
652        }
653
654        fn transaction_broadcast_raw(&self, _: &[u8]) -> Result<bitcoin::Txid, super::Error> {
655            unreachable!()
656        }
657
658        fn transaction_broadcast_package_raw<T: AsRef<[u8]>>(
659            &self,
660            _: &[T],
661        ) -> Result<super::BroadcastPackageRes, super::Error> {
662            unreachable!()
663        }
664
665        fn transaction_get_merkle(
666            &self,
667            _: &bitcoin::Txid,
668            _: usize,
669        ) -> Result<super::GetMerkleRes, super::Error> {
670            unreachable!()
671        }
672
673        fn batch_transaction_get_merkle<I>(
674            &self,
675            _: I,
676        ) -> Result<Vec<crate::GetMerkleRes>, crate::Error>
677        where
678            I: IntoIterator + Clone,
679            I::Item: std::borrow::Borrow<(bitcoin::Txid, usize)>,
680        {
681            unreachable!()
682        }
683
684        fn txid_from_pos(&self, _: usize, _: usize) -> Result<bitcoin::Txid, super::Error> {
685            unreachable!()
686        }
687
688        fn txid_from_pos_with_merkle(
689            &self,
690            _: usize,
691            _: usize,
692        ) -> Result<super::TxidFromPosRes, super::Error> {
693            unreachable!()
694        }
695
696        fn server_features(&self) -> Result<super::ServerFeaturesRes, super::Error> {
697            unreachable!()
698        }
699
700        fn mempool_get_info(&self) -> Result<super::MempoolInfoRes, super::Error> {
701            unreachable!()
702        }
703
704        fn ping(&self) -> Result<(), super::Error> {
705            unreachable!()
706        }
707
708        fn calls_made(&self) -> Result<usize, super::Error> {
709            unreachable!()
710        }
711    }
712
713    fn is_impl<A: ElectrumApi>() {}
714
715    #[test]
716    fn deref() {
717        is_impl::<FakeApi>();
718        is_impl::<&FakeApi>();
719        is_impl::<Arc<FakeApi>>();
720        is_impl::<Box<FakeApi>>();
721        is_impl::<Cow<FakeApi>>();
722    }
723}