diff --git a/skeema/gradido_login/crypto_keys.sql b/skeema/gradido_login/crypto_keys.sql index 971c56a7b..43b511db2 100644 --- a/skeema/gradido_login/crypto_keys.sql +++ b/skeema/gradido_login/crypto_keys.sql @@ -1,7 +1,7 @@ CREATE TABLE `crypto_keys` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `private_key` VARBINARY(64) NOT NULL, - `public_key` BINARY(32) NOT NULL, - `crypto_key_type_id` INT NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; + `id` int unsigned NOT NULL AUTO_INCREMENT, + `private_key` varbinary(64) NOT NULL, + `public_key` binary(32) NOT NULL, + `crypto_key_type_id` int NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/skeema/gradido_login/elopage_buys.sql b/skeema/gradido_login/elopage_buys.sql index be3464846..0be79a34b 100644 --- a/skeema/gradido_login/elopage_buys.sql +++ b/skeema/gradido_login/elopage_buys.sql @@ -1,15 +1,15 @@ CREATE TABLE `elopage_buys` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `elopage_user_id` int NOT NULL, `affiliate_program_id` int NOT NULL, `publisher_id` int NOT NULL, `order_id` int NOT NULL, `product_id` int NOT NULL, `product_price` int NOT NULL, - `payer_email` varchar(255) COLLATE utf8_bin NOT NULL, - `publisher_email` varchar(255) COLLATE utf8_bin NOT NULL, + `payer_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `publisher_email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `payed` tinyint NOT NULL, `success_date` datetime NOT NULL, - `event` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `event` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/skeema/gradido_login/email_opt_in.sql b/skeema/gradido_login/email_opt_in.sql index 1589093e8..da4288475 100644 --- a/skeema/gradido_login/email_opt_in.sql +++ b/skeema/gradido_login/email_opt_in.sql @@ -1,11 +1,11 @@ CREATE TABLE `email_opt_in` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `verification_code` bigint unsigned NOT NULL, `email_opt_in_type_id` int NOT NULL, - `created` datetime NOT NULL DEFAULT current_timestamp(), - `resend_count` int DEFAULT 0, - `updated` DATETIME on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `resend_count` int DEFAULT '0', + `updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `verification_code` (`verification_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/skeema/gradido_login/email_opt_in_types.sql b/skeema/gradido_login/email_opt_in_types.sql index f46275727..dbcd2d272 100644 --- a/skeema/gradido_login/email_opt_in_types.sql +++ b/skeema/gradido_login/email_opt_in_types.sql @@ -1,5 +1,5 @@ CREATE TABLE `email_opt_in_types` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` varchar(255) NOT NULL, PRIMARY KEY (`id`) diff --git a/skeema/gradido_login/groups.sql b/skeema/gradido_login/groups.sql index c3d0bc787..8c5e143bb 100644 --- a/skeema/gradido_login/groups.sql +++ b/skeema/gradido_login/groups.sql @@ -1,7 +1,8 @@ -CREATE TABLE `groups` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `alias` VARCHAR(255) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `description` TEXT NULL DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file +CREATE TABLE `groups` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `alias` varchar(190) NOT NULL, + `name` varchar(255) NOT NULL, + `description` text, + PRIMARY KEY (`id`), + UNIQUE KEY `alias` (`alias`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/skeema/gradido_login/hedera_accounts.sql b/skeema/gradido_login/hedera_accounts.sql index fc2ad9735..23ffa33d1 100644 --- a/skeema/gradido_login/hedera_accounts.sql +++ b/skeema/gradido_login/hedera_accounts.sql @@ -1,9 +1,11 @@ CREATE TABLE `hedera_accounts` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `user_id` INT UNSIGNED NOT NULL, - `account_hedera_id` INT UNSIGNED NOT NULL, - `account_key_id` INT UNSIGNED NOT NULL, - `balance` BIGINT UNSIGNED NOT NULL DEFAULT '0', - `updated` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; + `id` int unsigned NOT NULL AUTO_INCREMENT, + `user_id` int unsigned NOT NULL, + `account_hedera_id` int unsigned NOT NULL, + `account_key_id` int unsigned NOT NULL, + `balance` bigint unsigned NOT NULL DEFAULT '0', + `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `account_hedera_id` (`account_hedera_id`), + UNIQUE KEY `account_key_id` (`account_key_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/skeema/gradido_login/hedera_ids.sql b/skeema/gradido_login/hedera_ids.sql index 624a02207..b5fd26682 100644 --- a/skeema/gradido_login/hedera_ids.sql +++ b/skeema/gradido_login/hedera_ids.sql @@ -1,7 +1,7 @@ -CREATE TABLE `hedera_ids` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `shardNum` BIGINT NOT NULL DEFAULT '0', - `realmNum` BIGINT NOT NULL DEFAULT '0', - `num` BIGINT NOT NULL, - PRIMARY KEY (`id`) -) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file +CREATE TABLE `hedera_ids` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `shardNum` bigint NOT NULL DEFAULT '0', + `realmNum` bigint NOT NULL DEFAULT '0', + `num` bigint NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/skeema/gradido_login/hedera_topics.sql b/skeema/gradido_login/hedera_topics.sql index c1fa90f2b..6a58174c1 100644 --- a/skeema/gradido_login/hedera_topics.sql +++ b/skeema/gradido_login/hedera_topics.sql @@ -1,13 +1,14 @@ CREATE TABLE `hedera_topics` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `topic_hedera_id` INT UNSIGNED NOT NULL, - `auto_renew_account_hedera_id` INT UNSIGNED NULL, - `auto_renew_period` INT UNSIGNED NOT NULL DEFAULT '0', - `group_id` INT UNSIGNED NOT NULL, - `admin_key_id` INT UNSIGNED NULL, - `submit_key_id` INT UNSIGNED NULL, - `current_timeout` BIGINT UNSIGNED NOT NULL DEFAULT '0', - `sequence_number` BIGINT UNSIGNED NULL DEFAULT '0', - `updated` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; + `id` int unsigned NOT NULL AUTO_INCREMENT, + `topic_hedera_id` int unsigned NOT NULL, + `auto_renew_account_hedera_id` int unsigned DEFAULT NULL, + `auto_renew_period` int unsigned NOT NULL DEFAULT '0', + `group_id` int unsigned NOT NULL, + `admin_key_id` int unsigned DEFAULT NULL, + `submit_key_id` int unsigned DEFAULT NULL, + `current_timeout` timestamp NOT NULL DEFAULT '0', + `sequence_number` bigint unsigned DEFAULT '0', + `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `topic_hedera_id` (`topic_hedera_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/skeema/gradido_login/roles.sql b/skeema/gradido_login/roles.sql index b9d51dd11..c99223961 100644 --- a/skeema/gradido_login/roles.sql +++ b/skeema/gradido_login/roles.sql @@ -1,7 +1,7 @@ CREATE TABLE `roles` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` varchar(255) NOT NULL, - `flags` bigint NOT NULL DEFAULT 0, + `flags` bigint NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/skeema/gradido_login/user_backups.sql b/skeema/gradido_login/user_backups.sql index 699c9a2c6..7e3b7d85a 100644 --- a/skeema/gradido_login/user_backups.sql +++ b/skeema/gradido_login/user_backups.sql @@ -1,5 +1,5 @@ CREATE TABLE `user_backups` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `passphrase` text NOT NULL, `mnemonic_type` int DEFAULT '-1', diff --git a/skeema/gradido_login/user_roles.sql b/skeema/gradido_login/user_roles.sql index ac9f0834c..a92154ce8 100644 --- a/skeema/gradido_login/user_roles.sql +++ b/skeema/gradido_login/user_roles.sql @@ -1,5 +1,5 @@ CREATE TABLE `user_roles` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `role_id` int NOT NULL, PRIMARY KEY (`id`) diff --git a/skeema/gradido_login/users.sql b/skeema/gradido_login/users.sql index 172f34b56..e3c7deec5 100644 --- a/skeema/gradido_login/users.sql +++ b/skeema/gradido_login/users.sql @@ -1,16 +1,16 @@ CREATE TABLE `users` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `id` int unsigned NOT NULL AUTO_INCREMENT, `email` varchar(191) NOT NULL, `first_name` varchar(150) NOT NULL, `last_name` varchar(255) DEFAULT '', `password` bigint unsigned NOT NULL, `pubkey` binary(32) DEFAULT NULL, `privkey` binary(80) DEFAULT NULL, - `created` datetime NOT NULL DEFAULT current_timestamp(), - `email_checked` tinyint NOT NULL DEFAULT 0, - `passphrase_shown` tinyint NOT NULL DEFAULT 0, + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `email_checked` tinyint NOT NULL DEFAULT '0', + `passphrase_shown` tinyint NOT NULL DEFAULT '0', `language` varchar(4) NOT NULL DEFAULT 'de', - `disabled` BOOLEAN NULL DEFAULT FALSE, + `disabled` tinyint DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/src/cpp/model/table/CryptoKeys.cpp b/src/cpp/model/table/CryptoKeys.cpp index e69de29bb..e159f51cc 100644 --- a/src/cpp/model/table/CryptoKeys.cpp +++ b/src/cpp/model/table/CryptoKeys.cpp @@ -0,0 +1,70 @@ +#include "CryptoKeys.h" +#include "../../lib/DataTypeConverter.h" +using namespace Poco::Data::Keywords; + +namespace model { + namespace table { + CryptoKeys::CryptoKeys() + { + + } + + CryptoKeys::~CryptoKeys() + { + + } + + std::string CryptoKeys::toString() + { + assert(mKeyType < KEY_TYPE_COUNT && mKeyType >= 0); + std::stringstream ss; + ss << "Key Type: " << typeToString(static_cast(mKeyType)) << std::endl; + ss << "Public Key: " << DataTypeConverter::binToHex(mPublicKey); + return ss.str(); + } + + + const char* CryptoKeys::typeToString(KeyType type) + { + switch (type) { + case KEY_TYPE_ED25519_REF10: return "ed25519 ref10"; + case KEY_TYPE_SODIUM_ED25519: return "sodium ed22519"; + } + return ""; + } + + Poco::Data::Statement CryptoKeys::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) + { + Poco::Data::Statement select(session); + + select << "SELECT id, private_key, public_key, crypto_key_type_id FROM " << getTableName() + << " where " << fieldName << " = ?" + , into(mID), into(mPrivateKey), into(mPublicKey), into(mKeyType); + + return select; + } + + Poco::Data::Statement CryptoKeys::_loadIdFromDB(Poco::Data::Session session) + { + Poco::Data::Statement select(session); + lock(); + select << "SELECT id FROM " << getTableName() + << " where public_key = ?" + , into(mID), use(mPublicKey); + unlock(); + return select; + } + + + Poco::Data::Statement CryptoKeys::_insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + lock(); + insert << "INSERT INTO " << getTableName() + << " (private_key, public_key, crypto_key_type_id) VALUES(?,?,?)" + , use(mPrivateKey), use(mPublicKey), use(mKeyType); + unlock(); + return insert; + } + } +} \ No newline at end of file diff --git a/src/cpp/model/table/CryptoKeys.h b/src/cpp/model/table/CryptoKeys.h index e69de29bb..15991c70b 100644 --- a/src/cpp/model/table/CryptoKeys.h +++ b/src/cpp/model/table/CryptoKeys.h @@ -0,0 +1,43 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_CRYPTO_KEYS_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_CRYPTO_KEYS_INCLUDE + +#include "ModelBase.h" +#include "Poco/Types.h" + +namespace model { + namespace table { + + enum KeyType { + KEY_TYPE_SODIUM_ED25519, + KEY_TYPE_ED25519_REF10, + KEY_TYPE_COUNT + }; + + class CryptoKeys : public ModelBase + { + public: + CryptoKeys(); + ~CryptoKeys(); + + // generic db operations + const char* getTableName() const { return "crypto_keys"; } + std::string toString(); + + + static const char* typeToString(KeyType type); + protected: + Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); + Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session); + Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); + + Poco::Nullable mPrivateKey; + Poco::Nullable mPublicKey; + int mKeyType; + + }; + + } +} + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_CRYPTO_KEYS_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/Groups.cpp b/src/cpp/model/table/Groups.cpp index e69de29bb..e99780783 100644 --- a/src/cpp/model/table/Groups.cpp +++ b/src/cpp/model/table/Groups.cpp @@ -0,0 +1,57 @@ +#include "Groups.h" + +using namespace Poco::Data::Keywords; + +namespace model { + namespace table { + Groups::Groups() + { + } + + Groups::~Groups() + { + + } + + std::string Groups::toString() + { + std::stringstream ss; + ss << "Alias: " << mAlias << std::endl; + ss << "Name: " << mName << std::endl; + ss << "Description:" << mDescription << std::endl; + return ss.str(); + } + + Poco::Data::Statement Groups::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) + { + Poco::Data::Statement select(session); + + select << "SELECT id, alias, name, description FROM " << getTableName() + << " where " << fieldName << " = ?" + , into(mID), into(mAlias), into(mName), into(mDescription); + + return select; + } + Poco::Data::Statement Groups::_loadIdFromDB(Poco::Data::Session session) + { + Poco::Data::Statement select(session); + lock(); + select << "SELECT id FROM " << getTableName() + << " where alias = ?" + , into(mID), use(mAlias); + unlock(); + return select; + + } + Poco::Data::Statement Groups::_insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + lock(); + insert << "INSERT INTO " << getTableName() + << " (alias, name, description) VALUES(?,?,?)" + , use(mAlias), use(mName), use(mDescription); + unlock(); + return insert; + } + } +} \ No newline at end of file diff --git a/src/cpp/model/table/Groups.h b/src/cpp/model/table/Groups.h index e69de29bb..adc5789c0 100644 --- a/src/cpp/model/table/Groups.h +++ b/src/cpp/model/table/Groups.h @@ -0,0 +1,35 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_GROUPS_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_GROUPS_INCLUDE + +#include "ModelBase.h" + +namespace model { + namespace table { + + class Groups : public ModelBase + { + public: + Groups(); + ~Groups(); + + // generic db operations + const char* getTableName() const { return "groups"; } + std::string toString(); + + + protected: + Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); + Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session); + Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); + + std::string mAlias; + std::string mName; + std::string mDescription; + + }; + + } +} + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_GROUPS_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/HederaAccounts.cpp b/src/cpp/model/table/HederaAccounts.cpp index e69de29bb..3c019374d 100644 --- a/src/cpp/model/table/HederaAccounts.cpp +++ b/src/cpp/model/table/HederaAccounts.cpp @@ -0,0 +1,63 @@ +#include "HederaAccounts.h" + +using namespace Poco::Data::Keywords; + +namespace model { + namespace table { + + HederaAccounts::HederaAccounts() + { + + } + + HederaAccounts::~HederaAccounts() + { + + } + + std::string HederaAccounts::toString() + { + std::stringstream ss; + ss << "user id: " << std::to_string(mUserId) << std::endl; + ss << "account hedera id: " << std::to_string(mAccountHederaId) << std::endl; + ss << "account crypto key id: " << std::to_string(mAccountKeyId) << std::endl; + // balance in tinybars, 100,000,000 tinybar = 1 HashBar + ss << "account balance: " << std::to_string((double)(mBalance) * 100000000.0) << " HBAR" << std::endl; + ss << "last update: " << Poco::DateTimeFormatter::format(mUpdated, "%f.%m.%Y %H:%M:%S") << std::endl; + + return ss.str(); + } + + Poco::Data::Statement HederaAccounts::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) + { + Poco::Data::Statement select(session); + + select << "SELECT id, user_id, account_hedera_id, account_key_id, balance, updated FROM " << getTableName() + << " where " << fieldName << " = ?" + , into(mID), into(mUserId), into(mAccountHederaId), into(mAccountKeyId), into(mBalance), into(mUpdated); + + return select; + + } + Poco::Data::Statement HederaAccounts::_loadIdFromDB(Poco::Data::Session session) + { + Poco::Data::Statement select(session); + lock(); + select << "SELECT id FROM " << getTableName() + << " where account_hedera_id = ?" + , into(mID), use(mAccountHederaId); + unlock(); + return select; + } + Poco::Data::Statement HederaAccounts::_insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + lock(); + insert << "INSERT INTO " << getTableName() + << " (user_id, account_hedera_id, account_key_id, balance) VALUES(?,?,?,?)" + , use(mUserId), use(mAccountHederaId), use(mAccountKeyId), use(mBalance); + unlock(); + return insert; + } + } +} \ No newline at end of file diff --git a/src/cpp/model/table/HederaAccounts.h b/src/cpp/model/table/HederaAccounts.h index e69de29bb..74b2063d4 100644 --- a/src/cpp/model/table/HederaAccounts.h +++ b/src/cpp/model/table/HederaAccounts.h @@ -0,0 +1,36 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_ACCOUNTS_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_ACCOUNTS_INCLUDE + +#include "ModelBase.h" + +namespace model { + namespace table { + + class HederaAccounts : public ModelBase + { + public: + HederaAccounts(); + ~HederaAccounts(); + + // generic db operations + const char* getTableName() const { return "hedera_accounts"; } + std::string toString(); + + + protected: + Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); + Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session); + Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); + + int mUserId; + int mAccountHederaId; + int mAccountKeyId; + Poco::UInt64 mBalance; + Poco::DateTime mUpdated; + }; + + } +} + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_ACCOUNTS_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/HederaIds.cpp b/src/cpp/model/table/HederaIds.cpp index e69de29bb..8eeed0e55 100644 --- a/src/cpp/model/table/HederaIds.cpp +++ b/src/cpp/model/table/HederaIds.cpp @@ -0,0 +1,58 @@ +#include "HederaIds.h" + +using namespace Poco::Data::Keywords; + +namespace model { + namespace table { + HederaIds::HederaIds() + { + + } + + HederaIds::~HederaIds() + { + + } + + std::string HederaIds::toString() + { + std::stringstream ss; + ss << "Shard Num: " << std::to_string(mShardNum) << std::endl; + ss << "Realm Num: " << std::to_string(mRealmNum) << std::endl; + ss << "Num: " << std::to_string(mNum) << std::endl; + return ss.str(); + } + + Poco::Data::Statement HederaIds::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) + { + + Poco::Data::Statement select(session); + + select << "SELECT id, shardNum, realmNum, num FROM " << getTableName() + << " where " << fieldName << " = ?" + , into(mID), into(mShardNum), into(mRealmNum), into(mNum); + + return select; + } + Poco::Data::Statement HederaIds::_loadIdFromDB(Poco::Data::Session session) + { + Poco::Data::Statement select(session); + lock(); + select << "SELECT id FROM " << getTableName() + << " where shardNum = ? AND realmNum = ? AND num = ?" + , into(mID), use(mShardNum), use(mRealmNum), use(mNum); + unlock(); + return select; + } + Poco::Data::Statement HederaIds::_insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + lock(); + insert << "INSERT INTO " << getTableName() + << " (shardNum, realmNum, num) VALUES(?,?,?)" + , use(mShardNum), use(mRealmNum), use(mNum); + unlock(); + return insert; + } + } +} \ No newline at end of file diff --git a/src/cpp/model/table/HederaIds.h b/src/cpp/model/table/HederaIds.h index e69de29bb..eaa6612b8 100644 --- a/src/cpp/model/table/HederaIds.h +++ b/src/cpp/model/table/HederaIds.h @@ -0,0 +1,36 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_IDS_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_IDS_INCLUDE + +#include "ModelBase.h" +#include "Poco/Types.h" + +namespace model { + namespace table { + + class HederaIds : public ModelBase + { + public: + HederaIds(); + ~HederaIds(); + + // generic db operations + const char* getTableName() const { return "hedera_ids"; } + std::string toString(); + + + protected: + Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); + Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session); + Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); + + Poco::UInt64 mShardNum; + Poco::UInt64 mRealmNum; + Poco::UInt64 mNum; + + }; + + } +} + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_IDS_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/HederaTopics.cpp b/src/cpp/model/table/HederaTopics.cpp index e69de29bb..aeed1ea05 100644 --- a/src/cpp/model/table/HederaTopics.cpp +++ b/src/cpp/model/table/HederaTopics.cpp @@ -0,0 +1,69 @@ +#include "HederaTopics.h" + +using namespace Poco::Data::Keywords; + +namespace model { + namespace table { + HederaTopics::HederaTopics() + { + + } + + HederaTopics::~HederaTopics() + { + + } + + std::string HederaTopics::toString() + { + std::stringstream ss; + ss << "Topic Hedera id: " << std::to_string(mTopicHederaId) << std::endl; + ss << "Auto Renew Account Hedera id: " << std::to_string(mAutoRenewAccountHederaId) << std::endl; + ss << "Auto Renew Period: " << std::to_string(mAutoRenewPeriod) << " seconds" << std::endl; + ss << "Group id: " << std::to_string(mGroupId) << std::endl; + ss << "Admin Key id: " << std::to_string(mAdminKeyId) << std::endl; + ss << "Submit Key id: " << std::to_string(mSubmitKeyId) << std::endl; + ss << "Hedera Topic Tiemout: " << Poco::DateTimeFormatter::format(mCurrentTimeout, "%f.%m.%Y %H:%M:%S") << std::endl; + ss << "Hedera Topic Sequence Number: " << std::to_string(mSequenceNumber) << std::endl; + ss << "Updated: " << Poco::DateTimeFormatter::format(mUpdated, "%f.%m.%Y %H:%M:%S") << std::endl; + return ss.str(); + } + + Poco::Data::Statement HederaTopics::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) + { + Poco::Data::Statement select(session); + + select << "SELECT id, topic_hedera_id, auto_renew_account_hedera_id, auto_renew_period, " + << "group_id, admin_key_id, submit_key_id, current_timeout, sequence_number, updated FROM " << getTableName() + << " where " << fieldName << " = ?" + , into(mID), into(mTopicHederaId), into(mAutoRenewAccountHederaId), into(mAutoRenewPeriod) + , into(mGroupId), into(mAdminKeyId), into(mSubmitKeyId), into(mCurrentTimeout), into(mSequenceNumber), into(mUpdated); + + return select; + + } + Poco::Data::Statement HederaTopics::_loadIdFromDB(Poco::Data::Session session) + { + Poco::Data::Statement select(session); + lock(); + select << "SELECT id FROM " << getTableName() + << " where topic_hedera_id = ?" + , into(mID), use(mTopicHederaId); + unlock(); + return select; + } + Poco::Data::Statement HederaTopics::_insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + lock(); + insert << "INSERT INTO " << getTableName() + << " (topic_hedera_id, auto_renew_account_hedera_id, auto_renew_period," + << " group_id, admin_key_id, submit_key_id, current_timeout, sequence_number) VALUES(?,?,?,?,?,?,?,?)" + , use(mTopicHederaId), use(mAutoRenewAccountHederaId), use(mAutoRenewPeriod) + , use(mGroupId), use(mAdminKeyId), use(mSubmitKeyId), use(mCurrentTimeout), use(mSequenceNumber), use(mUpdated); + unlock(); + return insert; + } + + } +} \ No newline at end of file diff --git a/src/cpp/model/table/HederaTopics.h b/src/cpp/model/table/HederaTopics.h index e69de29bb..4584026ab 100644 --- a/src/cpp/model/table/HederaTopics.h +++ b/src/cpp/model/table/HederaTopics.h @@ -0,0 +1,41 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_TOPICS_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_TOPICS_INCLUDE + +#include "ModelBase.h" + +namespace model { + namespace table { + + class HederaTopics : public ModelBase + { + public: + HederaTopics(); + ~HederaTopics(); + + // generic db operations + const char* getTableName() const { return "hedera_topics"; } + std::string toString(); + + + protected: + Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); + Poco::Data::Statement _loadIdFromDB(Poco::Data::Session session); + Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); + + Poco::UInt32 mTopicHederaId; + Poco::UInt32 mAutoRenewAccountHederaId; + // in seconds + Poco::UInt32 mAutoRenewPeriod; + Poco::UInt32 mGroupId; + Poco::UInt32 mAdminKeyId; + Poco::UInt32 mSubmitKeyId; + Poco::DateTime mCurrentTimeout; + Poco::UInt64 mSequenceNumber; + Poco::DateTime mUpdated; + }; + + } +} + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_HEDERA_TOPICS_INCLUDE \ No newline at end of file