revert is_double_spent -> is_spent
This commit is contained in:
parent
21fdfabb0e
commit
0155c6e4ef
|
@ -471,7 +471,7 @@ impl<T> TransactionOutputProvider for BlockChainDatabase<T> where T: KeyValueDat
|
||||||
.and_then(|tx| tx.outputs.into_iter().nth(prevout.index as usize))
|
.and_then(|tx| tx.outputs.into_iter().nth(prevout.index as usize))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, prevout: &OutPoint) -> bool {
|
fn is_spent(&self, prevout: &OutPoint) -> bool {
|
||||||
self.transaction_meta(&prevout.hash)
|
self.transaction_meta(&prevout.hash)
|
||||||
.and_then(|meta| meta.is_spent(prevout.index as usize))
|
.and_then(|meta| meta.is_spent(prevout.index as usize))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
|
|
|
@ -9,7 +9,7 @@ fn transaction_output(transactions: &[IndexedTransaction], prevout: &OutPoint) -
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(transactions: &[IndexedTransaction], prevout: &OutPoint) -> bool {
|
fn is_spent(transactions: &[IndexedTransaction], prevout: &OutPoint) -> bool {
|
||||||
// the code below is valid, but has rather poor performance
|
// the code below is valid, but has rather poor performance
|
||||||
|
|
||||||
// if previous transaction output appears more than once than we can safely
|
// if previous transaction output appears more than once than we can safely
|
||||||
|
@ -29,7 +29,7 @@ impl TransactionOutputProvider for IndexedBlock {
|
||||||
transaction_output(&self.transactions[..take], outpoint)
|
transaction_output(&self.transactions[..take], outpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, outpoint: &OutPoint) -> bool {
|
fn is_spent(&self, outpoint: &OutPoint) -> bool {
|
||||||
is_double_spent(&self.transactions, outpoint)
|
is_spent(&self.transactions, outpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub trait TransactionOutputProvider: Send + Sync {
|
||||||
fn transaction_output(&self, outpoint: &OutPoint, transaction_index: usize) -> Option<TransactionOutput>;
|
fn transaction_output(&self, outpoint: &OutPoint, transaction_index: usize) -> Option<TransactionOutput>;
|
||||||
|
|
||||||
/// Returns true if we know that output is double spent.
|
/// Returns true if we know that output is double spent.
|
||||||
fn is_double_spent(&self, outpoint: &OutPoint) -> bool;
|
fn is_spent(&self, outpoint: &OutPoint) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transaction meta provider stores transaction meta information
|
/// Transaction meta provider stores transaction meta information
|
||||||
|
|
|
@ -180,7 +180,7 @@ impl<'a, T> TransactionOutputProvider for FittingTransactionsIterator<'a, T> whe
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, _outpoint: &OutPoint) -> bool {
|
fn is_spent(&self, _outpoint: &OutPoint) -> bool {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -819,7 +819,7 @@ impl TransactionOutputProvider for MemoryPool {
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, outpoint: &OutPoint) -> bool {
|
fn is_spent(&self, outpoint: &OutPoint) -> bool {
|
||||||
self.is_spent(outpoint)
|
self.is_spent(outpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl TransactionOutputProvider for MemoryPoolTransactionOutputProvider {
|
||||||
self.storage_provider.transaction_output(prevout, transaction_index)
|
self.storage_provider.transaction_output(prevout, transaction_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, prevout: &OutPoint) -> bool {
|
fn is_spent(&self, prevout: &OutPoint) -> bool {
|
||||||
// check if this output is spent by some non-final mempool transaction
|
// check if this output is spent by some non-final mempool transaction
|
||||||
if let Some(ref nonfinal_spends) = self.nonfinal_spends {
|
if let Some(ref nonfinal_spends) = self.nonfinal_spends {
|
||||||
if nonfinal_spends.double_spends.contains(&prevout.clone().into()) {
|
if nonfinal_spends.double_spends.contains(&prevout.clone().into()) {
|
||||||
|
@ -85,7 +85,7 @@ impl TransactionOutputProvider for MemoryPoolTransactionOutputProvider {
|
||||||
|
|
||||||
// we can omit memory_pool check here, because it has been completed in `for_transaction` method
|
// we can omit memory_pool check here, because it has been completed in `for_transaction` method
|
||||||
// => just check spending in storage
|
// => just check spending in storage
|
||||||
self.storage_provider.is_double_spent(prevout)
|
self.storage_provider.is_spent(prevout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ mod tests {
|
||||||
// =>
|
// =>
|
||||||
// if t3 is also depending on t1[0] || t2[0], it will be rejected by verification as missing inputs
|
// if t3 is also depending on t1[0] || t2[0], it will be rejected by verification as missing inputs
|
||||||
let provider = MemoryPoolTransactionOutputProvider::for_transaction(storage, &memory_pool, &dchain.at(3)).unwrap();
|
let provider = MemoryPoolTransactionOutputProvider::for_transaction(storage, &memory_pool, &dchain.at(3)).unwrap();
|
||||||
assert_eq!(provider.is_double_spent(&OutPoint { hash: dchain.at(0).hash(), index: 0, }), false);
|
assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(0).hash(), index: 0, }), false);
|
||||||
assert_eq!(provider.is_double_spent(&OutPoint { hash: dchain.at(1).hash(), index: 0, }), false);
|
assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(1).hash(), index: 0, }), false);
|
||||||
assert_eq!(provider.is_double_spent(&OutPoint { hash: dchain.at(2).hash(), index: 0, }), false);
|
assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(2).hash(), index: 0, }), false);
|
||||||
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(0).hash(), index: 0, }, 0), Some(dchain.at(0).outputs[0].clone()));
|
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(0).hash(), index: 0, }, 0), Some(dchain.at(0).outputs[0].clone()));
|
||||||
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(1).hash(), index: 0, }, 0), None);
|
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(1).hash(), index: 0, }, 0), None);
|
||||||
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(2).hash(), index: 0, }, 0), None);
|
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(2).hash(), index: 0, }, 0), None);
|
||||||
|
|
|
@ -338,7 +338,7 @@ impl<'a> TransactionDoubleSpend<'a> {
|
||||||
|
|
||||||
fn check(&self) -> Result<(), TransactionError> {
|
fn check(&self) -> Result<(), TransactionError> {
|
||||||
for input in &self.transaction.raw.inputs {
|
for input in &self.transaction.raw.inputs {
|
||||||
if self.store.is_double_spent(&input.previous_output) {
|
if self.store.is_spent(&input.previous_output) {
|
||||||
return Err(TransactionError::UsingSpentOutput(
|
return Err(TransactionError::UsingSpentOutput(
|
||||||
input.previous_output.hash.clone(),
|
input.previous_output.hash.clone(),
|
||||||
input.previous_output.index
|
input.previous_output.index
|
||||||
|
|
|
@ -25,8 +25,8 @@ impl<'a> TransactionOutputProvider for DuplexTransactionOutputProvider<'a> {
|
||||||
.or_else(|| self.second.transaction_output(prevout, transaction_index))
|
.or_else(|| self.second.transaction_output(prevout, transaction_index))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, prevout: &OutPoint) -> bool {
|
fn is_spent(&self, prevout: &OutPoint) -> bool {
|
||||||
self.first.is_double_spent(prevout) || self.second.is_double_spent(prevout)
|
self.first.is_spent(prevout) || self.second.is_spent(prevout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ impl TransactionOutputProvider for NoopStore {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_double_spent(&self, _prevout: &OutPoint) -> bool {
|
fn is_spent(&self, _prevout: &OutPoint) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue