fix errors, now consensus get topic info work :)

This commit is contained in:
Dario 2020-09-16 20:12:51 +02:00
parent 5045d402d7
commit 8d3783611a
11 changed files with 84 additions and 21 deletions

View File

@ -242,7 +242,7 @@ void AdminTopicPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
std::string timeout_color = "success-color";
if(hedera_topic_model->getCurrentTimeout() < Poco::DateTime()) {
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";
}
responseStream << "\n";

View File

@ -74,7 +74,7 @@ namespace controller {
auto payer_account = getAutoRenewAccount();
auto node_server = NodeServer::pick(payer_account->getModel()->getNetworkType(), getModel()->getGroupId());
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;
HederaRequest request;
query->sign(payer_account->getCryptoKey()->getKeyPair(user));
@ -89,18 +89,21 @@ namespace controller {
if (HEDERA_REQUEST_RETURN_OK == request.request(query, &response)) {
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();
model->setAutoRenewPeriod(consensus_topic_info->getAutoRenewPeriod().seconds());
model->setCurrentTimeout(consensus_topic_info->getExpirationTime());
model->setSequeceNumber(consensus_topic_info->getSequenceNumber());
std::string fieldNames[] = { "auto_renew_period", "current_timeout", "sequence_number" };
if (model->updateIntoDB(
fieldNames,
model->getAutoRenewPeriod(),
model->getCurrentTimeout(),
model->getSequenceNumber()
) != 1) {
) > 1) {
addError(new Error("DB", "error saving changes in DB"));
getErrors(model);
return false;

View File

@ -265,11 +265,12 @@ namespace DataTypeConverter
Poco::Timestamp convertFromProtoTimestamp(const proto::Timestamp& timestamp)
{
// 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)
{
return (duration.seconds(), 0);
return Poco::Timespan(duration.seconds(), 0);
}
}

View File

@ -1,11 +1,14 @@
#include "ConsensusTopicInfo.h"
#include <sstream>
#include "../../lib/DataTypeConverter.h"
#include "Poco/DateTimeFormatter.h"
namespace model {
namespace hedera {
ConsensusTopicInfo::ConsensusTopicInfo(const proto::ConsensusTopicInfo& consensusTopicInfo)
: mProto(consensusTopicInfo)
{
int zahl = 1;
}
ConsensusTopicInfo::~ConsensusTopicInfo()
@ -22,5 +25,44 @@ namespace model {
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();
}
}
}

View File

@ -20,7 +20,10 @@ namespace model
MemoryBin* getRunningHashCopy() const;
Poco::UInt64 getSequenceNumber() const { return mProto.sequencenumber(); }
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:
proto::ConsensusTopicInfo mProto;

View File

@ -76,11 +76,23 @@ namespace model {
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)
{
Transaction transaction;
mTransactionBody->updateTimestamp();
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());
transaction.resetPointer();
@ -89,16 +101,13 @@ namespace model {
void Query::setResponseType(proto::ResponseType type)
{
auto get_account_balance = mQueryProto.mutable_cryptogetaccountbalance();
auto query_header = get_account_balance->mutable_header();
auto query_header = getQueryHeader();
query_header->set_responsetype(type);
}
proto::ResponseType Query::getResponseType()
{
auto get_account_balance = mQueryProto.mutable_cryptogetaccountbalance();
auto query_header = get_account_balance->mutable_header();
auto query_header = getQueryHeader();
return query_header->responsetype();
}

View File

@ -32,6 +32,8 @@ namespace model {
inline const proto::Query* getProtoQuery() const { return &mQueryProto; }
inline std::string getConnectionString() const { return mTransactionBody->getConnectionString(); }
proto::QueryHeader* getQueryHeader();
protected:
Query();
proto::Query mQueryProto;

View File

@ -51,8 +51,9 @@ namespace model {
inline controller::NodeServerConnection getConnection() const { return mConnection; }
inline TransactionBodyType getType() const { return mType; }
protected:
void updateTimestamp();
protected:
proto::TransactionBody mTransactionBody;
controller::NodeServerConnection mConnection;
bool mHasBody;

View File

@ -47,7 +47,7 @@ namespace model {
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

View File

@ -287,9 +287,10 @@ namespace model {
return 0;
}
update << "UPDATE " << getTableName();
update << "UPDATE " << getTableName() << " SET ";
for (int i = 0; i < 2; i++) {
update << "SET " << fieldNames[i] << " = ? ";
if (i) update << ", ";
update << fieldNames[i] << " = ? ";
}
update << "WHERE id = ?"
, Poco::Data::Keywords::bind(fieldValue1), Poco::Data::Keywords::bind(fieldValue2)
@ -324,9 +325,10 @@ namespace model {
return 0;
}
update << "UPDATE " << getTableName();
update << "UPDATE " << getTableName() << " SET ";
for (int i = 0; i < 3; i++) {
update << "SET " << fieldNames[i] << " = ? ";
if (i) update << ", ";
update << fieldNames[i] << " = ? ";
}
update << "WHERE id = ?"
, Poco::Data::Keywords::bind(fieldValue1), Poco::Data::Keywords::bind(fieldValue2), Poco::Data::Keywords::bind(fieldValue3)

View File

@ -160,7 +160,7 @@
std::string timeout_color = "success-color";
if(hedera_topic_model->getCurrentTimeout() < Poco::DateTime()) {
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";
}
%>