Skip to content

Commit

Permalink
check double spend in inputs when add tx to pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhaohui committed Sep 25, 2018
1 parent f586773 commit cf5545a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib/blockchain/validate_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,18 @@ code validate_transaction::check_transaction_basic() const
if (tx.serialized_size() > max_transaction_size)
return error::size_limits;

// check double spend in inputs
std::set<std::string> set;
for (auto& input : tx.inputs) {
auto tx_hash = libbitcoin::encode_hash(input.previous_output.hash);
auto value = tx_hash + ":" + std::to_string(input.previous_output.index);
if (set.count(value)) {
return error::double_spend;
}

set.insert(value);
}

// Check for negative or overflow output values
uint64_t total_output_value = 0;

Expand Down

0 comments on commit cf5545a

Please sign in to comment.