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