Kagome
Polkadot Runtime Engine in C++17
offchain_worker.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_OFFCHAIN_WORKER_HPP
7 #define KAGOME_OFFCHAIN_WORKER_HPP
8 
9 #include <boost/optional.hpp>
10 #include <libp2p/multi/multiaddress.hpp>
11 #include <libp2p/peer/peer_id.hpp>
12 
13 #include "common/buffer.hpp"
14 #include "offchain/types.hpp"
15 #include "outcome/outcome.hpp"
16 #include "primitives/common.hpp"
17 #include "primitives/extrinsic.hpp"
18 
19 namespace kagome::offchain {
20 
32  public:
33  virtual ~OffchainWorker() = default;
34 
35  virtual outcome::result<void> run() = 0;
36 
37  // ------------------------- Off-Chain API methods -------------------------
38 
39  virtual bool isValidator() const = 0;
40 
42  const primitives::Extrinsic &ext) = 0;
43 
45 
46  virtual Timestamp timestamp() = 0;
47 
48  virtual void sleepUntil(Timestamp) = 0;
49 
50  virtual RandomSeed randomSeed() = 0;
51 
52  virtual void localStorageSet(StorageType storage_type,
53  const common::BufferView &key,
54  common::Buffer value) = 0;
55 
56  virtual void localStorageClear(StorageType storage_type,
57  const common::BufferView &key) = 0;
58 
59  virtual bool localStorageCompareAndSet(
60  StorageType storage_type,
61  const common::BufferView &key,
62  std::optional<common::BufferView> expected,
63  common::Buffer value) = 0;
64 
65  virtual outcome::result<common::Buffer> localStorageGet(
66  StorageType storage_type, const common::BufferView &key) = 0;
67 
69  HttpMethod method, std::string_view uri, common::Buffer meta) = 0;
70 
72  RequestId id, std::string_view name, std::string_view value) = 0;
73 
75  RequestId id,
76  common::Buffer chunk,
77  std::optional<Timestamp> deadline) = 0;
78 
79  virtual std::vector<HttpStatus> httpResponseWait(
80  const std::vector<RequestId> &ids,
81  std::optional<Timestamp> deadline) = 0;
82 
83  virtual std::vector<std::pair<std::string, std::string>>
85 
87  RequestId id,
88  common::Buffer &chunk,
89  std::optional<Timestamp> deadline) = 0;
90 
91  virtual void setAuthorizedNodes(std::vector<libp2p::peer::PeerId> nodes,
92  bool authorized_only) = 0;
93  };
94 
95 } // namespace kagome::offchain
96 
97 #endif /* KAGOME_OFFCHAIN_WORKER_HPP */
virtual Timestamp timestamp()=0
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
virtual Result< OpaqueNetworkState, Failure > networkState()=0
virtual void localStorageSet(StorageType storage_type, const common::BufferView &key, common::Buffer value)=0
virtual RandomSeed randomSeed()=0
virtual void sleepUntil(Timestamp)=0
virtual Result< RequestId, Failure > httpRequestStart(HttpMethod method, std::string_view uri, common::Buffer meta)=0
virtual Result< Success, Failure > submitTransaction(const primitives::Extrinsic &ext)=0
virtual ~OffchainWorker()=default
virtual outcome::result< void > run()=0
virtual Result< uint32_t, HttpError > httpResponseReadBody(RequestId id, common::Buffer &chunk, std::optional< Timestamp > deadline)=0
virtual bool localStorageCompareAndSet(StorageType storage_type, const common::BufferView &key, std::optional< common::BufferView > expected, common::Buffer value)=0
virtual void setAuthorizedNodes(std::vector< libp2p::peer::PeerId > nodes, bool authorized_only)=0
virtual std::vector< HttpStatus > httpResponseWait(const std::vector< RequestId > &ids, std::optional< Timestamp > deadline)=0
int16_t RequestId
Definition: types.hpp:29
virtual outcome::result< common::Buffer > localStorageGet(StorageType storage_type, const common::BufferView &key)=0
virtual bool isValidator() const =0
virtual Result< Success, HttpError > httpRequestWriteBody(RequestId id, common::Buffer chunk, std::optional< Timestamp > deadline)=0
uint64_t Timestamp
Timestamp is milliseconds since UNIX Epoch.
Definition: types.hpp:21
virtual std::vector< std::pair< std::string, std::string > > httpResponseHeaders(RequestId id)=0
Extrinsic class represents extrinsic.
Definition: extrinsic.hpp:24
virtual void localStorageClear(StorageType storage_type, const common::BufferView &key)=0
virtual Result< Success, Failure > httpRequestAddHeader(RequestId id, std::string_view name, std::string_view value)=0