• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ transaction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中transaction的典型用法代码示例。如果您正苦于以下问题:C++ transaction类的具体用法?C++ transaction怎么用?C++ transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了transaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:36,代码来源:validate_transaction.cpp


示例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_
    });
    ///////////////////////////////////////////////////////////////////////////
}
开发者ID:RojavaCrypto,项目名称:libbitcoin-database,代码行数:33,代码来源:unspent_outputs.cpp


示例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());
}
开发者ID:jaggedMiner,项目名称:vanillacoin,代码行数:15,代码来源:db_tx.cpp


示例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();
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:27,代码来源:validate_transaction.cpp


示例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);
        }
    }
}
开发者ID:machado-rev,项目名称:vcash,代码行数:33,代码来源:wallet_manager.cpp


示例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");
}
开发者ID:joker-eph,项目名称:TBoost.STM,代码行数:7,代码来源:contention_manager.cpp


示例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;
}
开发者ID:rafaelfelicio,项目名称:vcash-1,代码行数:32,代码来源:utility.cpp


示例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;
}
开发者ID:chizon,项目名称:libbitcoin-blockchain,代码行数:46,代码来源:validate_transaction.cpp


示例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)));
}
开发者ID:evoskuil,项目名称:libbitcoin-blockchain,代码行数:19,代码来源:validate_input.cpp


示例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 });
}
开发者ID:jasonw580,项目名称:libbitcoin-blockchain,代码行数:10,代码来源:transaction_pool.cpp


示例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;
        }
}
开发者ID:royertiago,项目名称:maratona,代码行数:20,代码来源:501.cpp


示例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();
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:12,代码来源:validate_transaction.cpp


示例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);
}
开发者ID:jaggedMiner,项目名称:vanillacoin,代码行数:13,代码来源:db_tx.cpp


示例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;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:36,代码来源:validate_transaction.cpp


示例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_
    });
    ///////////////////////////////////////////////////////////////////////////
}
开发者ID:evoskuil,项目名称:libbitcoin-database,代码行数:24,代码来源:unspent_outputs.cpp


示例16: construct_miner_tx

  //---------------------------------------------------------------
  bool construct_miner_tx(size_t height, size_t median_size, uint64_t already_generated_coins, size_t current_block_size, uint64_t fee, const account_public_address &miner_address, transaction& tx, const blobdata& extra_nonce, size_t max_outs, uint8_t hard_fork_version) {
    tx.vin.clear();
    tx.vout.clear();
    tx.extra.clear();

    keypair txkey = keypair::generate();
    add_tx_pub_key_to_extra(tx, txkey.pub);
    if(!extra_nonce.empty())
      if(!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce))
        return false;

    txin_gen in;
    in.height = height;

    uint64_t block_reward;
    if(!get_block_reward(median_size, current_block_size, already_generated_coins, block_reward, hard_fork_version))
    {
      LOG_PRINT_L0("Block is too big");
      return false;
    }

#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
    LOG_PRINT_L1("Creating block template: reward " << block_reward <<
      ", fee " << fee);
#endif
    block_reward += fee;

    // from hard fork 2, we cut out the low significant digits. This makes the tx smaller, and
    // keeps the paid amount almost the same. The unpaid remainder gets pushed back to the
    // emission schedule
    // from hard fork 4, we use a single "dusty" output. This makes the tx even smaller,
    // and avoids the quantization. These outputs will be added as rct outputs with identity
    // masks, to they can be used as rct inputs.
    if (hard_fork_version >= 2 && hard_fork_version < 4) {
      block_reward = block_reward - block_reward % ::config::BASE_REWARD_CLAMP_THRESHOLD;
    }

    std::vector<uint64_t> out_amounts;
    decompose_amount_into_digits(block_reward, hard_fork_version >= 2 ? 0 : ::config::DEFAULT_DUST_THRESHOLD,
      [&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); },
      [&out_amounts](uint64_t a_dust) { out_amounts.push_back(a_dust); });

    CHECK_AND_ASSERT_MES(1 <= max_outs, false, "max_out must be non-zero");
    if (height == 0 || hard_fork_version >= 4)
    {
      // the genesis block was not decomposed, for unknown reasons
      while (max_outs < out_amounts.size())
      {
        //out_amounts[out_amounts.size() - 2] += out_amounts.back();
        //out_amounts.resize(out_amounts.size() - 1);
        out_amounts[1] += out_amounts[0];
        for (size_t n = 1; n < out_amounts.size(); ++n)
          out_amounts[n - 1] = out_amounts[n];
        out_amounts.resize(out_amounts.size() - 1);
      }
    }
    else
    {
      CHECK_AND_ASSERT_MES(max_outs >= out_amounts.size(), false, "max_out exceeded");
    }

    uint64_t summary_amounts = 0;
    for (size_t no = 0; no < out_amounts.size(); no++)
    {
      crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);;
      crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key);
      bool r = crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation);
      CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << txkey.sec << ")");

      r = crypto::derive_public_key(derivation, no, miner_address.m_spend_public_key, out_eph_public_key);
      CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << no << ", "<< miner_address.m_spend_public_key << ")");

      txout_to_key tk;
      tk.key = out_eph_public_key;

      tx_out out;
      summary_amounts += out.amount = out_amounts[no];
      out.target = tk;
      tx.vout.push_back(out);
    }

    CHECK_AND_ASSERT_MES(summary_amounts == block_reward, false, "Failed to construct miner tx, summary_amounts = " << summary_amounts << " not equal block_reward = " << block_reward);

    if (hard_fork_version >= 4)
      tx.version = 2;
    else
      tx.version = 1;

    //lock
    tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW;
    tx.vin.push_back(in);

    tx.invalidate_hashes();

    //LOG_PRINT("MINER_TX generated ok, block_reward=" << print_money(block_reward) << "("  << print_money(block_reward - fee) << "+" << print_money(fee)
    //  << "), current_block_size=" << current_block_size << ", already_generated_coins=" << already_generated_coins << ", tx_id=" << get_transaction_hash(tx), LOG_LEVEL_2);
    return true;
  }
开发者ID:Coder420,项目名称:bitmonero,代码行数:99,代码来源:cryptonote_tx_utils.cpp


示例17: construct_tx_and_get_tx_key

  //---------------------------------------------------------------
  bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct)
  {
    std::vector<rct::key> amount_keys;
    tx.set_null();
    amount_keys.clear();

    tx.version = rct ? 2 : 1;
    tx.unlock_time = unlock_time;

    tx.extra = extra;
    keypair txkey = keypair::generate();
    remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key));
    add_tx_pub_key_to_extra(tx, txkey.pub);
    tx_key = txkey.sec;

    // if we have a stealth payment id, find it and encrypt it with the tx key now
    std::vector<tx_extra_field> tx_extra_fields;
    if (parse_tx_extra(tx.extra, tx_extra_fields))
    {
      tx_extra_nonce extra_nonce;
      if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
      {
        crypto::hash8 payment_id = null_hash8;
        if (get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
        {
          LOG_PRINT_L2("Encrypting payment id " << payment_id);
          crypto::public_key view_key_pub = get_destination_view_key_pub(destinations, sender_account_keys);
          if (view_key_pub == null_pkey)
          {
            LOG_ERROR("Destinations have to have exactly one output to support encrypted payment ids");
            return false;
          }

          if (!encrypt_payment_id(payment_id, view_key_pub, txkey.sec))
          {
            LOG_ERROR("Failed to encrypt payment id");
            return false;
          }

          std::string extra_nonce;
          set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
          remove_field_from_tx_extra(tx.extra, typeid(tx_extra_nonce));
          if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce))
          {
            LOG_ERROR("Failed to add encrypted payment id to tx extra");
            return false;
          }
          LOG_PRINT_L1("Encrypted payment ID: " << payment_id);
        }
      }
    }
    else
    {
      LOG_ERROR("Failed to parse tx extra");
      return false;
    }

    struct input_generation_context_data
    {
      keypair in_ephemeral;
    };
    std::vector<input_generation_context_data> in_contexts;

    uint64_t summary_inputs_money = 0;
    //fill inputs
    int idx = -1;
    for(const tx_source_entry& src_entr:  sources)
    {
      ++idx;
      if(src_entr.real_output >= src_entr.outputs.size())
      {
        LOG_ERROR("real_output index (" << src_entr.real_output << ")bigger than output_keys.size()=" << src_entr.outputs.size());
        return false;
      }
      summary_inputs_money += src_entr.amount;

      //key_derivation recv_derivation;
      in_contexts.push_back(input_generation_context_data());
      keypair& in_ephemeral = in_contexts.back().in_ephemeral;
      crypto::key_image img;
      if(!generate_key_image_helper(sender_account_keys, src_entr.real_out_tx_key, src_entr.real_output_in_tx_index, in_ephemeral, img))
        return false;

      //check that derivated key is equal with real output key
      if( !(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].second.dest) )
      {
        LOG_ERROR("derived public key mismatch with output public key at index " << idx << ", real out " << src_entr.real_output << "! "<< ENDL << "derived_key:"
          << string_tools::pod_to_hex(in_ephemeral.pub) << ENDL << "real output_public_key:"
          << string_tools::pod_to_hex(src_entr.outputs[src_entr.real_output].second) );
        LOG_ERROR("amount " << src_entr.amount << ", rct " << src_entr.rct);
        LOG_ERROR("tx pubkey " << src_entr.real_out_tx_key << ", real_output_in_tx_index " << src_entr.real_output_in_tx_index);
        return false;
      }

      //put key image into tx input
      txin_to_key input_to_key;
      input_to_key.amount = src_entr.amount;
      input_to_key.k_image = img;

//.........这里部分代码省略.........
开发者ID:Coder420,项目名称:bitmonero,代码行数:101,代码来源:cryptonote_tx_utils.cpp


示例18: digest

digest_type database_fixture::digest( const transaction& tx )
{
   return tx.digest();
}
开发者ID:sfinder,项目名称:graphene,代码行数:4,代码来源:database_fixture.cpp


示例19:

 bool operator<(const transaction& second) {
   return this->profit() < second.profit();
 }
开发者ID:vviral,项目名称:examples,代码行数:3,代码来源:min_heap.cpp


示例20: delete_single

bool transaction_pool::delete_single(const transaction& tx, const code& ec)
{
    return delete_single(tx, tx.hash(), ec);
}
开发者ID:jasonw580,项目名称:libbitcoin-blockchain,代码行数:4,代码来源:transaction_pool.cpp



注:本文中的transaction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ transaction_evaluation_state类代码示例发布时间:2022-05-31
下一篇:
C++ trainer_type类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap