Rename fields of tx_graph::Additions
* Changed `tx` to `txs` * Changed `txout` to `txouts`
This commit is contained in:
parent
1c3cbefa4d
commit
ac80829caa
@ -51,10 +51,10 @@ impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I> {
|
||||
|
||||
self.index.apply_additions(index_additions);
|
||||
|
||||
for tx in &graph_additions.tx {
|
||||
for tx in &graph_additions.txs {
|
||||
self.index.index_tx(tx);
|
||||
}
|
||||
for (&outpoint, txout) in &graph_additions.txout {
|
||||
for (&outpoint, txout) in &graph_additions.txouts {
|
||||
self.index.index_txout(outpoint, txout);
|
||||
}
|
||||
|
||||
@ -73,10 +73,10 @@ where
|
||||
let graph_additions = self.graph.apply_update(update);
|
||||
|
||||
let mut index_additions = I::Additions::default();
|
||||
for added_tx in &graph_additions.tx {
|
||||
for added_tx in &graph_additions.txs {
|
||||
index_additions.append(self.index.index_tx(added_tx));
|
||||
}
|
||||
for (&added_outpoint, added_txout) in &graph_additions.txout {
|
||||
for (&added_outpoint, added_txout) in &graph_additions.txouts {
|
||||
index_additions.append(self.index.index_txout(added_outpoint, added_txout));
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
|
||||
/// Applies [`Additions`] to [`TxGraph`].
|
||||
pub fn apply_additions(&mut self, additions: Additions<A>) {
|
||||
for tx in additions.tx {
|
||||
for tx in additions.txs {
|
||||
let txid = tx.txid();
|
||||
|
||||
tx.input
|
||||
@ -513,7 +513,7 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
}
|
||||
}
|
||||
|
||||
for (outpoint, txout) in additions.txout {
|
||||
for (outpoint, txout) in additions.txouts {
|
||||
let tx_entry = self
|
||||
.txs
|
||||
.entry(outpoint.txid)
|
||||
@ -553,11 +553,11 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
for (&txid, (update_tx_node, _, update_last_seen)) in &update.txs {
|
||||
let prev_last_seen: u64 = match (self.txs.get(&txid), update_tx_node) {
|
||||
(None, TxNodeInternal::Whole(update_tx)) => {
|
||||
additions.tx.insert(update_tx.clone());
|
||||
additions.txs.insert(update_tx.clone());
|
||||
0
|
||||
}
|
||||
(None, TxNodeInternal::Partial(update_txos)) => {
|
||||
additions.txout.extend(
|
||||
additions.txouts.extend(
|
||||
update_txos
|
||||
.iter()
|
||||
.map(|(&vout, txo)| (OutPoint::new(txid, vout), txo.clone())),
|
||||
@ -569,14 +569,14 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
Some((TxNodeInternal::Partial(_), _, last_seen)),
|
||||
TxNodeInternal::Whole(update_tx),
|
||||
) => {
|
||||
additions.tx.insert(update_tx.clone());
|
||||
additions.txs.insert(update_tx.clone());
|
||||
*last_seen
|
||||
}
|
||||
(
|
||||
Some((TxNodeInternal::Partial(txos), _, last_seen)),
|
||||
TxNodeInternal::Partial(update_txos),
|
||||
) => {
|
||||
additions.txout.extend(
|
||||
additions.txouts.extend(
|
||||
update_txos
|
||||
.iter()
|
||||
.filter(|(vout, _)| !txos.contains_key(*vout))
|
||||
@ -983,8 +983,8 @@ impl<A: Anchor> TxGraph<A> {
|
||||
)]
|
||||
#[must_use]
|
||||
pub struct Additions<A = ()> {
|
||||
pub tx: BTreeSet<Transaction>,
|
||||
pub txout: BTreeMap<OutPoint, TxOut>,
|
||||
pub txs: BTreeSet<Transaction>,
|
||||
pub txouts: BTreeMap<OutPoint, TxOut>,
|
||||
pub anchors: BTreeSet<(A, Txid)>,
|
||||
pub last_seen: BTreeMap<Txid, u64>,
|
||||
}
|
||||
@ -992,8 +992,8 @@ pub struct Additions<A = ()> {
|
||||
impl<A> Default for Additions<A> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tx: Default::default(),
|
||||
txout: Default::default(),
|
||||
txs: Default::default(),
|
||||
txouts: Default::default(),
|
||||
anchors: Default::default(),
|
||||
last_seen: Default::default(),
|
||||
}
|
||||
@ -1003,12 +1003,12 @@ impl<A> Default for Additions<A> {
|
||||
impl<A> Additions<A> {
|
||||
/// Returns true if the [`Additions`] is empty (no transactions or txouts).
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.tx.is_empty() && self.txout.is_empty()
|
||||
self.txs.is_empty() && self.txouts.is_empty()
|
||||
}
|
||||
|
||||
/// Iterates over all outpoints contained within [`Additions`].
|
||||
pub fn txouts(&self) -> impl Iterator<Item = (OutPoint, &TxOut)> {
|
||||
self.tx
|
||||
self.txs
|
||||
.iter()
|
||||
.flat_map(|tx| {
|
||||
tx.output
|
||||
@ -1016,14 +1016,14 @@ impl<A> Additions<A> {
|
||||
.enumerate()
|
||||
.map(move |(vout, txout)| (OutPoint::new(tx.txid(), vout as _), txout))
|
||||
})
|
||||
.chain(self.txout.iter().map(|(op, txout)| (*op, txout)))
|
||||
.chain(self.txouts.iter().map(|(op, txout)| (*op, txout)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Ord> Append for Additions<A> {
|
||||
fn append(&mut self, mut other: Self) {
|
||||
self.tx.append(&mut other.tx);
|
||||
self.txout.append(&mut other.txout);
|
||||
self.txs.append(&mut other.txs);
|
||||
self.txouts.append(&mut other.txouts);
|
||||
self.anchors.append(&mut other.anchors);
|
||||
|
||||
// last_seen timestamps should only increase
|
||||
@ -1037,8 +1037,8 @@ impl<A: Ord> Append for Additions<A> {
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.tx.is_empty()
|
||||
&& self.txout.is_empty()
|
||||
self.txs.is_empty()
|
||||
&& self.txouts.is_empty()
|
||||
&& self.anchors.is_empty()
|
||||
&& self.last_seen.is_empty()
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ fn insert_relevant_txs() {
|
||||
graph.insert_relevant_txs(txs.iter().map(|tx| (tx, None)), None),
|
||||
IndexedAdditions {
|
||||
graph_additions: Additions {
|
||||
tx: txs.into(),
|
||||
txs: txs.into(),
|
||||
..Default::default()
|
||||
},
|
||||
index_additions: DerivationAdditions([((), 9_u32)].into()),
|
||||
|
@ -71,7 +71,7 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
graph.insert_txout(*outpoint, txout.clone()),
|
||||
Additions {
|
||||
txout: [(*outpoint, txout.clone())].into(),
|
||||
txouts: [(*outpoint, txout.clone())].into(),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@ -87,7 +87,7 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
graph.insert_txout(*outpoint, txout.clone()),
|
||||
Additions {
|
||||
txout: [(*outpoint, txout.clone())].into(),
|
||||
txouts: [(*outpoint, txout.clone())].into(),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@ -95,8 +95,8 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
graph.insert_anchor(outpoint.txid, unconf_anchor),
|
||||
Additions {
|
||||
tx: [].into(),
|
||||
txout: [].into(),
|
||||
txs: [].into(),
|
||||
txouts: [].into(),
|
||||
anchors: [(unconf_anchor, outpoint.txid)].into(),
|
||||
last_seen: [].into()
|
||||
}
|
||||
@ -105,8 +105,8 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
graph.insert_seen_at(outpoint.txid, 1000000),
|
||||
Additions {
|
||||
tx: [].into(),
|
||||
txout: [].into(),
|
||||
txs: [].into(),
|
||||
txouts: [].into(),
|
||||
anchors: [].into(),
|
||||
last_seen: [(outpoint.txid, 1000000)].into()
|
||||
}
|
||||
@ -116,7 +116,7 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
graph.insert_tx(update_txs.clone()),
|
||||
Additions {
|
||||
tx: [update_txs.clone()].into(),
|
||||
txs: [update_txs.clone()].into(),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@ -125,8 +125,8 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
graph.insert_anchor(update_txs.txid(), conf_anchor),
|
||||
Additions {
|
||||
tx: [].into(),
|
||||
txout: [].into(),
|
||||
txs: [].into(),
|
||||
txouts: [].into(),
|
||||
anchors: [(conf_anchor, update_txs.txid())].into(),
|
||||
last_seen: [].into()
|
||||
}
|
||||
@ -140,8 +140,8 @@ fn insert_txouts() {
|
||||
assert_eq!(
|
||||
additions,
|
||||
Additions {
|
||||
tx: [update_txs.clone()].into(),
|
||||
txout: update_ops.into(),
|
||||
txs: [update_txs.clone()].into(),
|
||||
txouts: update_ops.into(),
|
||||
anchors: [(conf_anchor, update_txs.txid()), (unconf_anchor, h!("tx2"))].into(),
|
||||
last_seen: [(h!("tx2"), 1000000)].into()
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ impl<K> ElectrumUpdate<K, ConfirmationHeightAnchor> {
|
||||
let graph_additions = {
|
||||
let old_additions = TxGraph::default().determine_additions(&update.graph);
|
||||
tx_graph::Additions {
|
||||
tx: old_additions.tx,
|
||||
txout: old_additions.txout,
|
||||
txs: old_additions.txs,
|
||||
txouts: old_additions.txouts,
|
||||
last_seen: old_additions.last_seen,
|
||||
anchors: old_additions
|
||||
.anchors
|
||||
|
Loading…
x
Reference in New Issue
Block a user