[examples_redesign] Introduce example_cli package
This is the equivalent of `keychain_tracker_example_cli` that works with the redesigned structures.
This commit is contained in:
@@ -16,6 +16,13 @@ pub enum ObservedAs<A> {
|
||||
Unconfirmed(u64),
|
||||
}
|
||||
|
||||
impl<A> ObservedAs<A> {
|
||||
/// Returns whether [`ObservedAs`] is confirmed or not.
|
||||
pub fn is_confirmed(&self) -> bool {
|
||||
matches!(self, Self::Confirmed(_))
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Clone> ObservedAs<&A> {
|
||||
pub fn cloned(self) -> ObservedAs<A> {
|
||||
match self {
|
||||
|
||||
@@ -19,4 +19,7 @@ pub trait ChainOracle {
|
||||
block: BlockId,
|
||||
chain_tip: BlockId,
|
||||
) -> Result<Option<bool>, Self::Error>;
|
||||
|
||||
/// Get the best chain's chain tip.
|
||||
fn get_chain_tip(&self) -> Result<Option<BlockId>, Self::Error>;
|
||||
}
|
||||
|
||||
@@ -203,6 +203,15 @@ impl<A: Anchor, IA: Append> Append for IndexedAdditions<A, IA> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, IA: Default> From<Additions<A>> for IndexedAdditions<A, IA> {
|
||||
fn from(graph_additions: Additions<A>) -> Self {
|
||||
Self {
|
||||
graph_additions,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a structure that can index transaction data.
|
||||
pub trait Indexer {
|
||||
/// The resultant "additions" when new transaction data is indexed.
|
||||
|
||||
@@ -34,6 +34,10 @@ impl ChainOracle for LocalChain {
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn get_chain_tip(&self) -> Result<Option<BlockId>, Self::Error> {
|
||||
Ok(self.tip())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<BTreeMap<u32, BlockHash>> for LocalChain {
|
||||
|
||||
@@ -130,7 +130,7 @@ impl ElectrumExt for Client {
|
||||
let mut scanned_spk_iter = scanned_spks
|
||||
.iter()
|
||||
.map(|(i, (spk, _))| (i.clone(), spk.clone()));
|
||||
match populate_with_spks::<K, _, _>(
|
||||
match populate_with_spks::<_, _>(
|
||||
self,
|
||||
&mut update,
|
||||
&mut scanned_spk_iter,
|
||||
@@ -143,7 +143,7 @@ impl ElectrumExt for Client {
|
||||
};
|
||||
}
|
||||
for (keychain, keychain_spks) in &mut request_spks {
|
||||
match populate_with_spks::<K, u32, _>(
|
||||
match populate_with_spks::<u32, _>(
|
||||
self,
|
||||
&mut update,
|
||||
keychain_spks,
|
||||
@@ -529,7 +529,7 @@ fn populate_with_txids(
|
||||
|
||||
/// Populate an update [`SparseChain`] with transactions (and associated block positions) from
|
||||
/// the transaction history of the provided `spk`s.
|
||||
fn populate_with_spks<K, I, S>(
|
||||
fn populate_with_spks<I, S>(
|
||||
client: &Client,
|
||||
update: &mut SparseChain,
|
||||
spks: &mut S,
|
||||
@@ -537,7 +537,6 @@ fn populate_with_spks<K, I, S>(
|
||||
batch_size: usize,
|
||||
) -> Result<BTreeMap<I, (Script, bool)>, InternalError>
|
||||
where
|
||||
K: Ord + Clone,
|
||||
I: Ord + Clone,
|
||||
S: Iterator<Item = (I, Script)>,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user