diff --git a/CMakeLists.txt b/CMakeLists.txt index b16d3bb4e..f246d7e52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/cpp/Crypto/KeyPairHedera.h b/src/cpp/Crypto/KeyPairHedera.h index 7f0b7f3bc..a3e4337e5 100644 --- a/src/cpp/Crypto/KeyPairHedera.h +++ b/src/cpp/Crypto/KeyPairHedera.h @@ -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); diff --git a/src/cpp/HTTPInterface/AdminHederaAccountPage.cpp b/src/cpp/HTTPInterface/AdminHederaAccountPage.cpp index 0de7a6922..0169083ef 100644 --- a/src/cpp/HTTPInterface/AdminHederaAccountPage.cpp +++ b/src/cpp/HTTPInterface/AdminHederaAccountPage.cpp @@ -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
"; // 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 << "
\n"; @@ -210,32 +241,41 @@ void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request responseStream << "\t\t\t\t
Balance
\n"; responseStream << "\t\t\t\t
Server Type
\n"; responseStream << "\t\t\t\t
Last Updated
\n"; + responseStream << "\t\t\t\t
Aktionen
\n"; responseStream << "\t\t\t
\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
\n"; responseStream << "\t\t\t\t\t
"; -#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 << "
\n"; responseStream << "\t\t\t\t\t
"; -#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
\n"; responseStream << "\t\t\t\t\t
"; -#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 << "
\n"; responseStream << "\t\t\t\t\t
"; -#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 << "
\n"; + responseStream << "\t\t\t\t\t
\n"; + responseStream << "\t\t\t\t\t\n"; responseStream << "\t\t\t\t
\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
\n"; responseStream << "\t
\n"; @@ -255,21 +295,21 @@ void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request responseStream << "\t\t\t\n"; responseStream << "\t\t\t\n"; responseStream << "\t\t\t\n"; responseStream << "\t\n"; diff --git a/src/cpp/controller/CryptoKey.cpp b/src/cpp/controller/CryptoKey.cpp index 093a21e69..3fabc25c5 100644 --- a/src/cpp/controller/CryptoKey.cpp +++ b/src/cpp/controller/CryptoKey.cpp @@ -62,19 +62,21 @@ namespace controller { return nullptr; } - KeyPairHedera* CryptoKey::getKeyPair(Poco::AutoPtr user) + std::unique_ptr CryptoKey::getKeyPair(Poco::AutoPtr 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(clearPassword, model->getPublicKey(), model->getPublicKeySize()); mm->releaseMemory(clearPassword); return key_pair; } diff --git a/src/cpp/controller/CryptoKey.h b/src/cpp/controller/CryptoKey.h index 12bb40e70..fc69d042c 100644 --- a/src/cpp/controller/CryptoKey.h +++ b/src/cpp/controller/CryptoKey.h @@ -27,7 +27,7 @@ namespace controller { inline Poco::AutoPtr getModel() { return _getModel(); } - KeyPairHedera* getKeyPair(Poco::AutoPtr user); + std::unique_ptr getKeyPair(Poco::AutoPtr user); protected: diff --git a/src/cpp/controller/HederaAccount.cpp b/src/cpp/controller/HederaAccount.cpp index 9f4ff5b40..564752f72 100644 --- a/src/cpp/controller/HederaAccount.cpp +++ b/src/cpp/controller/HederaAccount.cpp @@ -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 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; + } + } diff --git a/src/cpp/controller/HederaAccount.h b/src/cpp/controller/HederaAccount.h index dd4c97435..1a3fd9ace 100644 --- a/src/cpp/controller/HederaAccount.h +++ b/src/cpp/controller/HederaAccount.h @@ -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 hederaId) { mHederaID = hederaId; } inline Poco::AutoPtr getHederaId() { return mHederaID; } + bool updateBalanceFromHedera(Poco::AutoPtr user); + protected: HederaAccount(model::table::HederaAccount* dbModel); Poco::AutoPtr mHederaID; diff --git a/src/cpp/controller/HederaId.cpp b/src/cpp/controller/HederaId.cpp index e6d281907..ce171a7a8 100644 --- a/src/cpp/controller/HederaId.cpp +++ b/src/cpp/controller/HederaId.cpp @@ -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()); + } } \ No newline at end of file diff --git a/src/cpp/controller/HederaId.h b/src/cpp/controller/HederaId.h index f02e69373..ae9296a43 100644 --- a/src/cpp/controller/HederaId.h +++ b/src/cpp/controller/HederaId.h @@ -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 getModel() { return _getModel(); } + inline const model::table::HederaId* getModel() const { return _getModel(); } + + void copyToProtoAccountId(proto::AccountID* protoAccountId) const; protected: diff --git a/src/cpp/controller/NodeServer.h b/src/cpp/controller/NodeServer.h index 5a2750194..8cc4b4e23 100644 --- a/src/cpp/controller/NodeServer.h +++ b/src/cpp/controller/NodeServer.h @@ -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> load(model::table::NodeServerType type, int group_id = 0); static std::vector> 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 getModel() { return _getModel(); } diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 715352f91..910db09ff 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -13,6 +13,7 @@ #include "model/table/EmailOptIn.h" #include "Poco/DateTimeParser.h" +#include #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 \ No newline at end of file diff --git a/src/cpp/model/hedera/Query.cpp b/src/cpp/model/hedera/Query.cpp index e69de29bb..d47449bc6 100644 --- a/src/cpp/model/hedera/Query.cpp +++ b/src/cpp/model/hedera/Query.cpp @@ -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 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) + { + 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; + } + } +} \ No newline at end of file diff --git a/src/cpp/model/hedera/Query.h b/src/cpp/model/hedera/Query.h index e69de29bb..8dff35024 100644 --- a/src/cpp/model/hedera/Query.h +++ b/src/cpp/model/hedera/Query.h @@ -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 accountId, const controller::NodeServerConnection& connection); + bool sign(std::unique_ptr 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 \ No newline at end of file diff --git a/src/cpp/model/table/HederaAccount.cpp b/src/cpp/model/table/HederaAccount.cpp index 06538fdcb..1485ff554 100644 --- a/src/cpp/model/table/HederaAccount.cpp +++ b/src/cpp/model/table/HederaAccount.cpp @@ -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); diff --git a/src/cpp/model/table/HederaAccount.h b/src/cpp/model/table/HederaAccount.h index c38af1df1..4d4dd6575 100644 --- a/src/cpp/model/table/HederaAccount.h +++ b/src/cpp/model/table/HederaAccount.h @@ -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"); } diff --git a/src/cpp/model/table/HederaId.h b/src/cpp/model/table/HederaId.h index 8de69c2a9..9dc2029bc 100644 --- a/src/cpp/model/table/HederaId.h +++ b/src/cpp/model/table/HederaId.h @@ -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); diff --git a/src/cpp/model/table/NodeServer.h b/src/cpp/model/table/NodeServer.h index 899be9196..4e592c822 100644 --- a/src/cpp/model/table/NodeServer.h +++ b/src/cpp/model/table/NodeServer.h @@ -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);