github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/runtime/nr/impl/nr_impl.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 "runtime/nr/impl/nr_impl.h"
    22  #include "common/common.h"
    23  #include "common/configuration.h"
    24  #include "common/int128_conversion.h"
    25  #include "common/nebulas_currency.h"
    26  #include "fs/blockchain/blockchain_api_test.h"
    27  #include "runtime/nr/impl/nebulas_rank.h"
    28  
    29  namespace neb {
    30  namespace rt {
    31  namespace nr {
    32  
    33  nr_ret_type entry_point_nr_impl(compatible_uint64_t start_block,
    34                                  compatible_uint64_t end_block,
    35                                  version_t version, compatible_int64_t a,
    36                                  compatible_int64_t b, compatible_int64_t c,
    37                                  compatible_int64_t d, nr_float_t theta,
    38                                  nr_float_t mu, nr_float_t lambda) {
    39  
    40    std::unique_ptr<neb::fs::blockchain_api_base> pba;
    41    if (neb::use_test_blockchain) {
    42      pba = std::unique_ptr<neb::fs::blockchain_api_base>(
    43          new neb::fs::blockchain_api_test());
    44    } else {
    45      pba = std::unique_ptr<neb::fs::blockchain_api_base>(
    46          new neb::fs::blockchain_api());
    47    }
    48    transaction_db_ptr_t tdb_ptr =
    49        std::make_unique<neb::fs::transaction_db>(pba.get());
    50    account_db_ptr_t adb_ptr = std::make_unique<neb::fs::account_db>(pba.get());
    51  
    52    LOG(INFO) << "start block: " << start_block << " , end block: " << end_block;
    53    neb::rt::nr::rank_params_t rp{a, b, c, d, theta, mu, lambda};
    54  
    55    std::vector<std::pair<std::string, std::string>> meta_info;
    56    meta_info.push_back(
    57        std::make_pair("start_height", std::to_string(start_block)));
    58    meta_info.push_back(std::make_pair("end_height", std::to_string(end_block)));
    59    meta_info.push_back(std::make_pair("version", std::to_string(version)));
    60  
    61    nr_ret_type ret;
    62    std::get<0>(ret) = 1;
    63    std::get<1>(ret) = meta_info_to_json(meta_info);
    64    std::get<2>(ret) =
    65        nebulas_rank::get_nr_score(tdb_ptr, adb_ptr, rp, start_block, end_block);
    66    return ret;
    67  }
    68  
    69  } // namespace nr
    70  } // namespace rt
    71  } // namespace neb
    72