当前位置: 首页>>代码示例>>C++>>正文


C++ core::get_blockchain_storage方法代码示例

本文整理汇总了C++中cryptonote::core::get_blockchain_storage方法的典型用法代码示例。如果您正苦于以下问题:C++ core::get_blockchain_storage方法的具体用法?C++ core::get_blockchain_storage怎么用?C++ core::get_blockchain_storage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cryptonote::core的用法示例。


在下文中一共展示了core::get_blockchain_storage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pop_blocks

int pop_blocks(cryptonote::core& core, int num_blocks)
{
  bool use_batch = opt_batch;

  if (use_batch)
    core.get_blockchain_storage().get_db().batch_start();

  int quit = 0;
  block popped_block;
  std::vector<transaction> popped_txs;
  for (int i=0; i < num_blocks; ++i)
  {
    // simple_core.m_storage.pop_block_from_blockchain() is private, so call directly through db
    core.get_blockchain_storage().get_db().pop_block(popped_block, popped_txs);
    quit = 1;
  }


  if (use_batch)
  {
    if (quit > 1)
    {
      // There was an error, so don't commit pending data.
      // Destructor will abort write txn.
    }
    else
    {
      core.get_blockchain_storage().get_db().batch_stop();
    }
    core.get_blockchain_storage().get_db().show_stats();
  }

  return num_blocks;
}
开发者ID:monero-project,项目名称:bitmonero,代码行数:34,代码来源:blockchain_import.cpp

示例2: check_double_spend

bool DoubleSpendBase::check_double_spend(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& events)
{
  DEFINE_TESTS_ERROR_CONTEXT("DoubleSpendBase::check_double_spend");
  CHECK_EQ(m_last_valid_block, c.get_blockchain_storage().get_tail_id());
  return true;
}
开发者ID:netsafe,项目名称:digitalnote,代码行数:6,代码来源:double_spend.cpp

示例3: mark_last_valid_block

bool DoubleSpendBase::mark_last_valid_block(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& /*events*/)
{
  m_last_valid_block = c.get_blockchain_storage().get_tail_id();
  return true;
}
开发者ID:netsafe,项目名称:digitalnote,代码行数:5,代码来源:double_spend.cpp

示例4: import_from_file

int import_from_file(cryptonote::core& core, const std::string& import_file_path, uint64_t block_stop=0)
{
  // Reset stats, in case we're using newly created db, accumulating stats
  // from addition of genesis block.
  // This aligns internal db counts with importer counts.
  core.get_blockchain_storage().get_db().reset_stats();

  boost::filesystem::path fs_import_file_path(import_file_path);
  boost::system::error_code ec;
  if (!boost::filesystem::exists(fs_import_file_path, ec))
  {
    MFATAL("bootstrap file not found: " << fs_import_file_path);
    return false;
  }

  uint64_t start_height = 1, seek_height;
  if (opt_resume)
    start_height = core.get_blockchain_storage().get_current_blockchain_height();

  seek_height = start_height;
  BootstrapFile bootstrap;
  std::streampos pos;
  // BootstrapFile bootstrap(import_file_path);
  uint64_t total_source_blocks = bootstrap.count_blocks(import_file_path, pos, seek_height);
  MINFO("bootstrap file last block number: " << total_source_blocks-1 << " (zero-based height)  total blocks: " << total_source_blocks);

  if (total_source_blocks-1 <= start_height)
  {
    return false;
  }

  std::cout << ENDL;
  std::cout << "Preparing to read blocks..." << ENDL;
  std::cout << ENDL;

  std::ifstream import_file;
  import_file.open(import_file_path, std::ios_base::binary | std::ifstream::in);

  uint64_t h = 0;
  uint64_t num_imported = 0;
  if (import_file.fail())
  {
    MFATAL("import_file.open() fail");
    return false;
  }

  // 4 byte magic + (currently) 1024 byte header structures
  uint8_t major_version, minor_version;
  bootstrap.seek_to_first_chunk(import_file, major_version, minor_version);

  std::string str1;
  char buffer1[1024];
  char buffer_block[BUFFER_SIZE];
  block b;
  transaction tx;
  int quit = 0;
  uint64_t bytes_read;

  // Note that a new blockchain will start with block number 0 (total blocks: 1)
  // due to genesis block being added at initialization.

  if (! block_stop)
  {
    block_stop = total_source_blocks - 1;
  }

  // These are what we'll try to use, and they don't have to be a determination
  // from source and destination blockchains, but those are the defaults.
  MINFO("start block: " << start_height << "  stop block: " <<
      block_stop);

  bool use_batch = opt_batch && !opt_verify;

  MINFO("Reading blockchain from bootstrap file...");
  std::cout << ENDL;

  std::vector<block_complete_entry> blocks;

  // Skip to start_height before we start adding.
  {
    bool q2 = false;
    import_file.seekg(pos);
    bytes_read = bootstrap.count_bytes(import_file, start_height-seek_height, h, q2);
    if (q2)
    {
      quit = 2;
      goto quitting;
    }
    h = start_height;
  }

  if (use_batch)
  {
    uint64_t bytes, h2;
    bool q2;
    pos = import_file.tellg();
    bytes = bootstrap.count_bytes(import_file, db_batch_size, h2, q2);
    if (import_file.eof())
      import_file.clear();
    import_file.seekg(pos);
//.........这里部分代码省略.........
开发者ID:monero-project,项目名称:bitmonero,代码行数:101,代码来源:blockchain_import.cpp

示例5: check_flush

int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &blocks, bool force)
{
  if (blocks.empty())
    return 0;
  if (!force && blocks.size() < db_batch_size)
    return 0;

  // wait till we can verify a full HOH without extra, for speed
  uint64_t new_height = core.get_blockchain_storage().get_db().height() + blocks.size();
  if (!force && new_height % HASH_OF_HASHES_STEP)
    return 0;

  std::vector<crypto::hash> hashes;
  for (const auto &b: blocks)
  {
    cryptonote::block block;
    if (!parse_and_validate_block_from_blob(b.block, block))
    {
      MERROR("Failed to parse block: "
          << epee::string_tools::pod_to_hex(get_blob_hash(b.block)));
      core.cleanup_handle_incoming_blocks();
      return 1;
    }
    hashes.push_back(cryptonote::get_block_hash(block));
  }
  core.prevalidate_block_hashes(core.get_blockchain_storage().get_db().height(), hashes);

  std::vector<block> pblocks;
  if (!core.prepare_handle_incoming_blocks(blocks, pblocks))
  {
    MERROR("Failed to prepare to add blocks");
    return 1;
  }
  if (!pblocks.empty() && pblocks.size() != blocks.size())
  {
    MERROR("Unexpected parsed blocks size");
    core.cleanup_handle_incoming_blocks();
    return 1;
  }

  size_t blockidx = 0;
  for(const block_complete_entry& block_entry: blocks)
  {
    // process transactions
    for(auto& tx_blob: block_entry.txs)
    {
      tx_verification_context tvc = AUTO_VAL_INIT(tvc);
      core.handle_incoming_tx(tx_blob, tvc, true, true, false);
      if(tvc.m_verifivation_failed)
      {
        MERROR("transaction verification failed, tx_id = "
            << epee::string_tools::pod_to_hex(get_blob_hash(tx_blob)));
        core.cleanup_handle_incoming_blocks();
        return 1;
      }
    }

    // process block

    block_verification_context bvc = boost::value_initialized<block_verification_context>();

    core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx++], bvc, false); // <--- process block

    if(bvc.m_verifivation_failed)
    {
      MERROR("Block verification failed, id = "
          << epee::string_tools::pod_to_hex(get_blob_hash(block_entry.block)));
      core.cleanup_handle_incoming_blocks();
      return 1;
    }
    if(bvc.m_marked_as_orphaned)
    {
      MERROR("Block received at sync phase was marked as orphaned");
      core.cleanup_handle_incoming_blocks();
      return 1;
    }

  } // each download block
  if (!core.cleanup_handle_incoming_blocks())
    return 1;

  blocks.clear();
  return 0;
}
开发者ID:monero-project,项目名称:bitmonero,代码行数:84,代码来源:blockchain_import.cpp


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