mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
compose hedera query to get balance, update CMakeLists.txt for adding missing libs for grpc
This commit is contained in:
parent
5b899366d9
commit
71edd964ac
@ -95,9 +95,30 @@ find_library(MYSQL_LIBRARIES mariadbclient.lib PATHS "dependencies/mariadb-conne
|
||||
find_library(COMPILED_MARIADB_CLIENT_DEBUG mariadbclient PATHS "dependencies/mariadb-connector-c/build/libmariadb/Debug" REQUIRED)
|
||||
find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build/Debug" REQUIRED)
|
||||
set(GRPC_PATH "dependencies/grpc/_build/Debug")
|
||||
set(GRPC_ABSL_PATH "dependencies/grpc/_build/third_party/abseil-cpp/absl/types/Debug")
|
||||
set(GRPC_CARES_PATH "dependencies/grpc/_build/third_party/cares/cares/lib/Debug")
|
||||
set(GRPC_BORING_SSL_PATH "dependencies/grpc/_build/third_party/boringssl-with-bazel/Debug")
|
||||
find_library(GRPC_PLUSPLUS grpc++ PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_UNSECURE grpc++_unsecure PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_REFLECTION grpc++_reflection PATHS ${GRPC_PATH} REQUIRED)
|
||||
set(GRPC_LIBS ${GRPC_PLUSPLUS} ${GRPC_REFLECTION})
|
||||
find_library(GRPC_LIB grpc PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_ERROR_DETAILS grpc++_error_details PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_RLIB gpr PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_UPB upb PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_ALTS grpc++_alts PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_ADDRESS_SORTING address_sorting PATHS ${GRPC_PATH} REQUIRED)
|
||||
find_library(GRPC_CARES cares PATHS ${GRPC_CARES_PATH} REQUIRED)
|
||||
find_library(GRPC_BORING_SSL_CRYPTO crypto ${GRPC_BORING_SSL_PATH} REQUIRED)
|
||||
find_library(GRPC_BORING_SSL_SSL ssl ${GRPC_BORING_SSL_PATH} REQUIRED)
|
||||
|
||||
find_library(GRPC_ABSL_BAD_OPTIONAL_ACCESS absl_bad_optional_access ${GRPC_ABSL_PATH} REQUIRED)
|
||||
set(GRPC_LIBS
|
||||
${GRPC_PLUSPLUS} ${GRPC_REFLECTION} ${GRPC_UNSECURE} ${GRPC_LIB}
|
||||
${GRPC_ERROR_DETAILS} ${GRPC_RLIB} ${GRPC_UPB} ${GRPC_ALTS}
|
||||
${GRPC_ABSL_BAD_OPTIONAL_ACCESS} ${GRPC_ADDRESS_SORTING}
|
||||
${GRPC_CARES} ${GRPC_BORING_SSL_CRYPTO} ${GRPC_BORING_SSL_SSL}
|
||||
)
|
||||
|
||||
set(MYSQL_INCLUDE_DIR "dependencies/mariadb-connector-c/include")
|
||||
|
||||
#set(POCO_DEBUG_PATH "I:/FremdCode/C++/poco/win64/lib/Debug")
|
||||
@ -142,7 +163,9 @@ include_directories(
|
||||
|
||||
endif(WIN32)
|
||||
|
||||
target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519})
|
||||
add_subdirectory("dependencies/grpc/third_party/abseil-cpp")
|
||||
|
||||
target_link_libraries(Gradido_LoginServer absl::base absl::flat_hash_map absl::flags absl::memory absl::meta absl::numeric absl::strings ${CONAN_LIBS} ${IROHA_ED25519})
|
||||
if(WIN32)
|
||||
TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi)
|
||||
TARGET_LINK_LIBRARIES(Gradido_LoginServer debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi)
|
||||
|
||||
@ -37,6 +37,7 @@ public:
|
||||
|
||||
inline const unsigned char* getPublicKey() const { return mPublicKey; }
|
||||
MemoryBin* getPublicKeyCopy() const;
|
||||
const static size_t getPublicKeySize() {return ed25519_pubkey_SIZE;}
|
||||
|
||||
inline bool isTheSame(const KeyPairHedera& b) const {
|
||||
return 0 == sodium_memcmp(mPublicKey, b.mPublicKey, ed25519_pubkey_SIZE);
|
||||
|
||||
@ -14,6 +14,10 @@
|
||||
#include "../lib/DataTypeConverter.h"
|
||||
#include "../SingletonManager/SessionManager.h"
|
||||
|
||||
#include "../ServerConfig.h"
|
||||
|
||||
#include "Poco/URI.h"
|
||||
|
||||
#line 1 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\header_large.cpsp"
|
||||
|
||||
#include "../ServerConfig.h"
|
||||
@ -33,15 +37,42 @@ void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request
|
||||
if (_compressResponse) response.set("Content-Encoding", "gzip");
|
||||
|
||||
Poco::Net::HTMLForm form(request, request.stream());
|
||||
#line 16 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 20 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
|
||||
const char* pageName = "Hedera Account";
|
||||
auto sm = SessionManager::getInstance();
|
||||
auto mm = MemoryManager::getInstance();
|
||||
auto user = mSession->getNewUser();
|
||||
|
||||
Poco::URI uri(request.getURI());
|
||||
auto uri_query = uri.getQueryParameters();
|
||||
std::string action = "";
|
||||
std::string account_id_from_query;
|
||||
if(uri_query[0].first == "action") {
|
||||
action = uri_query[0].second;
|
||||
}
|
||||
if(uri_query[1].first == "account_id") {
|
||||
account_id_from_query = uri_query[1].second;
|
||||
}
|
||||
for(auto it = uri_query.begin(); it != uri_query.end(); it++) {
|
||||
printf("first: %s, second: %s\n", it->first.data(), it->second.data());
|
||||
}
|
||||
|
||||
if(action == "updateBalance") {
|
||||
int account_id = 0;
|
||||
if(DataTypeConverter::strToInt(account_id_from_query, account_id) != DataTypeConverter::NUMBER_PARSE_OKAY) {
|
||||
addError(new Error("Int Convert Error", "Error converting account_id_from_query to int"));
|
||||
} else {
|
||||
auto hedera_account = controller::HederaAccount::load("id", account_id);
|
||||
if(!hedera_account.size() || hedera_account[0].isNull()) {
|
||||
addError(new Error("Action Update Balance", "hedera id not found"));
|
||||
} else {
|
||||
hedera_account[0]->updateBalanceFromHedera(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
// add
|
||||
if(!form.empty()) {
|
||||
else if(!form.empty()) {
|
||||
// collect
|
||||
auto shardNumString = form.get("account-shard-num", "0");
|
||||
auto realmNumString = form.get("account-realm-num", "0");
|
||||
@ -196,7 +227,7 @@ void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request
|
||||
responseStream << "\t\t<div class=\"content\">";
|
||||
// end include header_large.cpsp
|
||||
responseStream << "\n";
|
||||
#line 121 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 152 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( getErrorsHtml() );
|
||||
responseStream << "\n";
|
||||
responseStream << "<div class=\"center-form-container\">\n";
|
||||
@ -210,32 +241,41 @@ void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request
|
||||
responseStream << "\t\t\t\t<div class=\"cell header-cell c3\">Balance</div>\n";
|
||||
responseStream << "\t\t\t\t<div class=\"cell header-cell c2\">Server Type</div>\n";
|
||||
responseStream << "\t\t\t\t<div class=\"cell header-cell c3\">Last Updated</div>\n";
|
||||
responseStream << "\t\t\t\t<div class=\"cell header-cell c5\">Aktionen</div>\n";
|
||||
responseStream << "\t\t\t</div>\n";
|
||||
responseStream << "\t\t\t";
|
||||
#line 134 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 166 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
for(auto it = hedera_accounts.begin(); it != hedera_accounts.end(); it++) {
|
||||
auto hedera_account_model = (*it)->getModel();
|
||||
auto updateUrl = ServerConfig::g_serverPath + "/hedera_account?action=updateBalance&account_id=" + std::to_string(hedera_account_model->getID());
|
||||
responseStream << "\n";
|
||||
responseStream << "\t\t\t\t<div class=\"row\">\n";
|
||||
responseStream << "\t\t\t\t\t<div class=\"cell c2\">";
|
||||
#line 138 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 171 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( (*it)->getHederaId()->getModel()->toString() );
|
||||
responseStream << "</div>\n";
|
||||
responseStream << "\t\t\t\t\t<div class=\"cell c3\">";
|
||||
#line 139 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 172 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( hedera_account_model->getBalanceDouble() );
|
||||
responseStream << " hbar</div>\n";
|
||||
responseStream << "\t\t\t\t\t<div class=\"cell c2\">";
|
||||
#line 140 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 173 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( model::table::HederaAccount::hederaNetworkTypeToString(hedera_account_model->getNetworkType()) );
|
||||
responseStream << "</div>\n";
|
||||
responseStream << "\t\t\t\t\t<div class=\"cell c3\">";
|
||||
#line 141 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 174 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( hedera_account_model->getUpdatedString() );
|
||||
responseStream << "</div>\n";
|
||||
responseStream << "\t\t\t\t\t<div class=\"cell c5\">\n";
|
||||
responseStream << "\t\t\t\t\t<button class=\"form-button\" title=\"Anfrage an Hedera, kostet etwas\" onclick=\"window.location.href='";
|
||||
#line 176 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( updateUrl );
|
||||
responseStream << "'\" >\n";
|
||||
responseStream << "\t\t\t\t\t\tUpdate Balance\n";
|
||||
responseStream << "\t\t\t\t\t</button>\n";
|
||||
responseStream << "\t\t\t\t</div>\n";
|
||||
responseStream << "\t\t\t";
|
||||
#line 143 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 180 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
} responseStream << "\n";
|
||||
responseStream << "\t\t</div>\n";
|
||||
responseStream << "\t</div>\n";
|
||||
@ -255,21 +295,21 @@ void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request
|
||||
responseStream << "\t\t\t<label class=\"form-label\" for=\"account-network-type\">Network Type</label>\n";
|
||||
responseStream << "\t\t\t<select class=\"form-control\" name=\"account-network-type\" id=\"account-network-type\">\n";
|
||||
responseStream << "\t\t\t";
|
||||
#line 161 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 198 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
for(int i = 0; i < model::table::HEDERA_NET_COUNT; i++) { responseStream << "\n";
|
||||
responseStream << "\t\t\t\t<option value=\"";
|
||||
#line 162 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 199 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( i );
|
||||
responseStream << "\">";
|
||||
#line 162 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 199 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( model::table::HederaAccount::hederaNetworkTypeToString((model::table::HederaNetworkType)i) );
|
||||
responseStream << "</option>\n";
|
||||
responseStream << "\t\t\t";
|
||||
#line 163 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 200 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
} responseStream << "\n";
|
||||
responseStream << "\t\t\t</select>\n";
|
||||
responseStream << "\t\t\t<input class=\"center-form-submit form-button\" type=\"submit\" name=\"submit\" value=\"";
|
||||
#line 165 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
#line 202 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp"
|
||||
responseStream << ( gettext("Add Account") );
|
||||
responseStream << "\">\n";
|
||||
responseStream << "\t</form>\n";
|
||||
|
||||
@ -62,19 +62,21 @@ namespace controller {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KeyPairHedera* CryptoKey::getKeyPair(Poco::AutoPtr<controller::User> user)
|
||||
std::unique_ptr<KeyPairHedera> CryptoKey::getKeyPair(Poco::AutoPtr<controller::User> user)
|
||||
{
|
||||
auto model = getModel();
|
||||
auto password = user->getPassword();
|
||||
auto mm = MemoryManager::getInstance();
|
||||
if (!password || !model->hasPrivateKeyEncrypted()) {
|
||||
printf("[CryptoKey::getKeyPair] return null, password empty or no private key\n");
|
||||
return nullptr;
|
||||
}
|
||||
MemoryBin* clearPassword = nullptr;
|
||||
if (password->decrypt(model->getPrivateKeyEncrypted(), &clearPassword) != SecretKeyCryptography::AUTH_DECRYPT_OK) {
|
||||
printf("[CryptoKey::getKeyPair] return null, error decrypting\n");
|
||||
return nullptr;
|
||||
}
|
||||
KeyPairHedera* key_pair = new KeyPairHedera(clearPassword, model->getPublicKey(), model->getPublicKeySize());
|
||||
auto key_pair = std::make_unique<KeyPairHedera>(clearPassword, model->getPublicKey(), model->getPublicKeySize());
|
||||
mm->releaseMemory(clearPassword);
|
||||
return key_pair;
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ namespace controller {
|
||||
|
||||
inline Poco::AutoPtr<model::table::CryptoKey> getModel() { return _getModel<model::table::CryptoKey>(); }
|
||||
|
||||
KeyPairHedera* getKeyPair(Poco::AutoPtr<controller::User> user);
|
||||
std::unique_ptr<KeyPairHedera> getKeyPair(Poco::AutoPtr<controller::User> user);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
|
||||
#include "HederaAccount.h"
|
||||
#include "NodeServer.h"
|
||||
#include "CryptoKey.h"
|
||||
#include "../model/hedera/Query.h"
|
||||
#include "HederaRequest.h"
|
||||
|
||||
namespace controller {
|
||||
|
||||
@ -69,5 +73,38 @@ namespace controller {
|
||||
return resultVector;
|
||||
}
|
||||
|
||||
bool HederaAccount::updateBalanceFromHedera(Poco::AutoPtr<controller::User> user)
|
||||
{
|
||||
static const char* functionName = "HederaAccount::updateBalanceFromHedera";
|
||||
|
||||
if (user.isNull() || !user->getModel()) {
|
||||
printf("[%s] invalid user\n", functionName);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto account_model = getModel();
|
||||
auto hedera_node = NodeServer::pick(account_model->networkTypeToNodeServerType(account_model->getNetworkType()));
|
||||
auto crypto_key = controller::CryptoKey::load(account_model->getCryptoKeyId());
|
||||
if (crypto_key.isNull()) {
|
||||
printf("[%s] error, crypto key with id: %d not found\n", functionName, account_model->getCryptoKeyId());
|
||||
return false;
|
||||
}
|
||||
auto hedera_key_pair = crypto_key->getKeyPair(user);
|
||||
if (!hedera_key_pair) {
|
||||
printf("[%s] error decrypting private key with id: %d, with user: %d\n", functionName, account_model->getCryptoKeyId(), user->getModel()->getID());
|
||||
return false;
|
||||
}
|
||||
auto query = model::hedera::Query::getBalance(mHederaID, hedera_node);
|
||||
if (!query) {
|
||||
printf("[%s] error creating query\n", functionName);
|
||||
}
|
||||
query->sign(std::move(hedera_key_pair));
|
||||
|
||||
HederaRequest request;
|
||||
request.request(query);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
#ifndef GRADIDO_LOGIN_SERVER_CONTROLLER_HEDERA_ACCOUNT_INCLUDE
|
||||
#define GRADIDO_LOGIN_SERVER_CONTROLLER_HEDERA_ACCOUNT_INCLUDE
|
||||
|
||||
#include "../controller/HederaId.h"
|
||||
#include "HederaId.h"
|
||||
#include "User.h"
|
||||
#include "../model/table/HederaAccount.h"
|
||||
|
||||
#include "Poco/SharedPtr.h"
|
||||
@ -26,6 +27,8 @@ namespace controller {
|
||||
inline void setHederaId(Poco::AutoPtr<controller::HederaId> hederaId) { mHederaID = hederaId; }
|
||||
inline Poco::AutoPtr<controller::HederaId> getHederaId() { return mHederaID; }
|
||||
|
||||
bool updateBalanceFromHedera(Poco::AutoPtr<controller::User> user);
|
||||
|
||||
protected:
|
||||
HederaAccount(model::table::HederaAccount* dbModel);
|
||||
Poco::AutoPtr<controller::HederaId> mHederaID;
|
||||
|
||||
@ -29,4 +29,12 @@ namespace controller {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void HederaId::copyToProtoAccountId(proto::AccountID* protoAccountId) const
|
||||
{
|
||||
auto model = getModel();
|
||||
protoAccountId->set_shardnum(model->getShardNum());
|
||||
protoAccountId->set_realmnum(model->getRealmNum());
|
||||
protoAccountId->set_accountnum(model->getNum());
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,8 @@
|
||||
|
||||
#include "TableControllerBase.h"
|
||||
|
||||
#include "../proto/hedera/BasicTypes.pb.h"
|
||||
|
||||
namespace controller {
|
||||
class HederaId : public TableControllerBase
|
||||
{
|
||||
@ -21,6 +23,9 @@ namespace controller {
|
||||
inline bool deleteFromDB() { return mDBModel->deleteFromDB(); }
|
||||
|
||||
inline Poco::AutoPtr<model::table::HederaId> getModel() { return _getModel<model::table::HederaId>(); }
|
||||
inline const model::table::HederaId* getModel() const { return _getModel<model::table::HederaId>(); }
|
||||
|
||||
void copyToProtoAccountId(proto::AccountID* protoAccountId) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -15,6 +15,8 @@ namespace controller {
|
||||
NodeServerConnection(const std::string& _url, int _port) : url(_url), port(_port) {}
|
||||
NodeServerConnection() :port(0) {};
|
||||
|
||||
std::string getUrlWithPort() const { return url + ":" + std::to_string(port); }
|
||||
|
||||
bool isValid() { return url != "" && port; }
|
||||
std::string url;
|
||||
int port;
|
||||
@ -35,7 +37,7 @@ namespace controller {
|
||||
static std::vector<Poco::AutoPtr<NodeServer>> load(model::table::NodeServerType type, int group_id = 0);
|
||||
static std::vector<Poco::AutoPtr<NodeServer>> listAll();
|
||||
// pick server randomly
|
||||
NodeServerConnection pick(model::table::NodeServerType type, int group_id = 0);
|
||||
static NodeServerConnection pick(model::table::NodeServerType type, int group_id = 0);
|
||||
inline bool deleteFromDB() { return mDBModel->deleteFromDB(); }
|
||||
|
||||
inline Poco::AutoPtr<model::table::NodeServer> getModel() { return _getModel<model::table::NodeServer>(); }
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include "model/table/EmailOptIn.h"
|
||||
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include <grpc/grpc.h>
|
||||
|
||||
#ifndef _TEST_BUILD
|
||||
|
||||
@ -35,8 +36,8 @@ int main(int argc, char** argv)
|
||||
ServerConfig::g_versionString = Poco::DateTimeFormatter::format(buildDateTime, "0.%y.%m.%d");
|
||||
//ServerConfig::g_versionString = "0.20.KW13.02";
|
||||
printf("Version: %s\n", ServerConfig::g_versionString.data());
|
||||
printf("User size: %d Bytes, Session size: %d Bytes\n", sizeof(User), sizeof(Session));
|
||||
printf("model sizes: User: %d Bytes, EmailOptIn: %d Bytes\n", sizeof(model::table::User), sizeof(model::table::EmailOptIn));
|
||||
printf("User size: %d Bytes, Session size: %d Bytes\n", (int)sizeof(User), (int)sizeof(Session));
|
||||
printf("model sizes: User: %d Bytes, EmailOptIn: %d Bytes\n", (int)sizeof(model::table::User), (int)sizeof(model::table::EmailOptIn));
|
||||
|
||||
// load word lists
|
||||
if (!ServerConfig::loadMnemonicWordLists()) {
|
||||
@ -49,8 +50,12 @@ int main(int argc, char** argv)
|
||||
printf("test passphrase generation and transformation failed\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
grpc_init();
|
||||
|
||||
Gradido_LoginServer app;
|
||||
return app.run(argc, argv);
|
||||
auto result = app.run(argc, argv);
|
||||
|
||||
grpc_shutdown();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,83 @@
|
||||
#include "Query.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "../../SingletonManager/MemoryManager.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
|
||||
Query::Query(const controller::NodeServerConnection& connection)
|
||||
: mConnection(connection)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Query::~Query()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Query* Query::getBalance(Poco::AutoPtr<controller::HederaId> accountId, const controller::NodeServerConnection& connection)
|
||||
{
|
||||
|
||||
assert(!accountId.isNull() && accountId->getModel());
|
||||
|
||||
auto query = new Query(connection);
|
||||
auto get_account_balance = query->mQueryProto.mutable_cryptogetaccountbalance();
|
||||
accountId->copyToProtoAccountId(get_account_balance->mutable_accountid());
|
||||
auto query_header = get_account_balance->mutable_header();
|
||||
query_header->set_responsetype(proto::ANSWER_ONLY);
|
||||
auto transaction = query_header->mutable_payment();
|
||||
//auto transaction_body = transaction->mutable_body();
|
||||
// body content
|
||||
// transaction id
|
||||
auto transaction_id = query->mTransactionBody.mutable_transactionid();
|
||||
auto timestamp = transaction_id->mutable_transactionvalidstart();
|
||||
Poco::Timestamp now;
|
||||
auto microseconds = now.epochMicroseconds() - now.epochTime() * now.resolution(); // 1*10^6
|
||||
timestamp->set_seconds(now.epochTime());
|
||||
timestamp->set_nanos(microseconds * 1000);
|
||||
accountId->copyToProtoAccountId(transaction_id->mutable_accountid());
|
||||
//
|
||||
// sdk default, but can be changed
|
||||
query->mTransactionBody.set_transactionfee(100000000);
|
||||
auto valid_duration = query->mTransactionBody.mutable_transactionvalidduration();
|
||||
// maximal 2 minutes
|
||||
valid_duration->set_seconds(120);
|
||||
auto crypto_transfer = query->mTransactionBody.mutable_cryptotransfer();
|
||||
auto transfer_list = crypto_transfer->mutable_transfers();
|
||||
auto account_amounts = transfer_list->mutable_accountamounts();
|
||||
account_amounts->Add();
|
||||
auto account_amount = account_amounts->Mutable(0);
|
||||
account_amount->set_amount(0);
|
||||
connection.hederaId->copyToProtoAccountId(account_amount->mutable_accountid());
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
bool Query::sign(std::unique_ptr<KeyPairHedera> keyPairHedera)
|
||||
{
|
||||
auto mm = MemoryManager::getInstance();
|
||||
auto body_bytes = mTransactionBody.SerializeAsString();
|
||||
auto transaction = mQueryProto.mutable_cryptogetaccountbalance()->mutable_header()->mutable_payment();
|
||||
transaction->set_bodybytes(body_bytes.data());
|
||||
auto signature_map = transaction->mutable_sigmap();
|
||||
auto signature_pairs = signature_map->mutable_sigpair();
|
||||
signature_pairs->Add();
|
||||
auto signature_pair = signature_pairs->Mutable(0);
|
||||
auto public_key = keyPairHedera->getPublicKey();
|
||||
|
||||
|
||||
auto sign = keyPairHedera->sign(body_bytes);
|
||||
if (!sign) {
|
||||
printf("[Query::sign] error signing message\n");
|
||||
return false;
|
||||
}
|
||||
signature_pair->set_pubkeyprefix(public_key, keyPairHedera->getPublicKeySize());
|
||||
signature_pair->set_ed25519(*sign, sign->size());
|
||||
|
||||
mm->releaseMemory(sign);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
#ifndef _GRADIDO_LOGIN_SERVER_MODEL_HEDERA_QUERY_H
|
||||
#define _GRADIDO_LOGIN_SERVER_MODEL_HEDERA_QUERY_H
|
||||
|
||||
/*!
|
||||
* @author: Dario Rekowski
|
||||
*
|
||||
* @date: 31.08.20
|
||||
*
|
||||
* @brief: class for put together hedera querys (ask for state data, not a transaction, but needs a payment transaction)
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../proto/hedera/Query.pb.h"
|
||||
#include "../../controller/NodeServer.h"
|
||||
#include "../../Crypto/KeyPairHedera.h"
|
||||
|
||||
namespace model {
|
||||
namespace hedera {
|
||||
class Query
|
||||
{
|
||||
public:
|
||||
~Query();
|
||||
static Query* getBalance(Poco::AutoPtr<controller::HederaId> accountId, const controller::NodeServerConnection& connection);
|
||||
bool sign(std::unique_ptr<KeyPairHedera> keyPairHedera);
|
||||
|
||||
inline const proto::Query* getProtoQuery() const { return &mQueryProto; }
|
||||
inline std::string getConnectionString() const { return mConnection.getUrlWithPort(); }
|
||||
|
||||
protected:
|
||||
Query(const controller::NodeServerConnection& connection);
|
||||
proto::Query mQueryProto;
|
||||
proto::TransactionBody mTransactionBody;
|
||||
controller::NodeServerConnection mConnection;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //_GRADIDO_LOGIN_SERVER_MODEL_HEDERA_QUERY_H
|
||||
@ -53,6 +53,15 @@ namespace model {
|
||||
}
|
||||
}
|
||||
|
||||
NodeServerType HederaAccount::networkTypeToNodeServerType(HederaNetworkType type)
|
||||
{
|
||||
switch (type) {
|
||||
case HEDERA_MAINNET: return NODE_SERVER_HEDERA_MAINNET_NODE;
|
||||
case HEDERA_TESTNET: return NODE_SERVER_HEDERA_TESTNET_NODE;
|
||||
default: return NODE_SERVER_TYPE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
Poco::Data::Statement HederaAccount::_loadFromDB(Poco::Data::Session session, const std::string& fieldName)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
#include "ModelBase.h"
|
||||
#include "Poco/Tuple.h"
|
||||
|
||||
#include "NodeServer.h"
|
||||
|
||||
namespace model {
|
||||
namespace table {
|
||||
|
||||
@ -12,7 +14,7 @@ namespace model {
|
||||
enum HederaNetworkType {
|
||||
HEDERA_MAINNET,
|
||||
HEDERA_TESTNET,
|
||||
HEDERA_NET_COUNT
|
||||
HEDERA_NET_COUNT,
|
||||
};
|
||||
|
||||
class HederaAccount : public ModelBase
|
||||
@ -28,13 +30,16 @@ namespace model {
|
||||
std::string toString();
|
||||
|
||||
static const char* hederaNetworkTypeToString(HederaNetworkType type);
|
||||
static NodeServerType networkTypeToNodeServerType(HederaNetworkType type);
|
||||
|
||||
inline int getAccountHederaId() { return mAccountHederaId; }
|
||||
inline int getAccountHederaId() const { return mAccountHederaId; }
|
||||
inline int getCryptoKeyId() const { return mAccountKeyId; }
|
||||
|
||||
inline Poco::UInt64 getBalance() { return mBalance; }
|
||||
inline double getBalanceDouble() { return (double)mBalance / 100000000.0; }
|
||||
|
||||
inline HederaNetworkType getNetworkType() { return (HederaNetworkType)mType; }
|
||||
|
||||
|
||||
inline std::string getUpdatedString() { return Poco::DateTimeFormatter::format(mUpdated, "%f.%m.%Y %H:%M:%S"); }
|
||||
|
||||
|
||||
@ -21,6 +21,10 @@ namespace model {
|
||||
//! \brief check if hedera id already in db, then return id, else insert in db and return
|
||||
int getID();
|
||||
|
||||
inline Poco::UInt64 getShardNum() const { return mShardNum; }
|
||||
inline Poco::UInt64 getRealmNum() const { return mRealmNum; }
|
||||
inline Poco::UInt64 getNum() const { return mNum; }
|
||||
|
||||
|
||||
protected:
|
||||
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||
|
||||
@ -15,7 +15,8 @@ namespace model {
|
||||
NODE_SERVER_GRADIDO_COMMUNITY,
|
||||
NODE_SERVER_HEDERA_MAINNET_NODE,
|
||||
NODE_SERVER_HEDERA_TESTNET_NODE,
|
||||
NODE_SERVER_TYPE_COUNT
|
||||
NODE_SERVER_TYPE_COUNT,
|
||||
NODE_SERVER_TYPE_NONE
|
||||
};
|
||||
bool NodeServerIsHederaNode(NodeServerType type);
|
||||
bool NodeServerHasGroup(NodeServerType type);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user