/* This file is part of TON Blockchain Library. TON Blockchain Library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. TON Blockchain Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . Copyright 2017-2019 Telegram Systems LLP */ #pragma once #include "adnl/adnl.h" #include "adnl/utils.hpp" #include "overlay/overlays.h" #include "catchain-types.h" namespace ton { namespace catchain { class CatChainBlock { public: class Extra { public: virtual ~Extra() = default; }; virtual td::SharedSlice &payload() = 0; virtual const td::SharedSlice &payload() const = 0; virtual Extra *extra() const = 0; virtual std::unique_ptr move_extra() = 0; virtual void set_extra(std::unique_ptr extra) = 0; virtual td::uint32 source() const = 0; virtual td::uint32 fork() const = 0; virtual PublicKeyHash source_hash() const = 0; virtual CatChainBlockHash hash() const = 0; virtual CatChainBlockHeight height() const = 0; virtual CatChainBlock *prev() = 0; virtual const CatChainBlock *prev() const = 0; virtual const std::vector &deps() const = 0; virtual const std::vector &vt() const = 0; virtual bool preprocess_is_sent() const = 0; virtual void preprocess_sent() = 0; virtual bool is_processed() const = 0; virtual void set_processed() = 0; virtual bool is_descendant_of(CatChainBlock *block) = 0; static std::unique_ptr create(td::uint32 src, td::uint32 fork_id, PublicKeyHash src_hash, CatChainBlockHeight height, CatChainBlockHash hash, td::SharedSlice payload, CatChainBlock *prev, std::vector deps, std::vector vt); virtual ~CatChainBlock() = default; }; class CatChain : public td::actor::Actor { public: class Callback { public: virtual void process_blocks(std::vector blocks) = 0; virtual void finished_processing() = 0; virtual void preprocess_block(CatChainBlock *block) = 0; virtual void process_broadcast(PublicKeyHash src, td::BufferSlice data) = 0; virtual void process_message(PublicKeyHash src, td::BufferSlice data) = 0; virtual void process_query(PublicKeyHash src, td::BufferSlice data, td::Promise promise) = 0; virtual void started() = 0; virtual ~Callback() = default; }; struct PrintId { CatChainSessionId instance_; PublicKeyHash local_id_; }; virtual PrintId print_id() const = 0; virtual void processed_block(td::BufferSlice payload) = 0; virtual void need_new_block(td::Timestamp t) = 0; virtual void debug_add_fork(td::BufferSlice payload, CatChainBlockHeight height) = 0; virtual void send_broadcast(td::BufferSlice data) = 0; virtual void send_message(PublicKeyHash dst, td::BufferSlice data) = 0; virtual void send_query(PublicKeyHash dst, std::string name, td::Promise promise, td::Timestamp timeout, td::BufferSlice query) = 0; virtual void send_query_via(PublicKeyHash dst, std::string name, td::Promise promise, td::Timestamp timeout, td::BufferSlice query, td::uint64 max_answer_size, td::actor::ActorId via) = 0; virtual void destroy() = 0; static td::actor::ActorOwn create(std::unique_ptr callback, CatChainOptions opts, td::actor::ActorId keyring, td::actor::ActorId adnl, td::actor::ActorId overlay_manager, std::vector ids, PublicKeyHash local_id, CatChainSessionId unique_hash, std::string db_root); virtual ~CatChain() = default; }; } // namespace catchain } // namespace ton namespace td { inline td::StringBuilder &operator<<(td::StringBuilder &sb, const ton::catchain::CatChain::PrintId &print_id) { sb << "[catchain " << print_id.instance_ << "@" << print_id.local_id_ << "]"; return sb; } inline td::StringBuilder &operator<<(td::StringBuilder &sb, const ton::catchain::CatChain *catchain) { sb << catchain->print_id(); return sb; } } // namespace td