github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/fs/blockchain/transaction/transaction_db.cpp (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  
    21  #include "fs/blockchain/transaction/transaction_db.h"
    22  
    23  namespace neb {
    24  namespace fs {
    25  
    26  transaction_db::transaction_db(blockchain_api_base *blockchain_ptr)
    27      : m_blockchain(blockchain_ptr) {}
    28  
    29  std::unique_ptr<std::vector<transaction_info_t>>
    30  transaction_db::read_transactions_from_db_with_duration(
    31      block_height_t start_block, block_height_t end_block) {
    32  
    33    auto ret = std::make_unique<std::vector<transaction_info_t>>();
    34  
    35    for (block_height_t h = start_block; h < end_block; h++) {
    36      auto tmp = m_blockchain->get_block_transactions_api(h);
    37      ret->insert(ret->end(), tmp->begin(), tmp->end());
    38    }
    39    return ret;
    40  }
    41  
    42  std::unique_ptr<std::vector<transaction_info_t>>
    43  transaction_db::read_transactions_with_address_type(
    44      const std::vector<transaction_info_t> &txs, byte_t from_type,
    45      byte_t to_type) {
    46  
    47    auto ret = std::make_unique<std::vector<transaction_info_t>>();
    48    for (auto &tx : txs) {
    49      neb::bytes from_bytes = tx.m_from;
    50      neb::bytes to_bytes = tx.m_to;
    51  
    52      if (from_bytes[1] == from_type && to_bytes[1] == to_type) {
    53        ret->push_back(tx);
    54      }
    55    }
    56    return ret;
    57  }
    58  
    59  } // namespace fs
    60  } // namespace neb