github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/fs/blockchain/blockchain_api.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 25 namespace neb { 26 namespace fs { 27 28 struct transaction_info_t { 29 block_height_t m_height; 30 int32_t m_status; // 0: fail, 1: succ, 2: special 31 address_t m_from; 32 address_t m_to; 33 std::string m_tx_type; // "binary", "call", "deploy", "protocol" 34 wei_t m_tx_value; 35 int64_t m_timestamp; // no use 36 wei_t m_gas_used; 37 wei_t m_gas_price; 38 }; 39 40 struct account_info_t { 41 address_t m_address; 42 wei_t m_balance; 43 }; 44 45 struct event_info_t { 46 int32_t m_status; 47 wei_t m_gas_used; 48 }; 49 50 class blockchain_api_base { 51 public: 52 virtual ~blockchain_api_base(); 53 virtual std::unique_ptr<std::vector<transaction_info_t>> 54 get_block_transactions_api(block_height_t height) = 0; 55 56 virtual std::unique_ptr<corepb::Account> 57 get_account_api(const address_t &addr, block_height_t height) = 0; 58 virtual std::unique_ptr<corepb::Transaction> 59 get_transaction_api(const std::string &tx_hash, block_height_t height) = 0; 60 }; 61 62 class blockchain_api : public blockchain_api_base { 63 public: 64 blockchain_api(); 65 virtual ~blockchain_api(); 66 67 virtual std::unique_ptr<std::vector<transaction_info_t>> 68 get_block_transactions_api(block_height_t height); 69 70 virtual std::unique_ptr<corepb::Account> 71 get_account_api(const address_t &addr, block_height_t height); 72 virtual std::unique_ptr<corepb::Transaction> 73 get_transaction_api(const std::string &tx_hash, block_height_t height); 74 75 private: 76 std::unique_ptr<event_info_t> 77 get_transaction_result_api(const neb::bytes &events_root, 78 const neb::bytes &tx_hash); 79 std::unique_ptr<event_info_t> json_parse_event(const std::string &json); 80 }; 81 82 } // namespace fs 83 } // namespace neb