mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
work on hedera task for hedera transactions async
This commit is contained in:
parent
5182953d0f
commit
4ece67c057
@ -58,6 +58,8 @@ namespace model {
|
||||
auto signature_pair = signature_pairs->Mutable(0);
|
||||
auto public_key = keyPairHedera->getPublicKey();
|
||||
|
||||
mTransactionId = transactionBody->getProtoTransactionBody()->transactionid();
|
||||
|
||||
auto sign = keyPairHedera->sign(body_bytes);
|
||||
if (!sign) {
|
||||
printf("[Query::sign] error signing message\n");
|
||||
|
||||
@ -29,11 +29,13 @@ namespace model {
|
||||
inline std::string getConnectionString() const { return mConnection.getUriWithPort(); }
|
||||
void resetPointer() { mTransaction = nullptr; }
|
||||
inline TransactionBodyType getType() const { return mType; }
|
||||
inline proto::TransactionID getTransactionId() const { return mTransactionId; }
|
||||
|
||||
protected:
|
||||
proto::Transaction* mTransaction;
|
||||
controller::NodeServerConnection mConnection;
|
||||
TransactionBodyType mType;
|
||||
proto::TransactionID mTransactionId;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
16
src/cpp/model/hedera/TransactionReceipt.cpp
Normal file
16
src/cpp/model/hedera/TransactionReceipt.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "TransactionReceipt.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
|
||||
TransactionReceipt::TransactionReceipt()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TransactionReceipt::~TransactionReceipt()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/cpp/model/hedera/TransactionReceipt.h
Normal file
23
src/cpp/model/hedera/TransactionReceipt.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_MODEL_HEDERA_TRANSACTION_RECEIPT_H
|
||||
#define __GRADIDO_LOGIN_SERVER_MODEL_HEDERA_TRANSACTION_RECEIPT_H
|
||||
|
||||
#include "../proto/hedera/TransactionReceipt.pb.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
class TransactionReceipt
|
||||
{
|
||||
public:
|
||||
TransactionReceipt();
|
||||
~TransactionReceipt();
|
||||
|
||||
inline proto::TransactionReceipt* getProto() { return &mProtoReceipt; }
|
||||
|
||||
protected:
|
||||
proto::TransactionReceipt mProtoReceipt;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_MODEL_HEDERA_TRANSACTION_RECEIPT_H
|
||||
0
src/cpp/model/hedera/TransactionRecord.cpp
Normal file
0
src/cpp/model/hedera/TransactionRecord.cpp
Normal file
0
src/cpp/model/hedera/TransactionRecord.h
Normal file
0
src/cpp/model/hedera/TransactionRecord.h
Normal file
@ -0,0 +1,45 @@
|
||||
#include "HederaTask.h"
|
||||
#include "../lib/DataTypeConverter.h"
|
||||
|
||||
#include "../proto/hedera/TransactionGetReceipt.pb.h"
|
||||
|
||||
HederaTask::HederaTask()
|
||||
: mTransactionReceipt(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HederaTask::~HederaTask()
|
||||
{
|
||||
if (mTransactionReceipt) {
|
||||
delete mTransactionReceipt;
|
||||
mTransactionReceipt = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool HederaTask::isTimeout()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> _lock(mWorkingMutex);
|
||||
auto valid_start = mTransactionID.transactionvalidstart();
|
||||
auto poco_timestamp = DataTypeConverter::convertFromProtoTimestamp(valid_start);
|
||||
auto poco_duration = DataTypeConverter::convertFromProtoDuration(mValidDuration);
|
||||
return (poco_timestamp + poco_duration) > Poco::Timestamp();
|
||||
}
|
||||
|
||||
void HederaTask::setTransactionReceipt(model::hedera::TransactionReceipt* transactionReceipt)
|
||||
{
|
||||
assert(transactionReceipt);
|
||||
|
||||
std::unique_lock<std::shared_mutex> _lock(mWorkingMutex);
|
||||
if (mTransactionReceipt) {
|
||||
printf("[HederaTask::setTransactionReceipt] warning, receipt already set\n");
|
||||
delete mTransactionReceipt;
|
||||
}
|
||||
mTransactionReceipt = transactionReceipt;
|
||||
}
|
||||
|
||||
bool HederaTask::tryQueryReceipt()
|
||||
{
|
||||
proto::TransactionGetReceiptQuery get_receipt_query;
|
||||
return true;
|
||||
}
|
||||
@ -2,14 +2,48 @@
|
||||
#define __GRADIDO_LOGIN_TASKS_HEDERA_TASKS_H
|
||||
|
||||
#include "../model/hedera/TransactionResponse.h"
|
||||
#include "../model/hedera/TransactionReceipt.h"
|
||||
#include "../proto/hedera/BasicTypes.pb.h"
|
||||
#include "../proto/hedera/Duration.pb.h"
|
||||
|
||||
#include "Poco/Timestamp.h"
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
class HederaTask
|
||||
{
|
||||
public:
|
||||
inline model::hedera::TransactionResponse* getTransactionResponse() { return &mTransactionResponse; }
|
||||
|
||||
HederaTask();
|
||||
~HederaTask();
|
||||
|
||||
inline model::hedera::TransactionResponse* getTransactionResponse() { std::shared_lock<std::shared_mutex> _lock(mWorkingMutex); return &mTransactionResponse; }
|
||||
inline void setTransactionId(const proto::TransactionID& transactionId) { std::unique_lock<std::shared_mutex> _lock(mWorkingMutex); mTransactionID = transactionId; }
|
||||
inline void setValidDuration(const proto::Duration& validDuration) { std::unique_lock<std::shared_mutex> _lock(mWorkingMutex); mValidDuration = validDuration; }
|
||||
//! \param transactionReceipt take ownership and call delete if done
|
||||
void setTransactionReceipt(model::hedera::TransactionReceipt* transactionReceipt);
|
||||
|
||||
inline const proto::TransactionID& getTransactionId() const { std::shared_lock<std::shared_mutex> _lock(mWorkingMutex); return mTransactionID; }
|
||||
inline const proto::Duration& getDuration() const { std::shared_lock<std::shared_mutex> _lock(mWorkingMutex); return mValidDuration; }
|
||||
inline const model::hedera::TransactionReceipt* getTransactionReceipt() const{ std::shared_lock<std::shared_mutex> _lock(mWorkingMutex); return mTransactionReceipt; }
|
||||
|
||||
//! \ brief return true if transactionValidStart + validDuration > now
|
||||
bool isTimeout();
|
||||
|
||||
bool tryQueryReceipt();
|
||||
|
||||
|
||||
protected:
|
||||
model::hedera::TransactionResponse mTransactionResponse;
|
||||
model::hedera::TransactionReceipt* mTransactionReceipt;
|
||||
|
||||
proto::TransactionID mTransactionID;
|
||||
proto::Duration mValidDuration;
|
||||
|
||||
// last time checked if transaction receipt is available
|
||||
Poco::Timestamp mLastCheck;
|
||||
|
||||
mutable std::shared_mutex mWorkingMutex;
|
||||
};
|
||||
|
||||
#endif //__GRADIDO_LOGIN_TASKS_HEDERA_TASKS_H
|
||||
@ -1,5 +1,8 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "SigningTransaction.h"
|
||||
|
||||
|
||||
#include <google/protobuf/text_format.h>
|
||||
|
||||
#include "../SingletonManager/ErrorManager.h"
|
||||
@ -184,7 +187,8 @@ int SigningTransaction::run() {
|
||||
}
|
||||
else {
|
||||
auto hedera_precheck_code_string = hedera_task.getTransactionResponse()->getPrecheckCodeString();
|
||||
printf("hedera response: %s\n", hedera_precheck_code_string.data());
|
||||
auto cost = hedera_task.getTransactionResponse()->getCost();
|
||||
printf("hedera response: %s, cost: %" PRIu64 "\n", hedera_precheck_code_string.data(), cost);
|
||||
}
|
||||
//model::hedera::TransactionBody hedera_transaction_body()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user