mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
prepare for hedera get topic info query
This commit is contained in:
parent
4ece67c057
commit
7bc02f4e63
@ -0,0 +1,15 @@
|
||||
#include "ConsensusGetTopicInfoResponse.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
ConsensusGetTopicInfoResponse::ConsensusGetTopicInfoResponse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ConsensusGetTopicInfoResponse::~ConsensusGetTopicInfoResponse()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_MODEL_HEDERA_CONSENSUS_GET_TOPIC_INFO_RESPONSE_H
|
||||
#define __GRADIDO_LOGIN_SERVER_MODEL_HEDERA_CONSENSUS_GET_TOPIC_INFO_RESPONSE_H
|
||||
|
||||
#include "../proto/hedera/ConsensusGetTopicInfo.pb.h"
|
||||
|
||||
namespace model
|
||||
{
|
||||
namespace hedera
|
||||
{
|
||||
class ConsensusGetTopicInfoResponse
|
||||
{
|
||||
public:
|
||||
ConsensusGetTopicInfoResponse();
|
||||
~ConsensusGetTopicInfoResponse();
|
||||
|
||||
protected:
|
||||
proto::ConsensusGetTopicInfoResponse mProto;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_MODEL_HEDERA_CONSENSUS_GET_TOPIC_INFO_RESPONSE_H
|
||||
@ -48,6 +48,29 @@ namespace model {
|
||||
return query;
|
||||
}
|
||||
|
||||
Query* Query::getTopicInfo(Poco::AutoPtr<controller::HederaId> topicId, Poco::AutoPtr<controller::HederaId> payerAccountId, const controller::NodeServerConnection& connection)
|
||||
{
|
||||
assert(!topicId.isNull() && topicId->getModel());
|
||||
assert(!payerAccountId.isNull() && payerAccountId->getModel());
|
||||
|
||||
auto query = new Query;
|
||||
auto get_topic_info = query->mQueryProto.mutable_consensusgettopicinfo();
|
||||
topicId->copyToProtoTopicId(get_topic_info->mutable_topicid());
|
||||
|
||||
auto query_header = get_topic_info->mutable_header();
|
||||
query_header->set_responsetype(proto::ANSWER_ONLY);
|
||||
|
||||
query->mTransactionBody = new TransactionBody(payerAccountId, connection);
|
||||
CryptoTransferTransaction crypto_transaction;
|
||||
// 0.002809 Hashbars
|
||||
// fee from https://www.hedera.com/fees
|
||||
crypto_transaction.addSender(payerAccountId, -2809);
|
||||
crypto_transaction.addReceiver(connection.hederaId, 2809);
|
||||
query->mTransactionBody->setCryptoTransfer(crypto_transaction);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
bool Query::sign(std::unique_ptr<KeyPairHedera> keyPairHedera)
|
||||
{
|
||||
Transaction transaction;
|
||||
@ -73,5 +96,7 @@ namespace model {
|
||||
auto query_header = get_account_balance->mutable_header();
|
||||
return query_header->responsetype();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -22,10 +22,12 @@ namespace model {
|
||||
public:
|
||||
~Query();
|
||||
static Query* getBalance(Poco::AutoPtr<controller::HederaId> accountId, const controller::NodeServerConnection& connection);
|
||||
static Query* getTopicInfo(Poco::AutoPtr<controller::HederaId> topicId, Poco::AutoPtr<controller::HederaId> payerAccountId, const controller::NodeServerConnection& connection);
|
||||
bool sign(std::unique_ptr<KeyPairHedera> keyPairHedera);
|
||||
|
||||
void setResponseType(proto::ResponseType type);
|
||||
proto::ResponseType getResponseType();
|
||||
inline bool setTransactionFee(Poco::UInt64 fee) { return mTransactionBody->updateCryptoTransferAmount(fee);}
|
||||
|
||||
inline const proto::Query* getProtoQuery() const { return &mQueryProto; }
|
||||
inline std::string getConnectionString() const { return mTransactionBody->getConnectionString(); }
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
#include "QueryHeader.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
QueryHeader::QueryHeader(Transaction* paymentTransaction)
|
||||
{
|
||||
mProtoQueryHeader.set_responsetype(proto::ANSWER_ONLY);
|
||||
}
|
||||
|
||||
QueryHeader::~QueryHeader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_MODEL_HEDERA_QUERY_HEADER_H
|
||||
#define __GRADIDO_LOGIN_SERVER_MODEL_HEDERA_QUERY_HEADER_H
|
||||
|
||||
#include "../proto/hedera/QueryHeader.pb.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
class QueryHeader
|
||||
{
|
||||
public:
|
||||
QueryHeader(Transaction* paymentTransaction);
|
||||
~QueryHeader();
|
||||
|
||||
void setResponseType(proto::ResponseType type) { mProtoQueryHeader.set_responsetype(type); };
|
||||
proto::ResponseType getResponseType() const { return mProtoQueryHeader.responsetype(); }
|
||||
|
||||
protected:
|
||||
proto::QueryHeader mProtoQueryHeader;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_MODEL_HEDERA_QUERY_HEADER_H
|
||||
@ -20,6 +20,21 @@ namespace model {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Poco::UInt64 Response::getQueryCost()
|
||||
{
|
||||
proto::ResponseHeader* response_header = nullptr;
|
||||
if (mResponseProto.has_consensusgettopicinfo()) {
|
||||
response_header = mResponseProto.mutable_consensusgettopicinfo()->mutable_header();
|
||||
}
|
||||
else if (mResponseProto.has_cryptogetaccountbalance()) {
|
||||
response_header = mResponseProto.mutable_cryptogetaccountbalance()->mutable_header();
|
||||
}
|
||||
if (response_header) {
|
||||
return response_header->cost();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
proto::ResponseCodeEnum Response::getResponseCode()
|
||||
{
|
||||
if (isCryptoGetAccountBalanceResponse()) {
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include "../../proto/hedera/Response.pb.h"
|
||||
#include "ConsensusGetTopicInfoResponse.h"
|
||||
#include "Poco/Types.h"
|
||||
|
||||
namespace model {
|
||||
@ -23,9 +24,12 @@ namespace model {
|
||||
|
||||
inline proto::Response* getResponsePtr() { return &mResponseProto; }
|
||||
Poco::UInt64 getAccountBalance();
|
||||
Poco::UInt64 getQueryCost();
|
||||
proto::ResponseCodeEnum getResponseCode();
|
||||
|
||||
|
||||
inline bool isCryptoGetAccountBalanceResponse() { return mResponseProto.has_cryptogetaccountbalance(); }
|
||||
inline bool isConsensusGetTopicInfoResponse() { return mResponseProto.has_consensusgettopicinfo(); }
|
||||
|
||||
protected:
|
||||
proto::Response mResponseProto;
|
||||
|
||||
@ -8,7 +8,7 @@ namespace model {
|
||||
connection.hederaId->copyToProtoAccountId(mTransactionBody.mutable_nodeaccountid());
|
||||
auto transaction_id = mTransactionBody.mutable_transactionid();
|
||||
operatorAccountId->copyToProtoAccountId(transaction_id->mutable_accountid());
|
||||
mTransactionBody.set_transactionfee(10000);
|
||||
mTransactionBody.set_transactionfee(1000000);
|
||||
auto transaction_valid_duration = mTransactionBody.mutable_transactionvalidduration();
|
||||
transaction_valid_duration->set_seconds(120);
|
||||
|
||||
@ -36,6 +36,34 @@ namespace model {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TransactionBody::updateCryptoTransferAmount(Poco::UInt64 newAmount)
|
||||
{
|
||||
assert(mHasBody);
|
||||
|
||||
if (!mTransactionBody.has_cryptotransfer()) {
|
||||
printf("[TransactionBody::updateCryptoTransferAmount] hasn't crypto transfer\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto crypto_transfer = mTransactionBody.mutable_cryptotransfer();
|
||||
auto transfers = crypto_transfer->mutable_transfers();
|
||||
if (transfers->accountamounts_size() != 2) {
|
||||
printf("[TransactionBody::updateCryptoTransferAmount] structure not like expected, transfers has %d accountamounts\n", transfers->accountamounts_size());
|
||||
return false;
|
||||
}
|
||||
proto::AccountAmount* account_amounts[] = { transfers->mutable_accountamounts(0), transfers->mutable_accountamounts(1) };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (account_amounts[i]->amount() > 0) {
|
||||
account_amounts[i]->set_amount(newAmount);
|
||||
}
|
||||
else if (account_amounts[i]->amount() < 0) {
|
||||
account_amounts[i]->set_amount(-newAmount);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool TransactionBody::setCreateTopic(ConsensusCreateTopic& consensusCreateTopicTransaction)
|
||||
{
|
||||
if (mHasBody) {
|
||||
|
||||
@ -40,6 +40,7 @@ namespace model {
|
||||
void setFee(Poco::UInt64 fee);
|
||||
|
||||
bool setCryptoTransfer(CryptoTransferTransaction& cryptoTransferTransaction);
|
||||
bool updateCryptoTransferAmount(Poco::UInt64 newAmount);
|
||||
bool setCryptoCreate(CryptoCreateTransaction& cryptoCreateTransaction);
|
||||
bool setCreateTopic(ConsensusCreateTopic& consensusCreateTopicTransaction);
|
||||
bool setConsensusSubmitMessage(ConsensusSubmitMessage& consensusSubmitMessageTransaction);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user