1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use chain::{OutPoint, TransactionOutput};
use network::TransactionOrdering;
use storage::TransactionOutputProvider;
#[derive(Clone, Copy)]
pub struct DuplexTransactionOutputProvider<'a> {
first: &'a TransactionOutputProvider,
second: &'a TransactionOutputProvider,
}
impl<'a> DuplexTransactionOutputProvider<'a> {
pub fn new(first: &'a TransactionOutputProvider, second: &'a TransactionOutputProvider) -> Self {
DuplexTransactionOutputProvider {
first: first,
second: second,
}
}
}
impl<'a> TransactionOutputProvider for DuplexTransactionOutputProvider<'a> {
fn transaction_output(&self, prevout: &OutPoint, transaction_index: usize) -> Option<TransactionOutput> {
self.first.transaction_output(prevout, transaction_index)
.or_else(|| self.second.transaction_output(prevout, transaction_index))
}
fn is_spent(&self, prevout: &OutPoint) -> bool {
self.first.is_spent(prevout) || self.second.is_spent(prevout)
}
}
pub struct NoopStore;
impl TransactionOutputProvider for NoopStore {
fn transaction_output(&self, _prevout: &OutPoint, _transaction_index: usize) -> Option<TransactionOutput> {
None
}
fn is_spent(&self, _prevout: &OutPoint) -> bool {
false
}
}
pub fn transaction_index_for_output_check(ordering: TransactionOrdering, tx_idx: usize) -> usize {
match ordering {
TransactionOrdering::Topological => tx_idx,
TransactionOrdering::Canonical => ::std::usize::MAX,
}
}