Merge branch 'consolidate' into bip90

This commit is contained in:
debris 2017-04-09 14:12:05 +08:00
commit abb4771770
8 changed files with 16 additions and 16 deletions

View File

@ -482,7 +482,7 @@ impl<T> TransactionOutputProvider for BlockChainDatabase<T> where T: KeyValueDat
.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)
.and_then(|meta| meta.is_spent(prevout.index as usize))
.unwrap_or(false)

View File

@ -9,7 +9,7 @@ fn transaction_output(transactions: &[IndexedTransaction], prevout: &OutPoint) -
.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
// 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)
}
fn is_double_spent(&self, outpoint: &OutPoint) -> bool {
is_double_spent(&self.transactions, outpoint)
fn is_spent(&self, outpoint: &OutPoint) -> bool {
is_spent(&self.transactions, outpoint)
}
}

View File

@ -23,7 +23,7 @@ pub trait TransactionOutputProvider: Send + Sync {
fn transaction_output(&self, outpoint: &OutPoint, transaction_index: usize) -> Option<TransactionOutput>;
/// 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

View File

@ -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!();
}
}

View File

@ -819,7 +819,7 @@ impl TransactionOutputProvider for MemoryPool {
.cloned()
}
fn is_double_spent(&self, outpoint: &OutPoint) -> bool {
fn is_spent(&self, outpoint: &OutPoint) -> bool {
self.is_spent(outpoint)
}
}

View File

@ -75,7 +75,7 @@ impl TransactionOutputProvider for MemoryPoolTransactionOutputProvider {
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
if let Some(ref nonfinal_spends) = self.nonfinal_spends {
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
// => just check spending in storage
self.storage_provider.is_double_spent(prevout)
self.storage_provider.is_spent(prevout)
}
}
@ -127,9 +127,9 @@ mod tests {
// =>
// 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();
assert_eq!(provider.is_double_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_double_spent(&OutPoint { hash: dchain.at(2).hash(), index: 0, }), false);
assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(0).hash(), index: 0, }), false);
assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(1).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(1).hash(), index: 0, }, 0), None);
assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(2).hash(), index: 0, }, 0), None);

View File

@ -342,7 +342,7 @@ impl<'a> TransactionDoubleSpend<'a> {
fn check(&self) -> Result<(), TransactionError> {
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(
input.previous_output.hash.clone(),
input.previous_output.index

View File

@ -25,8 +25,8 @@ impl<'a> TransactionOutputProvider for DuplexTransactionOutputProvider<'a> {
.or_else(|| self.second.transaction_output(prevout, transaction_index))
}
fn is_double_spent(&self, prevout: &OutPoint) -> bool {
self.first.is_double_spent(prevout) || self.second.is_double_spent(prevout)
fn is_spent(&self, prevout: &OutPoint) -> bool {
self.first.is_spent(prevout) || self.second.is_spent(prevout)
}
}
@ -37,7 +37,7 @@ impl TransactionOutputProvider for NoopStore {
None
}
fn is_double_spent(&self, _prevout: &OutPoint) -> bool {
fn is_spent(&self, _prevout: &OutPoint) -> bool {
false
}
}