-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_header_repository.hpp
More file actions
99 lines (87 loc) · 2.93 KB
/
Copy pathblock_header_repository.hpp
File metadata and controls
99 lines (87 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <optional>
#include <qtils/byte_arr.hpp>
// #include "common/visitor.hpp"
// #include <qtils/outcome.hpp>
#include "jam_types/block_header.hpp"
// #include "primitives/block_id.hpp"
namespace jam::blockchain {
/**
* Status of a block
*/
enum class BlockStatus : uint8_t {
InChain,
Unknown,
};
/**
* An interface to a storage with block headers that provides several
* convenience methods, such as getting bloch number by its hash and vice
* versa or getting a block status
*/
class BlockHeaderRepository {
public:
virtual ~BlockHeaderRepository() = default;
/**
* @return the number of the block with the provided {@param block_hash}
* in case one is in the storage or an error
*/
virtual outcome::result<BlockNumber> getNumberByHash(
const BlockHash &block_hash) const = 0;
// /**
// * @param block_number - the number of a block, contained in a block
// header
// * @return the hash of the block with the provided number in case one is
// * in the storage or an error
// */
// virtual outcome::result<BlockHash> getHashByNumber(
// BlockNumber block_number) const = 0;
/**
* @return block header with corresponding {@param block_hash} or an error
*/
[[nodiscard]] virtual outcome::result<BlockHeader> getBlockHeader(
const BlockHash &block_hash) const = 0;
// /**
// * @return block header with corresponding {@param block_hash} or a none
// * optional if the corresponding block header is not in storage or a
// * storage error
// */
// virtual outcome::result<std::optional<BlockHeader>>
// tryGetBlockHeader(const BlockHash &block_hash) const = 0;
// /**
// * @param id of a block which number is returned
// * @return block number or a none optional if the corresponding block
// * header is not in storage or a storage error
// */
// outcome::result<BlockNumber> getNumberById(
// const BlockId &block_id) const {
// return visit_in_place(
// block_id,
// [](const BlockNumber &block_number) {
// return block_number;
// },
// [this](const BlockHash &block_hash) {
// return getNumberByHash(block_hash);
// });
// }
//
// /**
// * @param id of a block which hash is returned
// * @return block hash or a none optional if the corresponding block
// * header is not in storage or a storage error
// */
// outcome::result<BlockHash> getHashById(
// const BlockId &id) const {
// return visit_in_place(
// id,
// [this](const BlockNumber &n) {
// return getHashByNumber(n);
// },
// [](const BlockHash &hash) { return hash; });
// }
};
} // namespace jam::blockchain