-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
175 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
libraries/types/pbft_block/include/pbft/pbft_block_extra_data.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include <libdevcore/Common.h> | ||
#include <libdevcore/RLP.h> | ||
#include <libdevcore/SHA3.h> | ||
#include <libdevcrypto/Common.h> | ||
|
||
#include "common/types.hpp" | ||
#include "dag/dag_block.hpp" | ||
#include "vote/vote.hpp" | ||
|
||
namespace taraxa { | ||
|
||
/** @addtogroup PBFT | ||
* @{ | ||
*/ | ||
|
||
class PbftBlockExtraData { | ||
public: | ||
PbftBlockExtraData() {} | ||
PbftBlockExtraData(const uint16_t major_version, const uint16_t minor_version, const uint16_t patch_version, | ||
const uint16_t net_version, const std::string node_implementation); | ||
PbftBlockExtraData(const bytes& data); | ||
|
||
/** | ||
* @brief Get rlp | ||
* @return rlp | ||
*/ | ||
bytes rlp() const; | ||
|
||
/** | ||
* @brief Get JSON | ||
* @return Json | ||
*/ | ||
Json::Value getJson() const; | ||
|
||
protected: | ||
uint16_t major_version_; | ||
uint16_t minor_version_; | ||
uint16_t patch_version_; | ||
uint16_t net_version_; | ||
std::string node_implementation_; | ||
static constexpr uint32_t kExtraDataMaxSize = 1024; | ||
}; | ||
|
||
/** @}*/ | ||
|
||
} // namespace taraxa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "pbft/pbft_block_extra_data.hpp" | ||
|
||
#include <iostream> | ||
|
||
#include "common/jsoncpp.hpp" | ||
|
||
namespace taraxa { | ||
|
||
PbftBlockExtraData::PbftBlockExtraData(const uint16_t major_version, const uint16_t minor_version, | ||
const uint16_t patch_version, const uint16_t net_version, | ||
const std::string node_implementation) | ||
: major_version_(major_version), | ||
minor_version_(minor_version), | ||
patch_version_(patch_version), | ||
net_version_(net_version), | ||
node_implementation_(node_implementation) {} | ||
|
||
PbftBlockExtraData::PbftBlockExtraData(const bytes& data) { | ||
if (data.size() > kExtraDataMaxSize) { | ||
throw std::runtime_error("Pbft block invalid, extra data size over the limit"); | ||
} | ||
dev::RLP rlp(data); | ||
util::rlp_tuple(util::RLPDecoderRef(rlp, true), major_version_, minor_version_, patch_version_, net_version_, | ||
node_implementation_); | ||
} | ||
|
||
bytes PbftBlockExtraData::rlp() const { | ||
dev::RLPStream s; | ||
s.appendList(5); | ||
s << major_version_; | ||
s << minor_version_; | ||
s << patch_version_; | ||
s << net_version_; | ||
s << node_implementation_; | ||
return s.invalidate(); | ||
} | ||
|
||
Json::Value PbftBlockExtraData::getJson() const { | ||
Json::Value json; | ||
json["major_version"] = major_version_; | ||
json["minor_version"] = minor_version_; | ||
json["patch_version"] = patch_version_; | ||
json["net_version"] = net_version_; | ||
json["node_implementation"] = node_implementation_; | ||
|
||
return json; | ||
} | ||
|
||
} // namespace taraxa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.