本文整理汇总了C++中transaction类的典型用法代码示例。如果您正苦于以下问题:C++ transaction类的具体用法?C++ transaction怎么用?C++ transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_consensus
// Validate script consensus conformance based on flags provided.
static bool check_consensus(const script& prevout_script,
const transaction& current_tx, size_t input_index,
uint32_t options)
{
BITCOIN_ASSERT(input_index <= max_uint32);
BITCOIN_ASSERT(input_index < current_tx.inputs.size());
const auto input_index32 = static_cast<uint32_t>(input_index);
const auto bip16_enabled = ((options & validation_options::p2sh) != 0);
#ifdef WITH_CONSENSUS
using namespace bc::consensus;
const auto previous_output_script = prevout_script.to_data(false);
data_chunk current_transaction = current_tx.to_data();
const auto flags = (bip16_enabled ? verify_flags_p2sh : verify_flags_none);
const auto result = verify_script(current_transaction.data(),
current_transaction.size(), previous_output_script.data(),
previous_output_script.size(), input_index32, flags);
const auto valid = (result == verify_result::verify_result_eval_true);
#else
// Copy the const prevout script so it can be run.
auto previous_output_script = prevout_script;
const auto& current_input_script = current_tx.inputs[input_index].script;
const auto valid = script::verify(current_input_script,
previous_output_script, current_tx, input_index32, bip16_enabled);
#endif
if (!valid)
log::warning(LOG_VALIDATE) << "Invalid transaction ["
<< encode_hash(current_tx.hash()) << "]";
return valid;
}
示例2: LOG_DEBUG
void unspent_outputs::add(const transaction& tx, size_t height,
uint32_t median_time_past, bool confirmed)
{
if (disabled() || tx.outputs().empty())
return;
if (tx.is_coinbase())
{
LOG_DEBUG(LOG_DATABASE)
<< "Output cache hit rate: " << hit_rate() << ", size: " << size();
}
// Critical Section
///////////////////////////////////////////////////////////////////////////
unique_lock lock(mutex_);
// It's been a long time since the last restart (~16 years).
if (sequence_ == max_uint32)
unspent_.clear();
// Remove the oldest entry if the buffer is at capacity.
if (unspent_.size() >= capacity_)
unspent_.right.erase(unspent_.right.begin());
// TODO: promote the unconfirmed tx cache instead of replacing it.
// A confirmed tx may replace the same unconfirmed tx here.
unspent_.insert(
{
unspent_transaction{ tx, height, median_time_past, confirmed },
++sequence_
});
///////////////////////////////////////////////////////////////////////////
}
示例3: assert
bool db_tx::read_disk_transaction(
const sha256 & hash, transaction & tx, transaction_index & index
)
{
assert(globals::instance().is_client() == false);
tx.set_null();
if (read_transaction_index(hash, index) == false)
{
return false;
}
return tx.read_from_disk(index.get_transaction_position());
}
示例4: connect_input
bool validate_transaction::connect_input(const transaction& tx,
size_t current_input, const transaction& previous_tx,
size_t parent_height, size_t last_block_height, uint64_t& value_in)
{
const auto& input = tx.inputs[current_input];
const auto& previous_outpoint = tx.inputs[current_input].previous_output;
if (previous_outpoint.index >= previous_tx.outputs.size())
return false;
const auto& previous_output = previous_tx.outputs[previous_outpoint.index];
const auto output_value = previous_output.value;
if (output_value > max_money())
return false;
if (previous_tx.is_coinbase())
{
const auto height_difference = last_block_height - parent_height;
if (height_difference < coinbase_maturity)
return false;
}
if (!check_consensus(previous_output.script, tx, current_input))
return false;
value_in += output_value;
return value_in <= max_money();
}
示例5: l1
void wallet_manager::sync_with_wallets(
const transaction & tx, block * blk, const bool & update,
const bool & connect
)
{
if (connect == false)
{
/**
* Wallets need to refund inputs when disconnecting coinstake (ppcoin).
*/
if (tx.is_coin_stake())
{
std::lock_guard<std::mutex> l1(mutex_);
for (auto & i : m_wallets)
{
if (i->is_from_me(tx))
{
i->disable_transaction(tx);
}
}
}
}
else
{
std::lock_guard<std::mutex> l1(mutex_);
for (auto & i : m_wallets)
{
i->add_to_wallet_if_involving_me(tx, blk, update);
}
}
}
示例6: aborted_transaction_exception
void ExceptAndBackOffOnAbortNoticeCM::abort_on_write
(transaction &t, base_transaction_object const &in)
{
//SLEEP(initialSleepTime_);
t.lock_and_abort();
throw aborted_transaction_exception("aborting transaction");
}
示例7: tx_db
bool utility::get_transaction(
const sha256 & hash_tx, transaction & tx, sha256 & hash_block_out
)
{
if (transaction_pool::instance().exists(hash_tx))
{
tx = transaction_pool::instance().lookup(hash_tx);
return true;
}
db_tx tx_db("r");
transaction_index index;
if (tx.read_from_disk(tx_db, point_out(hash_tx, 0), index))
{
block blk;
if (
blk.read_from_disk(index.get_transaction_position().file_index(),
index.get_transaction_position().block_position(), false)
)
{
hash_block_out = blk.get_hash();
}
return true;
}
return false;
}
示例8: BITCOIN_ASSERT
// Validate script consensus conformance based on flags provided.
bool validate_transaction::check_consensus(const script& prevout_script,
const transaction& current_tx, size_t input_index, uint32_t flags)
{
BITCOIN_ASSERT(input_index <= max_uint32);
BITCOIN_ASSERT(input_index < current_tx.inputs.size());
const auto input_index32 = static_cast<uint32_t>(input_index);
#ifdef WITH_CONSENSUS
using namespace bc::consensus;
const auto previous_output_script = prevout_script.to_data(false);
data_chunk current_transaction = current_tx.to_data();
// Convert native flags to libbitcoin-consensus flags.
uint32_t consensus_flags = verify_flags_none;
if ((flags & script_context::bip16_enabled) != 0)
consensus_flags |= verify_flags_p2sh;
if ((flags & script_context::bip65_enabled) != 0)
consensus_flags |= verify_flags_checklocktimeverify;
if ((flags & script_context::bip66_enabled) != 0)
consensus_flags |= verify_flags_dersig;
const auto result = verify_script(current_transaction.data(),
current_transaction.size(), previous_output_script.data(),
previous_output_script.size(), input_index32, consensus_flags);
const auto valid = (result == verify_result::verify_result_eval_true);
#else
// Copy the const prevout script so it can be run.
auto previous_output_script = prevout_script;
const auto& current_input_script = current_tx.inputs[input_index].script;
const auto valid = script::verify(current_input_script,
previous_output_script, current_tx, input_index32, flags);
#endif
if (!valid)
log::warning(LOG_BLOCKCHAIN)
<< "Invalid transaction ["
<< encode_hash(current_tx.hash()) << "]";
return valid;
}
示例9: verify_script
// TODO: cache transaction wire serialization.
code validate_input::verify_script(const transaction& tx, uint32_t input_index,
uint32_t forks, bool use_libconsensus)
{
if (!use_libconsensus)
return script::verify(tx, input_index, forks);
BITCOIN_ASSERT(input_index < tx.inputs().size());
const auto& prevout = tx.inputs()[input_index].previous_output().metadata;
const auto script_data = prevout.cache.script().to_data(false);
const auto prevout_value = prevout.cache.value();
const auto tx_data = tx.to_data(true, true);
// libconsensus
return convert_result(consensus::verify_script(tx_data.data(),
tx_data.size(), script_data.data(), script_data.size(), prevout_value,
input_index, convert_flags(forks)));
}
示例10: add
// A new transaction has been received, add it to the memory pool.
void transaction_pool::add(const transaction& tx, confirm_handler handler)
{
// When a new tx is added to the buffer drop the oldest.
if (maintain_consistency_ && buffer_.size() == buffer_.capacity())
delete_package(error::pool_filled);
// Store a precomputed tx hash to make lookups faster.
buffer_.push_back({ tx.hash(), tx, handler });
}
示例11: solve
void solve( transaction t ) {
std::multiset<int> list = {2100000001};
auto ref = list.insert( 2000000001 );
/* ref é um "ponteiro" que apontará para o valor que será o próximo
* i-ésimo da lista, a ser escrito no caso de um GET.
* Apenas deslocaremos ref para frente e para trás, de acordo com
* o inteiro que estamos inserindo. */
while( !t.end() )
if( t.add() ) {
int k = t.next();
list.insert( k );
if( k < *ref )
--ref;
}
else {
printf( "%i\n", *ref );
++ref;
}
}
示例12: tally_fees
bool validate_transaction::tally_fees(const transaction& tx, uint64_t value_in,
uint64_t& total_fees)
{
const auto value_out = tx.total_output_value();
if (value_in < value_out)
return false;
const auto fee = value_in - value_out;
total_fees += fee;
return total_fees <= max_money();
}
示例13: erase_transaction_index
bool db_tx::erase_transaction_index(const transaction & tx) const
{
std::string key_tx = "tx";
data_buffer buffer;
buffer.write_var_int(key_tx.size());
buffer.write_bytes(key_tx.data(), key_tx.size());
buffer.write_sha256(tx.get_hash());
return erase(buffer);
}
示例14: check_transaction
code validate_transaction::check_transaction(const transaction& tx)
{
if (tx.inputs.empty() || tx.outputs.empty())
return error::empty_transaction;
if (tx.serialized_size() > max_transaction_size)
return error::size_limits;
// Check for negative or overflow output values
uint64_t total_output_value = 0;
for (const auto& output: tx.outputs)
{
if (output.value > max_money())
return error::output_value_overflow;
total_output_value += output.value;
if (total_output_value > max_money())
return error::output_value_overflow;
}
if (tx.is_coinbase())
{
const auto& coinbase_script = tx.inputs[0].script;
const auto coinbase_size = coinbase_script.serialized_size(false);
if (coinbase_size < 2 || coinbase_size > 100)
return error::invalid_coinbase_script_size;
}
else
{
for (const auto& input: tx.inputs)
if (input.previous_output.is_null())
return error::previous_output_null;
}
return error::success;
}
示例15: lock
void unspent_outputs::add(const transaction& transaction, size_t height)
{
if (capacity_ == 0 || transaction.outputs().empty())
return;
// Critical Section
///////////////////////////////////////////////////////////////////////////
unique_lock lock(mutex_);
// It's been a long time since the last restart (~16 years).
if (sequence_ == max_uint32)
unspent_.clear();
// Remove the oldest entry if the buffer is at capacity.
if (unspent_.size() >= capacity_)
unspent_.right.erase(unspent_.right.begin());
unspent_.insert(
{
unspent_transaction{ transaction, height },
++sequence_
});
///////////////////////////////////////////////////////////////////////////
}