github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/fs/ir_manager/ir_manager_helper.h (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  #pragma once
    22  #include "common/address.h"
    23  #include "fs/blockchain.h"
    24  #include "fs/proto/ir.pb.h"
    25  #include "fs/rocksdb_storage.h"
    26  #include <boost/property_tree/ptree.hpp>
    27  
    28  namespace neb {
    29  namespace fs {
    30  
    31  typedef std::tuple<module_t, address_t> auth_key_t;
    32  typedef std::tuple<start_block_t, end_block_t> auth_val_t;
    33  
    34  class ir_manager_helper {
    35  public:
    36    static void set_failed_flag(rocksdb_storage *rs, const std::string &flag);
    37    static bool has_failed_flag(rocksdb_storage *rs, const std::string &flag);
    38    static void del_failed_flag(rocksdb_storage *rs, const std::string &flag);
    39  
    40    static block_height_t nbre_block_height(rocksdb_storage *rs);
    41    static block_height_t lib_block_height(blockchain *bc);
    42  
    43    static void run_auth_table(nbre::NBREIR &nbre_ir,
    44                               std::map<auth_key_t, auth_val_t> &auth_table);
    45    static void load_auth_table(rocksdb_storage *rs,
    46                                std::map<auth_key_t, auth_val_t> &auth_table);
    47  
    48    static void deploy_auth_table(rocksdb_storage *rs, nbre::NBREIR &nbre_ir,
    49                                  std::map<auth_key_t, auth_val_t> &auth_table,
    50                                  const neb::bytes &payload_bytes);
    51    static void
    52    show_auth_table(const std::map<auth_key_t, auth_val_t> &auth_table);
    53  
    54    static void update_ir_list(const std::string &name, rocksdb_storage *rs);
    55    static void update_ir_versions(const std::string &name, uint64_t version,
    56                                   rocksdb_storage *rs);
    57  
    58    static void deploy_ir(const std::string &name, uint64_t version,
    59                          const neb::bytes &payload_bytes, rocksdb_storage *rs);
    60  
    61    static void compile_payload_code(nbre::NBREIR *nbre_ir, bytes &payload_bytes);
    62  
    63  private:
    64    static void deploy_cpp(const std::string &name, uint64_t version,
    65                           const std::string &cpp_content, rocksdb_storage *rs);
    66  
    67    static void update_to_storage(const std::string &key,
    68                                  const boost::property_tree::ptree &val_pt,
    69                                  rocksdb_storage *rs);
    70  };
    71  
    72  } // namespace fs
    73  } // namespace neb