mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix errors, now consensus get topic info work :)
This commit is contained in:
parent
5045d402d7
commit
8d3783611a
@ -242,7 +242,7 @@ void AdminTopicPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
|
|||||||
std::string timeout_color = "success-color";
|
std::string timeout_color = "success-color";
|
||||||
if(hedera_topic_model->getCurrentTimeout() < Poco::DateTime()) {
|
if(hedera_topic_model->getCurrentTimeout() < Poco::DateTime()) {
|
||||||
timeout_color = "alert-color";
|
timeout_color = "alert-color";
|
||||||
} else if(hedera_topic_model->getCurrentTimeout() - Poco::DateTime() > Poco::Timespan(2,0,0,0,0)) {
|
} else if((hedera_topic_model->getCurrentTimeout() - Poco::DateTime()) < Poco::Timespan(2,0,0,0,0)) {
|
||||||
timeout_color = "orange-color";
|
timeout_color = "orange-color";
|
||||||
}
|
}
|
||||||
responseStream << "\n";
|
responseStream << "\n";
|
||||||
|
|||||||
@ -74,7 +74,7 @@ namespace controller {
|
|||||||
auto payer_account = getAutoRenewAccount();
|
auto payer_account = getAutoRenewAccount();
|
||||||
auto node_server = NodeServer::pick(payer_account->getModel()->getNetworkType(), getModel()->getGroupId());
|
auto node_server = NodeServer::pick(payer_account->getModel()->getNetworkType(), getModel()->getGroupId());
|
||||||
auto query = model::hedera::Query::getTopicInfo(getTopicHederaId(), payer_account->getHederaId(), node_server);
|
auto query = model::hedera::Query::getTopicInfo(getTopicHederaId(), payer_account->getHederaId(), node_server);
|
||||||
query->setResponseType(proto::ANSWER_ONLY);
|
query->setResponseType(proto::COST_ANSWER);
|
||||||
model::hedera::Response response;
|
model::hedera::Response response;
|
||||||
HederaRequest request;
|
HederaRequest request;
|
||||||
query->sign(payer_account->getCryptoKey()->getKeyPair(user));
|
query->sign(payer_account->getCryptoKey()->getKeyPair(user));
|
||||||
@ -89,18 +89,21 @@ namespace controller {
|
|||||||
|
|
||||||
if (HEDERA_REQUEST_RETURN_OK == request.request(query, &response)) {
|
if (HEDERA_REQUEST_RETURN_OK == request.request(query, &response)) {
|
||||||
auto consensus_topic_info = response.getConsensusTopicInfo();
|
auto consensus_topic_info = response.getConsensusTopicInfo();
|
||||||
addNotification(new ParamSuccess("consensus get topic info", "memo: ", consensus_topic_info->getMemo()));
|
//addNotification(new ParamSuccess("consensus get topic info", "memo: ", consensus_topic_info->getMemo()));
|
||||||
|
//addNotification(new ParamSuccess("consensus get topic info", "string: ", consensus_topic_info->toStringHtml()));
|
||||||
auto model = getModel();
|
auto model = getModel();
|
||||||
model->setAutoRenewPeriod(consensus_topic_info->getAutoRenewPeriod().seconds());
|
model->setAutoRenewPeriod(consensus_topic_info->getAutoRenewPeriod().seconds());
|
||||||
model->setCurrentTimeout(consensus_topic_info->getExpirationTime());
|
model->setCurrentTimeout(consensus_topic_info->getExpirationTime());
|
||||||
model->setSequeceNumber(consensus_topic_info->getSequenceNumber());
|
model->setSequeceNumber(consensus_topic_info->getSequenceNumber());
|
||||||
|
|
||||||
|
|
||||||
std::string fieldNames[] = { "auto_renew_period", "current_timeout", "sequence_number" };
|
std::string fieldNames[] = { "auto_renew_period", "current_timeout", "sequence_number" };
|
||||||
if (model->updateIntoDB(
|
if (model->updateIntoDB(
|
||||||
fieldNames,
|
fieldNames,
|
||||||
model->getAutoRenewPeriod(),
|
model->getAutoRenewPeriod(),
|
||||||
model->getCurrentTimeout(),
|
model->getCurrentTimeout(),
|
||||||
model->getSequenceNumber()
|
model->getSequenceNumber()
|
||||||
) != 1) {
|
) > 1) {
|
||||||
addError(new Error("DB", "error saving changes in DB"));
|
addError(new Error("DB", "error saving changes in DB"));
|
||||||
getErrors(model);
|
getErrors(model);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -265,11 +265,12 @@ namespace DataTypeConverter
|
|||||||
Poco::Timestamp convertFromProtoTimestamp(const proto::Timestamp& timestamp)
|
Poco::Timestamp convertFromProtoTimestamp(const proto::Timestamp& timestamp)
|
||||||
{
|
{
|
||||||
// microseconds
|
// microseconds
|
||||||
return timestamp.seconds() * 10e6 + (google::protobuf::int64)(timestamp.nanos()) / 10e3;
|
google::protobuf::int64 microseconds = timestamp.seconds() * (google::protobuf::int64)10e5 + (google::protobuf::int64)(timestamp.nanos()) / (google::protobuf::int64)10e2;
|
||||||
|
return microseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
Poco::Timespan convertFromProtoDuration(const proto::Duration& duration)
|
Poco::Timespan convertFromProtoDuration(const proto::Duration& duration)
|
||||||
{
|
{
|
||||||
return (duration.seconds(), 0);
|
return Poco::Timespan(duration.seconds(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,11 +1,14 @@
|
|||||||
#include "ConsensusTopicInfo.h"
|
#include "ConsensusTopicInfo.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include "../../lib/DataTypeConverter.h"
|
||||||
|
#include "Poco/DateTimeFormatter.h"
|
||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
namespace hedera {
|
namespace hedera {
|
||||||
ConsensusTopicInfo::ConsensusTopicInfo(const proto::ConsensusTopicInfo& consensusTopicInfo)
|
ConsensusTopicInfo::ConsensusTopicInfo(const proto::ConsensusTopicInfo& consensusTopicInfo)
|
||||||
: mProto(consensusTopicInfo)
|
: mProto(consensusTopicInfo)
|
||||||
{
|
{
|
||||||
int zahl = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsensusTopicInfo::~ConsensusTopicInfo()
|
ConsensusTopicInfo::~ConsensusTopicInfo()
|
||||||
@ -22,5 +25,44 @@ namespace model {
|
|||||||
return running_hash_bin;
|
return running_hash_bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ConsensusTopicInfo::toString()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "memo: " << mProto.memo() << std::endl;
|
||||||
|
ss << "running hash: " << DataTypeConverter::binToHex((const unsigned char*)mProto.runninghash().data(), mProto.runninghash().size()) << std::endl;
|
||||||
|
ss << "sequence number: " << mProto.sequencenumber() << std::endl;
|
||||||
|
Poco::DateTime expiration_time = DataTypeConverter::convertFromProtoTimestamp(mProto.expirationtime());
|
||||||
|
|
||||||
|
ss << "expiration time: " << Poco::DateTimeFormatter::format(expiration_time, "%f.%m.%Y %H:%M:%S") << std::endl;
|
||||||
|
ss << "has admin key: " << mProto.has_adminkey() << std::endl;
|
||||||
|
ss << "has submit key: " << mProto.has_submitkey() << std::endl;
|
||||||
|
auto auto_renew_period = DataTypeConverter::convertFromProtoDuration(mProto.autorenewperiod());
|
||||||
|
ss << "auto renew period: " << std::to_string(auto_renew_period.seconds()) << " seconds" << std::endl;
|
||||||
|
auto acc_id = mProto.autorenewaccount();
|
||||||
|
ss << "auto renew account: " << acc_id.shardnum() << ", " << acc_id.realmnum() << ", " << acc_id.accountnum() << std::endl;
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ConsensusTopicInfo::toStringHtml()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "<ul>";
|
||||||
|
ss << "<li>memo: " << mProto.memo() << "</li>";
|
||||||
|
ss << "<li>running hash: " << DataTypeConverter::binToHex((const unsigned char*)mProto.runninghash().data(), mProto.runninghash().size()) << "</li>";
|
||||||
|
ss << "<li>sequence number: " << mProto.sequencenumber() << "</li>";
|
||||||
|
Poco::DateTime expiration_time = DataTypeConverter::convertFromProtoTimestamp(mProto.expirationtime());
|
||||||
|
|
||||||
|
ss << "<li>expiration time: " << Poco::DateTimeFormatter::format(expiration_time, "%f.%m.%Y %H:%M:%S") << "</li>";
|
||||||
|
ss << "<li>has admin key: " << mProto.has_adminkey() << "</li>";
|
||||||
|
ss << "<li>has submit key: " << mProto.has_submitkey() << "</li>";
|
||||||
|
auto auto_renew_period = DataTypeConverter::convertFromProtoDuration(mProto.autorenewperiod());
|
||||||
|
ss << "<li>auto renew period: " << std::to_string(mProto.autorenewperiod().seconds()) << " seconds" << "</li>";
|
||||||
|
auto acc_id = mProto.autorenewaccount();
|
||||||
|
ss << "<li>auto renew account: " << acc_id.shardnum() << ", " << acc_id.realmnum() << ", " << acc_id.accountnum() << "</li>";
|
||||||
|
ss << "</ul>";
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,10 @@ namespace model
|
|||||||
MemoryBin* getRunningHashCopy() const;
|
MemoryBin* getRunningHashCopy() const;
|
||||||
Poco::UInt64 getSequenceNumber() const { return mProto.sequencenumber(); }
|
Poco::UInt64 getSequenceNumber() const { return mProto.sequencenumber(); }
|
||||||
inline Poco::DateTime getExpirationTime() const { return DataTypeConverter::convertFromProtoTimestamp(mProto.expirationtime());}
|
inline Poco::DateTime getExpirationTime() const { return DataTypeConverter::convertFromProtoTimestamp(mProto.expirationtime());}
|
||||||
inline Poco::Timespan getAutoRenewPeriod() const { return DataTypeConverter::convertFromProtoDuration(mProto.autorenewperiod()); }
|
inline proto::Duration getAutoRenewPeriod() const { return mProto.autorenewperiod(); }
|
||||||
|
|
||||||
|
std::string toString();
|
||||||
|
std::string toStringHtml();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
proto::ConsensusTopicInfo mProto;
|
proto::ConsensusTopicInfo mProto;
|
||||||
|
|||||||
@ -76,11 +76,23 @@ namespace model {
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proto::QueryHeader* Query::getQueryHeader()
|
||||||
|
{
|
||||||
|
if (mQueryProto.has_cryptogetaccountbalance()) {
|
||||||
|
return mQueryProto.mutable_cryptogetaccountbalance()->mutable_header();
|
||||||
|
}
|
||||||
|
else if (mQueryProto.has_consensusgettopicinfo()) {
|
||||||
|
return mQueryProto.mutable_consensusgettopicinfo()->mutable_header();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool Query::sign(std::unique_ptr<KeyPairHedera> keyPairHedera)
|
bool Query::sign(std::unique_ptr<KeyPairHedera> keyPairHedera)
|
||||||
{
|
{
|
||||||
Transaction transaction;
|
Transaction transaction;
|
||||||
|
mTransactionBody->updateTimestamp();
|
||||||
auto sign_result = transaction.sign(std::move(keyPairHedera), mTransactionBody);
|
auto sign_result = transaction.sign(std::move(keyPairHedera), mTransactionBody);
|
||||||
auto query_header = mQueryProto.mutable_cryptogetaccountbalance()->mutable_header();
|
auto query_header = getQueryHeader();
|
||||||
query_header->set_allocated_payment(transaction.getTransaction());
|
query_header->set_allocated_payment(transaction.getTransaction());
|
||||||
transaction.resetPointer();
|
transaction.resetPointer();
|
||||||
|
|
||||||
@ -89,16 +101,13 @@ namespace model {
|
|||||||
|
|
||||||
void Query::setResponseType(proto::ResponseType type)
|
void Query::setResponseType(proto::ResponseType type)
|
||||||
{
|
{
|
||||||
auto get_account_balance = mQueryProto.mutable_cryptogetaccountbalance();
|
auto query_header = getQueryHeader();
|
||||||
auto query_header = get_account_balance->mutable_header();
|
|
||||||
query_header->set_responsetype(type);
|
query_header->set_responsetype(type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proto::ResponseType Query::getResponseType()
|
proto::ResponseType Query::getResponseType()
|
||||||
{
|
{
|
||||||
auto get_account_balance = mQueryProto.mutable_cryptogetaccountbalance();
|
auto query_header = getQueryHeader();
|
||||||
auto query_header = get_account_balance->mutable_header();
|
|
||||||
return query_header->responsetype();
|
return query_header->responsetype();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,8 @@ namespace model {
|
|||||||
inline const proto::Query* getProtoQuery() const { return &mQueryProto; }
|
inline const proto::Query* getProtoQuery() const { return &mQueryProto; }
|
||||||
inline std::string getConnectionString() const { return mTransactionBody->getConnectionString(); }
|
inline std::string getConnectionString() const { return mTransactionBody->getConnectionString(); }
|
||||||
|
|
||||||
|
proto::QueryHeader* getQueryHeader();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Query();
|
Query();
|
||||||
proto::Query mQueryProto;
|
proto::Query mQueryProto;
|
||||||
|
|||||||
@ -51,8 +51,9 @@ namespace model {
|
|||||||
inline controller::NodeServerConnection getConnection() const { return mConnection; }
|
inline controller::NodeServerConnection getConnection() const { return mConnection; }
|
||||||
inline TransactionBodyType getType() const { return mType; }
|
inline TransactionBodyType getType() const { return mType; }
|
||||||
|
|
||||||
protected:
|
|
||||||
void updateTimestamp();
|
void updateTimestamp();
|
||||||
|
protected:
|
||||||
|
|
||||||
proto::TransactionBody mTransactionBody;
|
proto::TransactionBody mTransactionBody;
|
||||||
controller::NodeServerConnection mConnection;
|
controller::NodeServerConnection mConnection;
|
||||||
bool mHasBody;
|
bool mHasBody;
|
||||||
|
|||||||
@ -47,7 +47,7 @@ namespace model {
|
|||||||
|
|
||||||
std::string HederaTopic::getAutoRenewPeriodString() const
|
std::string HederaTopic::getAutoRenewPeriodString() const
|
||||||
{
|
{
|
||||||
return secondsToReadableDuration(mAutoRenewPeriod) + "(" + std::to_string(mAutoRenewPeriod) + " seconds)";
|
return secondsToReadableDuration(mAutoRenewPeriod) + " (" + std::to_string(mAutoRenewPeriod) + " seconds)";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HederaTopic::getCurrentTimeoutString() const
|
std::string HederaTopic::getCurrentTimeoutString() const
|
||||||
|
|||||||
@ -287,9 +287,10 @@ namespace model {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
update << "UPDATE " << getTableName();
|
update << "UPDATE " << getTableName() << " SET ";
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
update << "SET " << fieldNames[i] << " = ? ";
|
if (i) update << ", ";
|
||||||
|
update << fieldNames[i] << " = ? ";
|
||||||
}
|
}
|
||||||
update << "WHERE id = ?"
|
update << "WHERE id = ?"
|
||||||
, Poco::Data::Keywords::bind(fieldValue1), Poco::Data::Keywords::bind(fieldValue2)
|
, Poco::Data::Keywords::bind(fieldValue1), Poco::Data::Keywords::bind(fieldValue2)
|
||||||
@ -324,9 +325,10 @@ namespace model {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
update << "UPDATE " << getTableName();
|
update << "UPDATE " << getTableName() << " SET ";
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
update << "SET " << fieldNames[i] << " = ? ";
|
if (i) update << ", ";
|
||||||
|
update << fieldNames[i] << " = ? ";
|
||||||
}
|
}
|
||||||
update << "WHERE id = ?"
|
update << "WHERE id = ?"
|
||||||
, Poco::Data::Keywords::bind(fieldValue1), Poco::Data::Keywords::bind(fieldValue2), Poco::Data::Keywords::bind(fieldValue3)
|
, Poco::Data::Keywords::bind(fieldValue1), Poco::Data::Keywords::bind(fieldValue2), Poco::Data::Keywords::bind(fieldValue3)
|
||||||
|
|||||||
@ -160,7 +160,7 @@
|
|||||||
std::string timeout_color = "success-color";
|
std::string timeout_color = "success-color";
|
||||||
if(hedera_topic_model->getCurrentTimeout() < Poco::DateTime()) {
|
if(hedera_topic_model->getCurrentTimeout() < Poco::DateTime()) {
|
||||||
timeout_color = "alert-color";
|
timeout_color = "alert-color";
|
||||||
} else if(hedera_topic_model->getCurrentTimeout() - Poco::DateTime() > Poco::Timespan(2,0,0,0,0)) {
|
} else if((hedera_topic_model->getCurrentTimeout() - Poco::DateTime()) < Poco::Timespan(2,0,0,0,0)) {
|
||||||
timeout_color = "orange-color";
|
timeout_color = "orange-color";
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user