github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/ir/dip/dip_release_v1.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/dip/dip_impl.h"
    22  
    23  extern neb::rt::nr::nr_ret_type
    24  entry_point_nr(neb::compatible_uint64_t start_block,
    25                 neb::compatible_uint64_t end_block);
    26  
    27  neb::rt::dip::dip_ret_type entry_point_dip(neb::compatible_uint64_t height) {
    28    neb::rt::dip::dip_ret_type ret;
    29    std::get<0>(ret) = 0;
    30  
    31    uint64_t block_nums_of_a_day = 5;
    32    uint64_t days = 1;
    33    neb::compatible_uint64_t dip_start_block = 15;
    34    neb::compatible_uint64_t dip_block_interval = days * block_nums_of_a_day;
    35    std::string dip_reward_addr =
    36        std::string("n1c6y4ctkMeZk624QWBTXuywmNpCWmJZiBq");
    37    std::string coinbase_addr =
    38        std::string("n1HrPpwwH5gTA2d7QCkVjMw14YbN1NNNXHc");
    39  
    40    auto to_version_t = [](uint32_t major_version, uint16_t minor_version,
    41                           uint16_t patch_version) -> neb::rt::dip::version_t {
    42      return (0ULL + major_version) + ((0ULL + minor_version) << 32) +
    43             ((0ULL + patch_version) << 48);
    44    };
    45  
    46    if (!height) {
    47      std::get<1>(ret) = neb::rt::dip::dip_param_list(
    48          dip_start_block, dip_block_interval, dip_reward_addr, coinbase_addr,
    49          to_version_t(0, 0, 1));
    50      std::cout << "dip param list returned" << std::endl;
    51      return ret;
    52    }
    53  
    54    if (height < dip_start_block + dip_block_interval) {
    55      std::get<1>(ret) = std::string("{\"err\":\"invalid height\"}");
    56      return ret;
    57    }
    58  
    59    uint64_t interval_nums = (height - dip_start_block) / dip_block_interval;
    60    neb::compatible_uint64_t start_block =
    61        dip_start_block + dip_block_interval * interval_nums;
    62    neb::compatible_uint64_t end_block = start_block - 1;
    63    start_block -= dip_block_interval;
    64  
    65    auto nr_ret = entry_point_nr(start_block, end_block);
    66  
    67    neb::rt::dip::dip_float_t alpha = 8e-3;
    68    neb::rt::dip::dip_float_t beta = 1;
    69    return neb::rt::dip::entry_point_dip_impl(start_block, end_block,
    70                                              to_version_t(0, 0, 1), height,
    71                                              nr_ret, alpha, beta);
    72  }