From 6eac0eb741f301d9dae4f8b73bf9c52f8474578a Mon Sep 17 00:00:00 2001 From: iizuka Date: Wed, 5 Aug 2026 20:10:17 +0800 Subject: [PATCH 1/3] uncomment --- .../bc_wallet_trx/BalanceTransactionWalletHandler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp b/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp index 08dc07fe..74fdb294 100644 --- a/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp +++ b/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp @@ -102,7 +102,6 @@ BalanceTransferTransaction* BalanceTransactionWalletHandler::createTransaction(A trx->sign(musigProvidor, &utxoFinder); return __STP_MV(trx); - // FIXME } void BalanceTransactionWalletHandler::collectUtxoRefs(BalanceTransferTransaction* trx, BalanceUnit& amount, const BalanceUnit& feeRate @@ -143,7 +142,7 @@ void BalanceTransactionWalletHandler::collectUtxoRefs(BalanceTransferTransaction // add exchange address if(totalIn.compareTo(&required) > 0){ - if(trx->getUtxoSize() == destUtxoSize){ // FIXME utxo size + if(trx->getUtxoSize() == destUtxoSize){ // utxo size // add ChangeAddressStore* changeAddresses = this->account->getChangeAddresses(); AddressDescriptor* changeDesc = changeAddresses->getNextChangeAddress(encoder); __STP(changeDesc); From 880cd59d4871ebc585c0032c080d897ad532169a Mon Sep 17 00:00:00 2001 From: iizuka Date: Mon, 7 Sep 2026 11:20:45 +0800 Subject: [PATCH 2/3] start dev simnet --- CMakeLists.txt | 14 +++- CodableSim.cpp | 13 ++++ Codablecash.cpp | 25 +++++++ src_blockchain/CMakeLists.txt | 1 + .../bc_base/AddressCheckDigitException.cpp | 34 +++++++++ .../bc_base/AddressCheckDigitException.h | 29 ++++++++ src_blockchain/bc_base/AddressDescriptor.cpp | 22 ++++++ src_blockchain/bc_base/AddressDescriptor.h | 8 ++- src_blockchain/bc_base/CMakeLists.txt | 1 + .../bc_base_conf_store/StatusStore.cpp | 2 +- src_blockchain/bc_block_body/Stakebase.cpp | 1 + .../bc_block_generator/MiningConfig.cpp | 2 + src_blockchain/bc_block_vote/VotePart.cpp | 22 +++--- src_blockchain/bc_block_vote/VotePart.h | 1 + .../BlockHeaderStoreCache.cpp | 2 +- .../BlockHeaderStoreCacheElement.cpp | 2 +- .../BlockHeaderStoreCacheElement.h | 2 +- .../CodablecashNetworkNode.h | 3 + .../bc_status_cache/BlockHeadElement.cpp | 4 +- .../bc_status_cache/BlockHeadElement.h | 2 +- .../bc_status_cache/ZoneStatusCache.cpp | 2 +- .../bc_status_cache/ZoneStatusCache.h | 1 - .../FinalizedDataCache.cpp | 43 +++++++++--- .../bc_status_cache_data/FinalizedDataCache.h | 11 +-- .../bc_trx/AbstractBlockchainTransaction.cpp | 5 ++ .../bc_trx/AbstractBlockchainTransaction.h | 6 ++ src_blockchain/bc_trx/AbstractUtxo.cpp | 6 ++ src_blockchain/bc_trx/AbstractUtxo.h | 3 + src_blockchain/bc_trx/AbstractUtxoReference.h | 2 + .../BalanceTransferTransaction.cpp | 5 +- src_blockchain/bc_trx_balance/BalanceUtxo.cpp | 12 ++-- src_blockchain/bc_trx_balance/BalanceUtxo.h | 8 +-- src_blockchain/bc_trx_icc/CMakeLists.txt | 7 ++ .../bc_trx_icc/RemoteBalanceUtxo.cpp | 35 ++++++++++ src_blockchain/bc_trx_icc/RemoteBalanceUtxo.h | 30 ++++++++ .../bc_trx_icc/RemoteUtxoReference.cpp | 21 ++++++ .../bc_trx_icc/RemoteUtxoReference.h | 30 ++++++++ .../bc_wallet/AbstractAddressStore.cpp | 6 +- .../bc_wallet/AbstractAddressStore.h | 2 +- .../bc_wallet/ChangeAddressStore.cpp | 6 +- src_blockchain/bc_wallet/HdWallet.cpp | 22 ++++-- src_blockchain/bc_wallet/HdWallet.h | 1 + .../bc_wallet/ReceivingAddressStore.cpp | 6 +- .../bc_wallet/ReceivingAddressStore.h | 2 +- src_blockchain/bc_wallet/WalletAccount.cpp | 2 +- .../bc_wallet_filter/BloomHash1024.cpp | 5 ++ .../bc_wallet_net/NetworkWallet.cpp | 32 ++++++++- src_blockchain/bc_wallet_net/NetworkWallet.h | 6 ++ .../bc_wallet_net_data/NetworkWalletData.cpp | 41 +++++++++-- .../bc_wallet_net_data/NetworkWalletData.h | 6 +- .../TransactionGroupDataStore.cpp | 3 +- .../NetworkClientCommandProcessor.cpp | 14 ++-- .../AbstractWalletTransactionHandler.cpp | 2 +- .../BalanceTransactionWalletHandler.cpp | 2 +- .../TransactionTransferData.cpp | 2 +- src_db/base/HashMapKeySet.h | 4 +- src_db/base/HashMapRawArray.h | 10 +-- src_db/base/RawBitSet.cpp | 2 +- src_db/base_thread/SynchronizedLock.h | 2 +- src_db/btree/TreeNode.h | 2 +- src_db/filestore/LongRangeList.cpp | 1 - .../VariableBlockFileStore.h | 2 +- .../VariableBlockHeader.cpp | 2 +- src_db/json_object/AbstractJsonObject.h | 3 + src_db/json_object/JsonArrayObject.cpp | 21 ++++++ src_db/json_object/JsonArrayObject.h | 2 + src_db/json_object/JsonBooleanValue.cpp | 10 +++ src_db/json_object/JsonBooleanValue.h | 2 + src_db/json_object/JsonNumericValue.cpp | 5 ++ src_db/json_object/JsonNumericValue.h | 2 + src_db/json_object/JsonObject.cpp | 19 +++++ src_db/json_object/JsonObject.h | 2 + src_db/json_object/JsonStringValue.cpp | 4 ++ src_db/json_object/JsonStringValue.h | 2 + src_db/json_object/JsonValuePair.cpp | 16 +++++ src_db/json_object/JsonValuePair.h | 2 + src_simnet/CMakeLists.txt | 13 ++++ src_simnet/sim/CMakeLists.txt | 11 +++ src_simnet/sim/CodableSimNet.cpp | 59 ++++++++++++++++ src_simnet/sim/CodableSimNet.h | 33 +++++++++ src_simnet/sim/InstanceSimulator.cpp | 45 ++++++++++++ src_simnet/sim/InstanceSimulator.h | 33 +++++++++ src_simnet/sim/ZoneInstanceConfig.cpp | 64 +++++++++++++++++ src_simnet/sim/ZoneInstanceConfig.h | 44 ++++++++++++ src_simnet/sim/ZoneSimulator.cpp | 67 ++++++++++++++++++ src_simnet/sim/ZoneSimulator.h | 44 ++++++++++++ src_simnet/sim_net/CMakeLists.txt | 6 ++ src_simnet/sim_net/SimnetMainNet.cpp | 58 +++++++++++++++ src_simnet/sim_net/SimnetMainNet.h | 45 ++++++++++++ .../AbstractSimnetClientCommand.cpp | 24 +++++++ .../AbstractSimnetClientCommand.h | 24 +++++++ src_simnet/sim_net_client/CMakeLists.txt | 7 ++ src_simnet/sim_net_client/SimnetClient.cpp | 49 +++++++++++++ src_simnet/sim_net_client/SimnetClient.h | 42 +++++++++++ .../SimnetPubsubCommandExecutor.cpp | 42 +++++++++++ .../SimnetPubsubCommandExecutor.h | 35 ++++++++++ .../instance_parts/VMemHashMapKeySet.h | 4 +- .../instance_parts/VMemHashMapRawArray.h | 8 +-- src_test/CMakeLists.txt | 1 + .../wallet/test_client_command_queue.cpp | 70 ++++++++++++++----- src_test/simnet/CMakeLists.txt | 10 +++ src_test/simnet/test_sim_config.cpp | 27 +++++++ src_test/simnet/test_simnet_client.cpp | 47 +++++++++++++ 103 files changed, 1478 insertions(+), 126 deletions(-) create mode 100644 CodableSim.cpp create mode 100644 Codablecash.cpp create mode 100644 src_blockchain/bc_base/AddressCheckDigitException.cpp create mode 100644 src_blockchain/bc_base/AddressCheckDigitException.h create mode 100644 src_blockchain/bc_trx_icc/CMakeLists.txt create mode 100644 src_blockchain/bc_trx_icc/RemoteBalanceUtxo.cpp create mode 100644 src_blockchain/bc_trx_icc/RemoteBalanceUtxo.h create mode 100644 src_blockchain/bc_trx_icc/RemoteUtxoReference.cpp create mode 100644 src_blockchain/bc_trx_icc/RemoteUtxoReference.h create mode 100644 src_simnet/CMakeLists.txt create mode 100644 src_simnet/sim/CMakeLists.txt create mode 100644 src_simnet/sim/CodableSimNet.cpp create mode 100644 src_simnet/sim/CodableSimNet.h create mode 100644 src_simnet/sim/InstanceSimulator.cpp create mode 100644 src_simnet/sim/InstanceSimulator.h create mode 100644 src_simnet/sim/ZoneInstanceConfig.cpp create mode 100644 src_simnet/sim/ZoneInstanceConfig.h create mode 100644 src_simnet/sim/ZoneSimulator.cpp create mode 100644 src_simnet/sim/ZoneSimulator.h create mode 100644 src_simnet/sim_net/CMakeLists.txt create mode 100644 src_simnet/sim_net/SimnetMainNet.cpp create mode 100644 src_simnet/sim_net/SimnetMainNet.h create mode 100644 src_simnet/sim_net_client/AbstractSimnetClientCommand.cpp create mode 100644 src_simnet/sim_net_client/AbstractSimnetClientCommand.h create mode 100644 src_simnet/sim_net_client/CMakeLists.txt create mode 100644 src_simnet/sim_net_client/SimnetClient.cpp create mode 100644 src_simnet/sim_net_client/SimnetClient.h create mode 100644 src_simnet/sim_net_client/SimnetPubsubCommandExecutor.cpp create mode 100644 src_simnet/sim_net_client/SimnetPubsubCommandExecutor.h create mode 100644 src_test/simnet/CMakeLists.txt create mode 100644 src_test/simnet/test_sim_config.cpp create mode 100644 src_test/simnet/test_simnet_client.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c9d7f23b..ddf5bea4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,10 @@ endmacro(handle_sub) #[[ =========================================================================================== ]]# set(srcmain - AlinousStore.cpp + Codablecash.cpp +) +set(srcsim + CodableSim.cpp ) include_directories(${PROJECT_SOURCE_DIR}/src/) @@ -138,6 +141,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src_smartcontract/) include_directories(${PROJECT_SOURCE_DIR}/src_smartcontract_db/) include_directories(${PROJECT_SOURCE_DIR}/src_smartcontract_modular/) include_directories(${PROJECT_SOURCE_DIR}/src_smartcontract_vm/) +include_directories(${PROJECT_SOURCE_DIR}/src_simnet/) include_directories(${PROJECT_SOURCE_DIR}/src_test/) add_subdirectory(src) @@ -149,14 +153,18 @@ add_subdirectory(src_smartcontract) add_subdirectory(src_smartcontract_db) add_subdirectory(src_smartcontract_modular) add_subdirectory(src_smartcontract_vm) +add_subdirectory(src_simnet) -add_library(codablecashlib STATIC ${top_src} ${top_src_blockchain} ${top_src_blockchain_p2p} ${top_src_db} ${top_src_gen} ${top_src_smartcontract} ${top_src_smartcontract_db} ${top_src_smartcontract_modular} ${top_src_smartcontract_vm}) +add_library(codablecashlib STATIC ${top_src} ${top_src_blockchain} ${top_src_blockchain_p2p} ${top_src_db} ${top_src_gen} ${top_src_smartcontract} ${top_src_smartcontract_db} ${top_src_smartcontract_modular} ${top_src_smartcontract_vm} ${top_src_simnet}) target_link_libraries(codablecashlib extlib pthread gmp) add_executable(codablecash ${srcmain}) target_link_libraries(codablecash codablecashlib extlib pthread gmp) +add_executable(codablesim ${srcsim}) +target_link_libraries(codablesim codablecashlib extlib pthread gmp) + if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "ReleaseTest") # # Test Codes @@ -202,7 +210,7 @@ add_custom_target(valgrind add_custom_target(valgrindp COMMAND valgrind --leak-check=full --xml=yes --xml-file=testall.%p.valgrind.xml --main-stacksize=83886080 --max-threads=1000 --fair-sched=yes - ./testall -g TestMultiShardGroup + ./testall -g TestSimnetClientGroup WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) diff --git a/CodableSim.cpp b/CodableSim.cpp new file mode 100644 index 00000000..962665e2 --- /dev/null +++ b/CodableSim.cpp @@ -0,0 +1,13 @@ +/* + * CodableSim.cpp + * + * Created on: Sep 2, 2026 + * Author: iizuka + */ + + +int main(int ac, char** av) { + + return 0; +} + diff --git a/Codablecash.cpp b/Codablecash.cpp new file mode 100644 index 00000000..ebcb1710 --- /dev/null +++ b/Codablecash.cpp @@ -0,0 +1,25 @@ +//============================================================================ +// Name : AlinousStore.cpp +// Author : Tomohiro Iizuka +// Version : +// Copyright : MIT License +// Description : Hello World in C, Ansi-style +//============================================================================ + +#include +#include + +#include "test_utils/t_macros.h" + +#include "base/UnicodeString.h" +#include "base/Integer.h" +#include "base/exceptions.h" + +using namespace alinous; + +const char* prog = nullptr; + +int main(int ac, char** av) { + prog = av[0]; + return 0; +} diff --git a/src_blockchain/CMakeLists.txt b/src_blockchain/CMakeLists.txt index 45700bc6..cf53900f 100644 --- a/src_blockchain/CMakeLists.txt +++ b/src_blockchain/CMakeLists.txt @@ -36,6 +36,7 @@ add_subdirectory(bc_status_cache_vote) add_subdirectory(bc_trx) add_subdirectory(bc_trx_balance) add_subdirectory(bc_trx_genesis) +add_subdirectory(bc_trx_icc) add_subdirectory(bc_wallet) add_subdirectory(bc_wallet_encoder) add_subdirectory(bc_wallet_filter) diff --git a/src_blockchain/bc_base/AddressCheckDigitException.cpp b/src_blockchain/bc_base/AddressCheckDigitException.cpp new file mode 100644 index 00000000..1744fdf2 --- /dev/null +++ b/src_blockchain/bc_base/AddressCheckDigitException.cpp @@ -0,0 +1,34 @@ +/* + * AddressCheckDigitException.cpp + * + * Created on: Aug 6, 2026 + * Author: iizuka + */ + +#include "bc_base/AddressCheckDigitException.h" + +#include "base/UnicodeString.h" + + +namespace codablecash { + +const wchar_t* AddressCheckDigitException::defaultMessage = L"Checkdigit of the address is wrong. "; + +AddressCheckDigitException::AddressCheckDigitException(const char* srcfile, int srcline) noexcept : Exception(srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); +} +AddressCheckDigitException::AddressCheckDigitException(Exception* cause, const char* srcfile, int srcline) noexcept : Exception(cause, srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); +} +AddressCheckDigitException::AddressCheckDigitException(const wchar_t* message, const char* srcfile, int srcline) noexcept : Exception(message, srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); + this->message->append(message); +} +AddressCheckDigitException::AddressCheckDigitException(const wchar_t* message, Exception* cause, const char* srcfile, int srcline) noexcept : Exception(message, cause, srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); + this->message->append(message); +} +AddressCheckDigitException::~AddressCheckDigitException() { +} + +} /* namespace codablecash */ diff --git a/src_blockchain/bc_base/AddressCheckDigitException.h b/src_blockchain/bc_base/AddressCheckDigitException.h new file mode 100644 index 00000000..367a3070 --- /dev/null +++ b/src_blockchain/bc_base/AddressCheckDigitException.h @@ -0,0 +1,29 @@ +/* + * AddressCheckDigitException.h + * + * Created on: Aug 6, 2026 + * Author: iizuka + */ + +#ifndef BC_BASE_ADDRESSCHECKDIGITEXCEPTION_H_ +#define BC_BASE_ADDRESSCHECKDIGITEXCEPTION_H_ + +#include "base/Exception.h" + +using namespace alinous; + +namespace codablecash { + +class AddressCheckDigitException : public Exception { +public: + AddressCheckDigitException(const char* srcfile, int srcline) noexcept; + AddressCheckDigitException(Exception* cause, const char* srcfile, int srcline) noexcept; + AddressCheckDigitException(const wchar_t* message, const char* srcfile, int srcline) noexcept; + AddressCheckDigitException(const wchar_t* message, Exception* cause, const char* srcfile, int srcline) noexcept; + virtual ~AddressCheckDigitException(); + static const wchar_t* defaultMessage; +}; + +} /* namespace codablecash */ + +#endif /* BC_BASE_ADDRESSCHECKDIGITEXCEPTION_H_ */ diff --git a/src_blockchain/bc_base/AddressDescriptor.cpp b/src_blockchain/bc_base/AddressDescriptor.cpp index 55d4ac45..d438b59e 100644 --- a/src_blockchain/bc_base/AddressDescriptor.cpp +++ b/src_blockchain/bc_base/AddressDescriptor.cpp @@ -17,6 +17,11 @@ #include +#include "bc/ExceptionThrower.h" + +#include "bc_base/AddressCheckDigitException.h" + +#include "base/Integer.h" using namespace alinous; namespace codablecash { @@ -95,7 +100,14 @@ void AddressDescriptor::importCstring(const char *cstr) { UnicodeString str(bodycstr); this->body = Base58::decode(&str); + // check checkdigits + char __checkDigit[2]; + Mem::memcpy(__checkDigit, cstr + AddressDescriptor::PREFIX_LENGTH + AddressDescriptor::ZONE_LENGTH + bodylength, AddressDescriptor::CHECKDIGIT_LENGTH); + makeCheckDigit(); + + int cmp = Mem::memcmp(this->checkDigit, __checkDigit, AddressDescriptor::CHECKDIGIT_LENGTH); + ExceptionThrower::throwExceptionIfCondition(cmp != 0, L"Check digit error.", __FILE__, __LINE__); } void AddressDescriptor::makeCheckDigit() { @@ -167,4 +179,14 @@ IBlockObject* AddressDescriptor::copyData() const noexcept { return new AddressDescriptor(*this); } +uint16_t AddressDescriptor::getZone() const noexcept { + char buff[4]{}; + + Mem::memcpy(buff, this->prefix, 3); + UnicodeString str(buff); + + uint16_t zone = Integer::parseInt(&str, 16); + return zone; +} + } /* namespace codablecash */ diff --git a/src_blockchain/bc_base/AddressDescriptor.h b/src_blockchain/bc_base/AddressDescriptor.h index 83a0aa46..99c74481 100644 --- a/src_blockchain/bc_base/AddressDescriptor.h +++ b/src_blockchain/bc_base/AddressDescriptor.h @@ -40,15 +40,17 @@ class AddressDescriptor : public alinous::IBlockObject { int compareTo(const AddressDescriptor* other) const noexcept; + uint16_t getZone() const noexcept; + private: void makeCheckDigit(); void importCstring(const char* cstr); private: - char prefix[2]; - char zone[3]; + char prefix[2]; // utf base + char zone[3]; // utf base radix 16 ByteBuffer* body; - char checkDigit[2]; + char checkDigit[2];// utf base radix 10 }; } /* namespace codablecash */ diff --git a/src_blockchain/bc_base/CMakeLists.txt b/src_blockchain/bc_base/CMakeLists.txt index d0fde642..8ec3b399 100644 --- a/src_blockchain/bc_base/CMakeLists.txt +++ b/src_blockchain/bc_base/CMakeLists.txt @@ -3,6 +3,7 @@ set(__src Abstract32BytesId.cpp AbstractAddress.cpp + AddressCheckDigitException.cpp AddressDescriptor.cpp BalanceAddress.cpp BalanceUnit.cpp diff --git a/src_blockchain/bc_base_conf_store/StatusStore.cpp b/src_blockchain/bc_base_conf_store/StatusStore.cpp index a2c5f591..766db48a 100644 --- a/src_blockchain/bc_base_conf_store/StatusStore.cpp +++ b/src_blockchain/bc_base_conf_store/StatusStore.cpp @@ -226,7 +226,7 @@ void StatusStore::write() { int StatusStore::binarySize() const { int total = 0; - total += sizeof(int); + total += sizeof(uint32_t); Iterator* it = this->map.keySet()->iterator(); __STP(it); while(it->hasNext()){ diff --git a/src_blockchain/bc_block_body/Stakebase.cpp b/src_blockchain/bc_block_body/Stakebase.cpp index 6ef1522e..fc1d5598 100644 --- a/src_blockchain/bc_block_body/Stakebase.cpp +++ b/src_blockchain/bc_block_body/Stakebase.cpp @@ -40,6 +40,7 @@ void Stakebase::toBinary(ByteBuffer *out) const { void Stakebase::fromBinary(ByteBuffer *in) { this->amount = BalanceUnit::fromBinary(in); + BinaryUtils::checkNotNull(this->amount); } IBlockObject* Stakebase::copyData() const noexcept { diff --git a/src_blockchain/bc_block_generator/MiningConfig.cpp b/src_blockchain/bc_block_generator/MiningConfig.cpp index 49d731c7..bb506c4d 100644 --- a/src_blockchain/bc_block_generator/MiningConfig.cpp +++ b/src_blockchain/bc_block_generator/MiningConfig.cpp @@ -18,6 +18,8 @@ #include "ipconnect/IServerSocket.h" #include "bc_p2p_info/P2pNodeRecord.h" + + namespace codablecash { MiningConfig::MiningConfig(const MiningConfig &inst) { diff --git a/src_blockchain/bc_block_vote/VotePart.cpp b/src_blockchain/bc_block_vote/VotePart.cpp index 9720b138..07f2c1cc 100644 --- a/src_blockchain/bc_block_vote/VotePart.cpp +++ b/src_blockchain/bc_block_vote/VotePart.cpp @@ -17,6 +17,7 @@ namespace codablecash { VotePart::VotePart() { + this->list = new ArrayList(); this->map = new HashMap(); } @@ -30,6 +31,9 @@ VotePart::~VotePart() { } delete this->map; + + this->list->deleteElements(); + delete this->list; } void VotePart::addVote(const VoteBlockTransaction *trx) noexcept { @@ -38,6 +42,8 @@ void VotePart::addVote(const VoteBlockTransaction *trx) noexcept { VotedHeaderIdGroup* group = this->map->get(headerId); if(group == nullptr){ group = new VotedHeaderIdGroup(headerId); + + this->list->addElement(dynamic_cast(headerId->copyData())); this->map->put(headerId, group); } @@ -48,9 +54,9 @@ void VotePart::addVote(const VoteBlockTransaction *trx) noexcept { int VotePart::binarySize() const { int total = sizeof(uint8_t); - Iterator* it = this->map->keySet()->iterator(); __STP(it); - while(it->hasNext()){ - const BlockHeaderId* headerId = it->next(); + int maxLoop = this->list->size(); + for(int i = 0; i != maxLoop; ++i){ + const BlockHeaderId* headerId = this->list->get(i); VotedHeaderIdGroup* group = this->map->get(headerId); total += group->binarySize(); @@ -60,12 +66,11 @@ int VotePart::binarySize() const { } void VotePart::toBinary(ByteBuffer *out) const { - int size = this->map->size(); - out->put(size); + int maxLoop = this->list->size(); + out->put(maxLoop); - Iterator* it = this->map->keySet()->iterator(); __STP(it); - while(it->hasNext()){ - const BlockHeaderId* headerId = it->next(); + for(int i = 0; i != maxLoop; ++i){ + const BlockHeaderId* headerId = this->list->get(i); VotedHeaderIdGroup* group = this->map->get(headerId); group->toBinary(out); @@ -81,6 +86,7 @@ VotePart* VotePart::createFromBinary(ByteBuffer *in) { VotedHeaderIdGroup* group = VotedHeaderIdGroup::createFromBinary(in); const BlockHeaderId* headerId = group->getBlockHeaderId(); + part->list->addElement(dynamic_cast(headerId->copyData())); part->map->put(headerId, group); } diff --git a/src_blockchain/bc_block_vote/VotePart.h b/src_blockchain/bc_block_vote/VotePart.h index c742f63e..955a006b 100644 --- a/src_blockchain/bc_block_vote/VotePart.h +++ b/src_blockchain/bc_block_vote/VotePart.h @@ -46,6 +46,7 @@ class VotePart { void visitVoteTransactionIdCertificate(IVoteTransactionIdCertificatevisitor* visitor) const; private: + ArrayList* list; HashMap* map; }; diff --git a/src_blockchain/bc_blockstore_header/BlockHeaderStoreCache.cpp b/src_blockchain/bc_blockstore_header/BlockHeaderStoreCache.cpp index faf67b5f..69f7ab48 100644 --- a/src_blockchain/bc_blockstore_header/BlockHeaderStoreCache.cpp +++ b/src_blockchain/bc_blockstore_header/BlockHeaderStoreCache.cpp @@ -57,7 +57,7 @@ BlockHeaderStoreCacheElement* BlockHeaderStoreCache::getHeaderStoreCacheElement( cache->create(); } - cache->init(); // open + cache->open(); // open this->list->add(0, cache); diff --git a/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.cpp b/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.cpp index fbe95fb0..498ec3f3 100644 --- a/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.cpp +++ b/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.cpp @@ -42,7 +42,7 @@ BlockHeaderStoreCacheElement::~BlockHeaderStoreCacheElement() { delete this->cacheManager; } -void BlockHeaderStoreCacheElement::init() { +void BlockHeaderStoreCacheElement::open() { this->store = new BlockHeaderStore(this->index, this->baseDir, this->cacheManager); this->heightIndex = new BlockHeaderHeightIndex(this->index, this->baseDir, this->cacheManager); diff --git a/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.h b/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.h index 42d23b9d..e3b0b20e 100644 --- a/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.h +++ b/src_blockchain/bc_blockstore_header/BlockHeaderStoreCacheElement.h @@ -31,7 +31,7 @@ class BlockHeaderStoreCacheElement { BlockHeaderStoreCacheElement(const File* baseDir, uint64_t index); virtual ~BlockHeaderStoreCacheElement(); - void init(); + void open(); bool exist() const noexcept; void create(); diff --git a/src_blockchain/bc_network_instance/CodablecashNetworkNode.h b/src_blockchain/bc_network_instance/CodablecashNetworkNode.h index 22d96729..bb69d6ba 100644 --- a/src_blockchain/bc_network_instance/CodablecashNetworkNode.h +++ b/src_blockchain/bc_network_instance/CodablecashNetworkNode.h @@ -10,8 +10,11 @@ #include +#include "base/ArrayList.h" + namespace alinous { class File; +class UnicodeString; } using namespace alinous; diff --git a/src_blockchain/bc_status_cache/BlockHeadElement.cpp b/src_blockchain/bc_status_cache/BlockHeadElement.cpp index 318af72d..2a73634a 100644 --- a/src_blockchain/bc_status_cache/BlockHeadElement.cpp +++ b/src_blockchain/bc_status_cache/BlockHeadElement.cpp @@ -37,10 +37,10 @@ BlockHeadElement::~BlockHeadElement() { delete this->header; } -void BlockHeadElement::importVotes(const VotePart *vorts) noexcept { +void BlockHeadElement::importVotes(const VotePart *votes) noexcept { const BlockHeaderId* id = this->header->getId(); - const HashMap* map = vorts->getMap(); + const HashMap* map = votes->getMap(); Iterator* it = map->keySet()->iterator(); __STP(it); while(it->hasNext()){ diff --git a/src_blockchain/bc_status_cache/BlockHeadElement.h b/src_blockchain/bc_status_cache/BlockHeadElement.h index f7a6a11b..006463ce 100644 --- a/src_blockchain/bc_status_cache/BlockHeadElement.h +++ b/src_blockchain/bc_status_cache/BlockHeadElement.h @@ -30,7 +30,7 @@ class BlockHeadElement { return this->header; } - void importVotes(const VotePart* vorts) noexcept; + void importVotes(const VotePart* votes) noexcept; void hasTransactionInMemoryPool() noexcept; void hasNoTransactionInMemoryPool() noexcept; diff --git a/src_blockchain/bc_status_cache/ZoneStatusCache.cpp b/src_blockchain/bc_status_cache/ZoneStatusCache.cpp index 79f5178f..8d23351d 100644 --- a/src_blockchain/bc_status_cache/ZoneStatusCache.cpp +++ b/src_blockchain/bc_status_cache/ZoneStatusCache.cpp @@ -232,7 +232,7 @@ void ZoneStatusCache::finalizeUpdateCacheData(uint64_t finalizingHeight, const B BlockBody* body = bodyManager->getBlockBody(root, height); __STP(body); - this->finalizedCache->importBlockData(finalizingHeight, header, body, context); + this->finalizedCache->importBlockData(finalizingHeight, header, body, context, config); height++; } diff --git a/src_blockchain/bc_status_cache/ZoneStatusCache.h b/src_blockchain/bc_status_cache/ZoneStatusCache.h index 6d396027..ab10d057 100644 --- a/src_blockchain/bc_status_cache/ZoneStatusCache.h +++ b/src_blockchain/bc_status_cache/ZoneStatusCache.h @@ -119,7 +119,6 @@ class ZoneStatusCache { uint64_t ticketPrice; - File* baseDir; StatusStore* statusStore; HeadBlockDetector* headBlockDetector; diff --git a/src_blockchain/bc_status_cache_data/FinalizedDataCache.cpp b/src_blockchain/bc_status_cache_data/FinalizedDataCache.cpp index 0112e653..42f56d1c 100644 --- a/src_blockchain/bc_status_cache_data/FinalizedDataCache.cpp +++ b/src_blockchain/bc_status_cache_data/FinalizedDataCache.cpp @@ -105,7 +105,7 @@ void FinalizedDataCache::close() { } } -void FinalizedDataCache::importBlockData(uint64_t finalizingHeight, const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context) { +void FinalizedDataCache::importBlockData(uint64_t finalizingHeight, const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context, const CodablecashSystemParam* config) { BlockchainStatusCache* statusCache = context->getBlockchainStatusCache(); uint16_t zone = context->getZone(); @@ -115,10 +115,10 @@ void FinalizedDataCache::importBlockData(uint64_t finalizingHeight, const BlockH context->beginBlock(header, lockinManager, true); - importControlTransactions(header, body, context); - importInterChainCommunicationTransactions(header, body, context); - importBalanceTransactions(header, body); - importSmartcontractTransactions(header, body); + importControlTransactions(header, body, context, lockinManager, config); + importInterChainCommunicationTransactions(header, body, context, lockinManager, config); + importBalanceTransactions(header, body, context, lockinManager, config); + importSmartcontractTransactions(header, body, context, lockinManager, config); importRewardBaseTransactions(header, body); // register lockin actions on Finalize @endBlock(); @@ -143,9 +143,13 @@ void FinalizedDataCache::importRewardBaseTransactions(const BlockHeader *header, } } -void FinalizedDataCache::importControlTransactions(const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context) { +void FinalizedDataCache::importControlTransactions(const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context + , LockinManager* lockinManager, const CodablecashSystemParam* config) { const ArrayList* list = body->getControlTransactions(); + BlockchainStatusCache* cache = context->getBlockchainStatusCache(); + CodablecashBlockchain* blockchain = context->getBlockChain(); + int maxLoop = list->size(); for(int i = 0; i != maxLoop; ++i){ AbstractControlTransaction* trx = list->get(i); @@ -172,6 +176,8 @@ void FinalizedDataCache::importControlTransactions(const BlockHeader *header, co else if(type == AbstractBlockchainTransaction::TRX_TYPE_REVOKE_MISS_VOTED_TICKET){ // do nothing } + + trx->onFinalize(header, cache, blockchain, lockinManager, config); } } @@ -192,7 +198,10 @@ void FinalizedDataCache::importVoteBlockTransaction(const BlockHeader *header, context->registerVote(header, trx); } -void FinalizedDataCache::importBalanceTransactions(const BlockHeader *header, const BlockBody *body) { +void FinalizedDataCache::importBalanceTransactions(const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config) { + BlockchainStatusCache* cache = context->getBlockchainStatusCache(); + CodablecashBlockchain* blockchain = context->getBlockChain(); + const ArrayList* list = body->getBalanceTransactions(); int maxLoop = list->size(); @@ -200,10 +209,15 @@ void FinalizedDataCache::importBalanceTransactions(const BlockHeader *header, co AbstractBalanceTransaction* trx = list->get(i); importTransactionUtxos(trx, header); + + trx->onFinalize(header, cache, blockchain, lockinManager, config); } } -void FinalizedDataCache::importInterChainCommunicationTransactions(const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context) { +void FinalizedDataCache::importInterChainCommunicationTransactions(const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config) { + BlockchainStatusCache* cache = context->getBlockchainStatusCache(); + CodablecashBlockchain* blockchain = context->getBlockChain(); + const ArrayList* list = body->getInterChainCommunicationTransactions(); int maxLoop = list->size(); @@ -232,10 +246,15 @@ void FinalizedDataCache::importInterChainCommunicationTransactions(const BlockHe RemoteUtxoDetector* remoteUtxos = context->getRemoteUtxoDetector(); remoteUtxos->consumeRemoteUtxo(cutxoId, height); } + + trx->onFinalize(header, cache, blockchain, lockinManager, config); } } -void FinalizedDataCache::importSmartcontractTransactions(const BlockHeader *header, const BlockBody *body) { +void FinalizedDataCache::importSmartcontractTransactions(const BlockHeader *header, const BlockBody *body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config) { + BlockchainStatusCache* cache = context->getBlockchainStatusCache(); + CodablecashBlockchain* blockchain = context->getBlockChain(); + const ArrayList* list = body->getSmartcontractTransactions(); int maxLoop = list->size(); @@ -243,6 +262,8 @@ void FinalizedDataCache::importSmartcontractTransactions(const BlockHeader *head AbstractSmartcontractTransaction* trx = list->get(i); importTransactionUtxos(trx, header); + + trx->onFinalize(header, cache, blockchain, lockinManager, config); } } @@ -274,6 +295,10 @@ void FinalizedDataCache::importTransactionUtxos(const AbstractBlockchainTransact for(int i = 0; i != maxLoop; ++i){ AbstractUtxo* utxo = trx->getUtxo(i); + if(utxo->isRemote()){ + continue; + } + #ifdef __DEBUG__ { const UtxoId* utxoId = utxo->getId(); diff --git a/src_blockchain/bc_status_cache_data/FinalizedDataCache.h b/src_blockchain/bc_status_cache_data/FinalizedDataCache.h index cabd79b8..d96fc91e 100644 --- a/src_blockchain/bc_status_cache_data/FinalizedDataCache.h +++ b/src_blockchain/bc_status_cache_data/FinalizedDataCache.h @@ -32,6 +32,7 @@ class VoterStatusCacheContext; class RemoteUtxoRepository; class CodablecashSystemParam; class BlockchainSoftwareVersion; +class LockinManager; class FinalizedDataCache { public: @@ -45,7 +46,7 @@ class FinalizedDataCache { void open(); void close(); - void importBlockData(uint64_t finalizingHeight, const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context); + void importBlockData(uint64_t finalizingHeight, const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context, const CodablecashSystemParam* config); void writeBackVoterEntries(IStatusCacheContext* context); void writeBackVoterStatus(IStatusCacheContext* context); void writeBackRemoteUtxo(uint64_t finalizingHeight, IStatusCacheContext* context, const CodablecashSystemParam* config, const BlockchainSoftwareVersion* version); @@ -65,14 +66,14 @@ class FinalizedDataCache { } private: - void importControlTransactions(const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context); + void importControlTransactions(const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config); void importRegisterVotePoolTransaction(const BlockHeader* header, const BlockBody* body, const RegisterVotePoolTransaction* trx, IStatusCacheContext* context); void importRegisterTicketTransaction(const BlockHeader* header, const BlockBody* body, const RegisterTicketTransaction* trx, IStatusCacheContext* context); void importVoteBlockTransaction(const BlockHeader* header, const BlockBody* body, const VoteBlockTransaction* trx, IStatusCacheContext* context); - void importBalanceTransactions(const BlockHeader* header, const BlockBody* body); - void importInterChainCommunicationTransactions(const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context); - void importSmartcontractTransactions(const BlockHeader* header, const BlockBody* body); + void importBalanceTransactions(const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config); + void importInterChainCommunicationTransactions(const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config); + void importSmartcontractTransactions(const BlockHeader* header, const BlockBody* body, IStatusCacheContext* context, LockinManager* lockinManager, const CodablecashSystemParam* config); void importRewardBaseTransactions(const BlockHeader* header, const BlockBody* body); diff --git a/src_blockchain/bc_trx/AbstractBlockchainTransaction.cpp b/src_blockchain/bc_trx/AbstractBlockchainTransaction.cpp index 519a6500..f0bc6b2d 100644 --- a/src_blockchain/bc_trx/AbstractBlockchainTransaction.cpp +++ b/src_blockchain/bc_trx/AbstractBlockchainTransaction.cpp @@ -297,4 +297,9 @@ bool AbstractBlockchainTransaction::checkFilteredAddress(const IAddressChecker * return ret; } +void AbstractBlockchainTransaction::onFinalize(const BlockHeader *header, + BlockchainStatusCache *statusCache, CodablecashBlockchain *blockchain, + ILockinManager *lockinManager, const CodablecashSystemParam *config) { +} + } /* namespace codablecash */ diff --git a/src_blockchain/bc_trx/AbstractBlockchainTransaction.h b/src_blockchain/bc_trx/AbstractBlockchainTransaction.h index cbbbfbd7..523c4613 100644 --- a/src_blockchain/bc_trx/AbstractBlockchainTransaction.h +++ b/src_blockchain/bc_trx/AbstractBlockchainTransaction.h @@ -31,6 +31,10 @@ class IAddressChecker; class MerkleTree; class UtxoId; class TransactionVersion; +class BlockchainStatusCache; +class CodablecashBlockchain; +class ILockinManager; +class CodablecashSystemParam; enum class TrxValidationResult { @@ -94,6 +98,8 @@ class AbstractBlockchainTransaction : public alinous::IBlockObject { virtual TrxValidationResult validateFinal(const BlockHeader* header, MemPoolTransaction *memTrx, IStatusCacheContext* context) const = 0; virtual TrxValidationResult validateReported(const BlockHeader* header, IStatusCacheContext* context) const; + virtual void onFinalize(const BlockHeader *header, BlockchainStatusCache* statusCache, CodablecashBlockchain* blockchain, ILockinManager *lockinManager, const CodablecashSystemParam* config); + virtual bool checkFilter(const ArrayList *filtersList) const; virtual bool checkFilteredUxtoRef(const IUtxoRefChecker* utxoRefChecker) const; diff --git a/src_blockchain/bc_trx/AbstractUtxo.cpp b/src_blockchain/bc_trx/AbstractUtxo.cpp index 1e0d5b16..6cf6d37c 100644 --- a/src_blockchain/bc_trx/AbstractUtxo.cpp +++ b/src_blockchain/bc_trx/AbstractUtxo.cpp @@ -21,6 +21,9 @@ #include "base/StackRelease.h" +#include "bc_trx_icc/RemoteBalanceUtxo.h" + + namespace codablecash { AbstractUtxo::AbstractUtxo(const AbstractUtxo &inst) { @@ -51,6 +54,9 @@ AbstractUtxo* AbstractUtxo::createFromBinary(ByteBuffer *in) { case AbstractUtxo::TRX_UTXO_VOTED_TICKET: ret = new TicketVotedUtxo(); break; + case AbstractUtxo::TRX_UTXO_REMOTE_BALANCE: + ret = new RemoteBalanceUtxo(); + break; case AbstractUtxo::TRX_UTXO_REMOVED_DUMMY: ret = new RemovedDummyUtxo(); break; diff --git a/src_blockchain/bc_trx/AbstractUtxo.h b/src_blockchain/bc_trx/AbstractUtxo.h index c8a3a7c0..ab99b672 100644 --- a/src_blockchain/bc_trx/AbstractUtxo.h +++ b/src_blockchain/bc_trx/AbstractUtxo.h @@ -24,6 +24,7 @@ class AbstractUtxo : public alinous::IBlockObject { static const constexpr uint8_t TRX_UTXO_TICKET{2}; static const constexpr uint8_t TRX_UTXO_VOTED_TICKET{3}; + static const constexpr uint8_t TRX_UTXO_REMOTE_BALANCE{4}; static const constexpr uint8_t TRX_UTXO_REMOVED_DUMMY{100}; @@ -41,6 +42,8 @@ class AbstractUtxo : public alinous::IBlockObject { virtual const AddressDescriptor* getAddress() const noexcept = 0; virtual BalanceUnit getAmount() const noexcept = 0; + virtual bool isRemote() const noexcept {return false;} + bool equals(const AbstractUtxo* other) const noexcept; const UtxoId* getId() const noexcept { diff --git a/src_blockchain/bc_trx/AbstractUtxoReference.h b/src_blockchain/bc_trx/AbstractUtxoReference.h index 8c07c50a..7249192e 100644 --- a/src_blockchain/bc_trx/AbstractUtxoReference.h +++ b/src_blockchain/bc_trx/AbstractUtxoReference.h @@ -29,6 +29,8 @@ class AbstractUtxoReference : public alinous::IBlockObject { static const constexpr uint8_t UTXO_REF_TYPE_COINBASE{4}; static const constexpr uint8_t UTXO_REF_TYPE_STAKEBASE{5}; + static const constexpr uint8_t UTXO_REF_TYPE_REMOTE{6}; + AbstractUtxoReference(const AbstractUtxoReference& inst); AbstractUtxoReference(); diff --git a/src_blockchain/bc_trx_balance/BalanceTransferTransaction.cpp b/src_blockchain/bc_trx_balance/BalanceTransferTransaction.cpp index 99aca6df..406fd31d 100644 --- a/src_blockchain/bc_trx_balance/BalanceTransferTransaction.cpp +++ b/src_blockchain/bc_trx_balance/BalanceTransferTransaction.cpp @@ -12,8 +12,10 @@ #include "bc_trx_balance/BalanceUtxoReference.h" #include "bc_trx/TransactionId.h" +#include "bc_trx/TransactionVersion.h" #include "bc_base/BinaryUtils.h" +#include "bc_base/AddressDescriptor.h" #include "base/StackRelease.h" @@ -26,9 +28,6 @@ #include "ecda/Secp256k1CompressedPoint.h" #include "ecda/Secp256k1Point.h" -#include "bc_base/AddressDescriptor.h" - -#include "bc_trx/TransactionVersion.h" namespace codablecash { diff --git a/src_blockchain/bc_trx_balance/BalanceUtxo.cpp b/src_blockchain/bc_trx_balance/BalanceUtxo.cpp index 011313b8..f84685c2 100644 --- a/src_blockchain/bc_trx_balance/BalanceUtxo.cpp +++ b/src_blockchain/bc_trx_balance/BalanceUtxo.cpp @@ -38,19 +38,15 @@ BalanceUtxo::~BalanceUtxo() { delete this->addressDesc; } +uint8_t BalanceUtxo::getType() const noexcept { + return AbstractUtxo::TRX_UTXO_BALANCE; +} + void BalanceUtxo::setAddress(const AddressDescriptor *desc) noexcept { delete this->addressDesc; this->addressDesc = new AddressDescriptor(*desc); } -int BalanceUtxo::tmpBinarySize() const { - int total = sizeof(uint8_t); - - - - return total; -} - int BalanceUtxo::binarySize() const { BinaryUtils::checkNotNull(this->utxoId); BinaryUtils::checkNotNull(this->addressDesc); diff --git a/src_blockchain/bc_trx_balance/BalanceUtxo.h b/src_blockchain/bc_trx_balance/BalanceUtxo.h index 38b6aa3e..e36fdecf 100644 --- a/src_blockchain/bc_trx_balance/BalanceUtxo.h +++ b/src_blockchain/bc_trx_balance/BalanceUtxo.h @@ -23,9 +23,7 @@ class BalanceUtxo : public AbstractUtxo { explicit BalanceUtxo(BalanceUnit amount); virtual ~BalanceUtxo(); - virtual uint8_t getType() const noexcept { - return AbstractUtxo::TRX_UTXO_BALANCE; - } + virtual uint8_t getType() const noexcept; virtual const AddressDescriptor* getAddress() const noexcept { return this->addressDesc; @@ -37,8 +35,6 @@ class BalanceUtxo : public AbstractUtxo { virtual void toBinary(ByteBuffer* out) const; virtual void fromBinary(ByteBuffer* in); - int tmpBinarySize() const; - virtual IBlockObject* copyData() const noexcept; virtual void build(); @@ -49,7 +45,7 @@ class BalanceUtxo : public AbstractUtxo { void discountFee(const BalanceUnit& feeRemain); -private: +protected: AddressDescriptor* addressDesc; BalanceUnit amount; }; diff --git a/src_blockchain/bc_trx_icc/CMakeLists.txt b/src_blockchain/bc_trx_icc/CMakeLists.txt new file mode 100644 index 00000000..77b760b0 --- /dev/null +++ b/src_blockchain/bc_trx_icc/CMakeLists.txt @@ -0,0 +1,7 @@ + + +set(__src + RemoteBalanceUtxo.cpp + RemoteUtxoReference.cpp +) +handle_sub(codablecashlib "${__src}" blockchain bc_trx_icc) diff --git a/src_blockchain/bc_trx_icc/RemoteBalanceUtxo.cpp b/src_blockchain/bc_trx_icc/RemoteBalanceUtxo.cpp new file mode 100644 index 00000000..c5ae5577 --- /dev/null +++ b/src_blockchain/bc_trx_icc/RemoteBalanceUtxo.cpp @@ -0,0 +1,35 @@ +/* + * RemoteUtxo.cpp + * + * Created on: Aug 7, 2026 + * Author: iizuka + */ + +#include "bc_trx_icc/RemoteBalanceUtxo.h" + +namespace codablecash { + +RemoteBalanceUtxo::RemoteBalanceUtxo(const RemoteBalanceUtxo &inst) : BalanceUtxo(inst) { +} + +RemoteBalanceUtxo::RemoteBalanceUtxo() : BalanceUtxo() { + +} + +RemoteBalanceUtxo::~RemoteBalanceUtxo() { + +} + +uint8_t RemoteBalanceUtxo::getType() const noexcept { + return AbstractUtxo::TRX_UTXO_REMOTE_BALANCE; +} + +bool RemoteBalanceUtxo::isRemote() const noexcept { + return true; +} + +IBlockObject* RemoteBalanceUtxo::copyData() const noexcept { + return new RemoteBalanceUtxo(*this); +} + +} /* namespace codablecash */ diff --git a/src_blockchain/bc_trx_icc/RemoteBalanceUtxo.h b/src_blockchain/bc_trx_icc/RemoteBalanceUtxo.h new file mode 100644 index 00000000..d5cbd6e4 --- /dev/null +++ b/src_blockchain/bc_trx_icc/RemoteBalanceUtxo.h @@ -0,0 +1,30 @@ +/* + * RemoteUtxo.h + * + * Created on: Aug 7, 2026 + * Author: iizuka + */ + +#ifndef BC_TRX_ICC_REMOTEBALANCEUTXO_H_ +#define BC_TRX_ICC_REMOTEBALANCEUTXO_H_ + +#include "bc_trx_balance/BalanceUtxo.h" + + +namespace codablecash { + +class RemoteBalanceUtxo: public BalanceUtxo { +public: + RemoteBalanceUtxo(const RemoteBalanceUtxo& inst); + RemoteBalanceUtxo(); + virtual ~RemoteBalanceUtxo(); + + virtual uint8_t getType() const noexcept; + virtual bool isRemote() const noexcept; + + virtual IBlockObject* copyData() const noexcept; +}; + +} /* namespace codablecash */ + +#endif /* BC_TRX_ICC_REMOTEBALANCEUTXO_H_ */ diff --git a/src_blockchain/bc_trx_icc/RemoteUtxoReference.cpp b/src_blockchain/bc_trx_icc/RemoteUtxoReference.cpp new file mode 100644 index 00000000..a564675a --- /dev/null +++ b/src_blockchain/bc_trx_icc/RemoteUtxoReference.cpp @@ -0,0 +1,21 @@ +/* + * RemoteUtxoReference.cpp + * + * Created on: Aug 8, 2026 + * Author: iizuka + */ + +#include + +namespace codablecash { + +RemoteUtxoReference::RemoteUtxoReference() { + // TODO Auto-generated constructor stub + +} + +RemoteUtxoReference::~RemoteUtxoReference() { + // TODO Auto-generated destructor stub +} + +} /* namespace codablecash */ diff --git a/src_blockchain/bc_trx_icc/RemoteUtxoReference.h b/src_blockchain/bc_trx_icc/RemoteUtxoReference.h new file mode 100644 index 00000000..6ba01f7d --- /dev/null +++ b/src_blockchain/bc_trx_icc/RemoteUtxoReference.h @@ -0,0 +1,30 @@ +/* + * RemoteUtxoReference.h + * + * Created on: Aug 8, 2026 + * Author: iizuka + */ + +#ifndef BC_TRX_ICC_REMOTEUTXOREFERENCE_H_ +#define BC_TRX_ICC_REMOTEUTXOREFERENCE_H_ + +#include "bc_trx/AbstractUtxoReference.h" + +namespace codablecash { + +class RemoteUtxoReference: public AbstractUtxoReference { +public: + RemoteUtxoReference(); + virtual ~RemoteUtxoReference(); + + virtual uint8_t getType() const noexcept { + return AbstractUtxoReference::UTXO_REF_TYPE_REMOTE; + } + +private: + +}; + +} /* namespace codablecash */ + +#endif /* BC_TRX_ICC_REMOTEUTXOREFERENCE_H_ */ diff --git a/src_blockchain/bc_wallet/AbstractAddressStore.cpp b/src_blockchain/bc_wallet/AbstractAddressStore.cpp index c9983f80..018832eb 100644 --- a/src_blockchain/bc_wallet/AbstractAddressStore.cpp +++ b/src_blockchain/bc_wallet/AbstractAddressStore.cpp @@ -35,7 +35,7 @@ namespace codablecash { AbstractAddressStore::AbstractAddressStore(uint16_t zone, const File* baseDir, const wchar_t* storeName) { this->encryptedSeed = nullptr; - this->adressSerial = 0; + this->addressSerial = 0; this->zone = zone; this->list = new ArrayList(); @@ -136,7 +136,7 @@ void AbstractAddressStore::__save() { this->store->addBinaryValue(KEY_ENCRYPTED_SEED, buff->array(), buff->limit()); } - this->store->addLongValue(KEY_ADDRESS_SERIAL, this->adressSerial); + this->store->addLongValue(KEY_ADDRESS_SERIAL, this->addressSerial); } void AbstractAddressStore::__load() { @@ -148,7 +148,7 @@ void AbstractAddressStore::__load() { this->encryptedSeed = new HdWalletSeed((const char*)buff->array(), buff->limit()); } - this->adressSerial = this->store->getLongValue(KEY_ADDRESS_SERIAL); + this->addressSerial = this->store->getLongValue(KEY_ADDRESS_SERIAL); } } /* namespace codablecash */ diff --git a/src_blockchain/bc_wallet/AbstractAddressStore.h b/src_blockchain/bc_wallet/AbstractAddressStore.h index 4c420bf9..5fa85c9a 100644 --- a/src_blockchain/bc_wallet/AbstractAddressStore.h +++ b/src_blockchain/bc_wallet/AbstractAddressStore.h @@ -63,7 +63,7 @@ class AbstractAddressStore { protected: uint16_t zone; HdWalletSeed* encryptedSeed; - uint64_t adressSerial; + uint64_t addressSerial; ArrayList* list; StatusStore* store; diff --git a/src_blockchain/bc_wallet/ChangeAddressStore.cpp b/src_blockchain/bc_wallet/ChangeAddressStore.cpp index 609b0c39..b2615786 100644 --- a/src_blockchain/bc_wallet/ChangeAddressStore.cpp +++ b/src_blockchain/bc_wallet/ChangeAddressStore.cpp @@ -35,8 +35,8 @@ AddressDescriptor* ChangeAddressStore::getNextChangeAddress(const IWalletDataEnc this->currentIndex = 0; } - if(this->currentIndex >= this->adressSerial && this->list->size() < this->numAddressInThisGroup){ - AddressAndPrivateKey* pair = createNewAddressAndPrivateKey(encoder, this->adressSerial++); + if(this->currentIndex >= this->addressSerial && this->list->size() < this->numAddressInThisGroup){ + AddressAndPrivateKey* pair = createNewAddressAndPrivateKey(encoder, this->addressSerial++); this->list->addElement(pair); save(); } @@ -57,7 +57,7 @@ void ChangeAddressStore::load(const IWalletDataEncoder *encoder) { this->currentIndex = this->store->getLongValue(KEY_CURRENT_INDEX); this->numAddressInThisGroup = this->store->getLongValue(KEY_NUM_GROUP); - for(int i = 0; i != this->adressSerial; ++i){ + for(int i = 0; i != this->addressSerial; ++i){ AddressAndPrivateKey* pair = createNewAddressAndPrivateKey(encoder, i); this->list->addElement(pair); diff --git a/src_blockchain/bc_wallet/HdWallet.cpp b/src_blockchain/bc_wallet/HdWallet.cpp index a42dd187..197b3113 100644 --- a/src_blockchain/bc_wallet/HdWallet.cpp +++ b/src_blockchain/bc_wallet/HdWallet.cpp @@ -32,12 +32,7 @@ HdWallet::HdWallet(const File* baseDir) { } HdWallet::~HdWallet() { - delete this->store; - - this->accounts->deleteElements(); - delete this->accounts; - - delete this->encodedSeed; + close(); delete this->baseDir; } @@ -99,6 +94,21 @@ void HdWallet::load(const IWalletDataEncoder *encoder) { this->defaultZone = this->store->getShortValue(KEY_DEFAULT_ZONE); } +void HdWallet::close() { + if(this->store != nullptr){ + delete this->store, this->store = nullptr; + } + + if(this->accounts != nullptr){ + this->accounts->deleteElements(); + delete this->accounts, this->accounts = nullptr; + } + + if(this->encodedSeed != nullptr){ + delete this->encodedSeed, this->encodedSeed = nullptr; + } +} + HdWalletSeed* HdWallet::getRootSeed(const IWalletDataEncoder* encoder) const { HdWalletSeed* rootSeed = encoder->decode(this->encodedSeed); diff --git a/src_blockchain/bc_wallet/HdWallet.h b/src_blockchain/bc_wallet/HdWallet.h index 9c95cf9c..5901dff8 100644 --- a/src_blockchain/bc_wallet/HdWallet.h +++ b/src_blockchain/bc_wallet/HdWallet.h @@ -57,6 +57,7 @@ class HdWallet { void save(); void load(const IWalletDataEncoder* encoder); + void close(); ArrayList* getBloomFilters(const IWalletDataEncoder* encoder) const noexcept; diff --git a/src_blockchain/bc_wallet/ReceivingAddressStore.cpp b/src_blockchain/bc_wallet/ReceivingAddressStore.cpp index 6d2fbfb6..2a0ed56c 100644 --- a/src_blockchain/bc_wallet/ReceivingAddressStore.cpp +++ b/src_blockchain/bc_wallet/ReceivingAddressStore.cpp @@ -27,7 +27,7 @@ ReceivingAddressStore::~ReceivingAddressStore() { void ReceivingAddressStore::init(const IWalletDataEncoder *encoder) { int maxLoop = this->maxAddress; for(int i = 0; i != maxLoop; ++i){ - AddressAndPrivateKey* pair = createNewAddressAndPrivateKey(encoder, this->adressSerial++); + AddressAndPrivateKey* pair = createNewAddressAndPrivateKey(encoder, this->addressSerial++); this->list->addElement(pair); } @@ -47,14 +47,14 @@ void ReceivingAddressStore::load(const IWalletDataEncoder *encoder) { this->maxAddress = this->store->getShortValue(KEY_MAX_ADDRESS); - for(int i = 0; i != this->adressSerial; ++i){ + for(int i = 0; i != this->addressSerial; ++i){ AddressAndPrivateKey* pair = createNewAddressAndPrivateKey(encoder, i); this->list->addElement(pair); } } -void ReceivingAddressStore::exportAddress2Filger(BloomFilter1024 *filter) { +void ReceivingAddressStore::exportAddress2Filter(BloomFilter1024 *filter) { int maxLoop = this->list->size(); for(int i = 0; i != maxLoop; ++i){ AddressAndPrivateKey* addressKey = this->list->get(i); diff --git a/src_blockchain/bc_wallet/ReceivingAddressStore.h b/src_blockchain/bc_wallet/ReceivingAddressStore.h index 0b803af2..30c0efcd 100644 --- a/src_blockchain/bc_wallet/ReceivingAddressStore.h +++ b/src_blockchain/bc_wallet/ReceivingAddressStore.h @@ -27,7 +27,7 @@ class ReceivingAddressStore : public AbstractAddressStore { virtual void save(); virtual void load(const IWalletDataEncoder *encoder); - void exportAddress2Filger(BloomFilter1024* filter); + void exportAddress2Filter(BloomFilter1024* filter); private: int maxAddress; diff --git a/src_blockchain/bc_wallet/WalletAccount.cpp b/src_blockchain/bc_wallet/WalletAccount.cpp index ae7d24fc..224b39ce 100644 --- a/src_blockchain/bc_wallet/WalletAccount.cpp +++ b/src_blockchain/bc_wallet/WalletAccount.cpp @@ -388,7 +388,7 @@ void WalletAccount::createBloomFilter(const IWalletDataEncoder* encoder) { this->bloomFilter = new BloomFilter1024(); - this->receivingAddresses->exportAddress2Filger(this->bloomFilter); + this->receivingAddresses->exportAddress2Filter(this->bloomFilter); this->changeAddresses->exportAddress2Filter(this->bloomFilter, encoder); } diff --git a/src_blockchain/bc_wallet_filter/BloomHash1024.cpp b/src_blockchain/bc_wallet_filter/BloomHash1024.cpp index 5cddc079..c2483e1d 100644 --- a/src_blockchain/bc_wallet_filter/BloomHash1024.cpp +++ b/src_blockchain/bc_wallet_filter/BloomHash1024.cpp @@ -43,6 +43,11 @@ BloomHash1024::~BloomHash1024() { } +/** + * make flag + * @param base + * @param pos + */ void BloomHash1024::setBits(uint16_t base, int pos) noexcept { uint16_t val = base >> 8; val = val << (pos * NUM_EXTRA_BITS); diff --git a/src_blockchain/bc_wallet_net/NetworkWallet.cpp b/src_blockchain/bc_wallet_net/NetworkWallet.cpp index f201a736..cf54a553 100644 --- a/src_blockchain/bc_wallet_net/NetworkWallet.cpp +++ b/src_blockchain/bc_wallet_net/NetworkWallet.cpp @@ -67,8 +67,14 @@ void NetworkWallet::init() { this->clientCommandProcessor->init(); } +void NetworkWallet::resetComamndQueue() { + this->clientCommandProcessor->init(); + this->clientCommandProcessor->createBlank(); +} + void NetworkWallet::closeData() noexcept { if(this->walletData != nullptr){ + this->walletData->close(); delete this->walletData; this->walletData = nullptr; } @@ -88,10 +94,9 @@ NetworkWallet* NetworkWallet::createNewWallet(const File *dir, const UnicodeStri return __STP_MV(wallet); } - - void NetworkWallet::doCreateWallet(const IWalletDataEncoder *encoder, const HdWalletSeed *seed, uint16_t zone, int defaultMaxAddress) { this->walletData->createHdWallet(seed, zone, encoder, defaultMaxAddress); + this->init(); } HdWalletSeed* NetworkWallet::getRootSeed(const IWalletDataEncoder* encoder) const { @@ -112,6 +117,23 @@ NetworkWallet* NetworkWallet::resotreWallet(const File *dir, const UnicodeString return __STP_MV(wallet); } +NetworkWallet* NetworkWallet::openWallet(const File *dir, const UnicodeString *pass, + ISystemLogger *logger, const CodablecashSystemParam *config, const WalletConfig *walletConfig) { + NetworkWallet* wallet = new NetworkWallet(dir, logger, config, walletConfig); __STP(wallet); + wallet->resetComamndQueue(); + + PasswordEncoder enc(pass); + wallet->doOpeneWallet(&enc); + wallet->openData(); + + return __STP_MV(wallet); +} + +void NetworkWallet::doOpeneWallet(const IWalletDataEncoder *encoder) { + this->walletData->openHdWallet(encoder); + this->resetComamndQueue(); +} + void NetworkWallet::setNetworkSeeder(INetworkSeeder *seeder) noexcept { HdWallet* hdWallet = this->walletData->getHdWallet(); @@ -132,11 +154,15 @@ AddressDescriptor* NetworkWallet::getAddressDescriptor(int accountIndex, int add } void NetworkWallet::createData() { - this->walletData->createBlank(); + this->walletData->createBlankData(); this->clientCommandProcessor->createBlank(); } +void NetworkWallet::openData() { + this->walletData->openData(); +} + void NetworkWallet::initNetwork(INetworkSeeder *seeder, const IWalletDataEncoder* encoder) { setNetworkSeeder(seeder); diff --git a/src_blockchain/bc_wallet_net/NetworkWallet.h b/src_blockchain/bc_wallet_net/NetworkWallet.h index efc66792..42bee0ef 100644 --- a/src_blockchain/bc_wallet_net/NetworkWallet.h +++ b/src_blockchain/bc_wallet_net/NetworkWallet.h @@ -40,6 +40,7 @@ class NetworkWallet { virtual ~NetworkWallet(); void init(); + void resetComamndQueue(); void closeData() noexcept; @@ -47,8 +48,12 @@ class NetworkWallet { , const CodablecashSystemParam *config, const WalletConfig* walletConfig); static NetworkWallet* resotreWallet(const File* dir, const UnicodeString* pass, uint16_t zone, const HdWalletSeed* rootSeed, int defaultMaxAddress, ISystemLogger* logger , const CodablecashSystemParam *config, const WalletConfig* walletConfig); + static NetworkWallet* openWallet(const File* dir, const UnicodeString* pass, ISystemLogger* logger + , const CodablecashSystemParam *config, const WalletConfig* walletConfig); void createData(); + void openData(); + HdWalletSeed* getRootSeed(const IWalletDataEncoder* encoder) const; void setStakingSourceId(const NodeIdentifierSource* source, const IWalletDataEncoder* encoder); @@ -89,6 +94,7 @@ class NetworkWallet { private: void setNetworkSeeder(INetworkSeeder *seeder) noexcept; void doCreateWallet(const IWalletDataEncoder* encoder, const HdWalletSeed* seed, uint16_t zone, int defaultMaxAddress); + void doOpeneWallet(const IWalletDataEncoder *encoder); private: File* baseDir; diff --git a/src_blockchain/bc_wallet_net_data/NetworkWalletData.cpp b/src_blockchain/bc_wallet_net_data/NetworkWalletData.cpp index 41beaac4..f2dbdbc6 100644 --- a/src_blockchain/bc_wallet_net_data/NetworkWalletData.cpp +++ b/src_blockchain/bc_wallet_net_data/NetworkWalletData.cpp @@ -58,7 +58,7 @@ NetworkWalletData::NetworkWalletData(const File* baseDir, ISystemLogger* logger, this->hdWallet = nullptr; this->headerManager = nullptr; - this->detector = nullptr; + this->detector = new HeadBlockDetector(this->logger); this->transactionGroupData = new TransactionGroupDataStore(this->baseDir); @@ -77,8 +77,6 @@ NetworkWalletData::NetworkWalletData(const File* baseDir, ISystemLogger* logger, NetworkWalletData::~NetworkWalletData() { close(); - delete this->hdWallet; - delete this->mempool; delete this->headerManager; @@ -92,6 +90,30 @@ NetworkWalletData::~NetworkWalletData() { delete this->gateLock; } + +void NetworkWalletData::openHdWallet(const IWalletDataEncoder *encoder) { + StackWriteLock __lock(this->gateLock, __FILE__, __LINE__); + + __initStatusStore(); + __loadStatus(); + + delete this->hdWallet; + File* hdbase = this->baseDir->get(L"hd"); __STP(hdbase); + this->hdWallet = HdWallet::loadWallet(hdbase, encoder); +} + +void NetworkWalletData::openData() { + StackWriteLock __lock(this->gateLock, __FILE__, __LINE__); + + this->headerManager = new BlockHeaderStoreManager(this->baseDir, CodablecashBlockchain::DEFAULT_SECTION_LIMIT); + + this->transactionGroupData->open(); + this->mempool->open(); + + __initStatusStore(); + __loadStatus(); +} + void NetworkWalletData::close() noexcept { StackWriteLock __lock(this->gateLock, __FILE__, __LINE__); @@ -112,6 +134,11 @@ void NetworkWalletData::close() noexcept { delete this->statusStore; this->statusStore = nullptr; } + + if(this->hdWallet != nullptr){ + this->hdWallet->close(); + delete this->hdWallet; this->hdWallet = nullptr; + } } void NetworkWalletData::createHdWallet(const HdWalletSeed *seed, uint16_t defaultZone, const IWalletDataEncoder *encoder, int defaultMaxAddress) { @@ -129,11 +156,10 @@ void NetworkWalletData::createHdWallet(const HdWalletSeed *seed, uint16_t defaul __saveStatus(); } -void NetworkWalletData::createBlank() { +void NetworkWalletData::createBlankData() { StackWriteLock __lock(this->gateLock, __FILE__, __LINE__); this->headerManager = new BlockHeaderStoreManager(this->baseDir, CodablecashBlockchain::DEFAULT_SECTION_LIMIT); - this->detector = new HeadBlockDetector(this->logger); this->transactionGroupData->initBlank(); this->transactionGroupData->open(); @@ -375,6 +401,11 @@ void NetworkWalletData::__saveStatus() { this->statusStore->addLongValue(KEY_FINALIZED_HEIGHT, this->finalizedHeight); } +void NetworkWalletData::__loadStatus() { + this->zone = this->statusStore->getShortValue(KEY_ZONE); + this->finalizedHeight = this->statusStore->getLongValue(KEY_FINALIZED_HEIGHT); +} + BlockHeaderStoreManager* NetworkWalletData::getHeaderManager(uint16_t zone) const noexcept { return this->headerManager; } diff --git a/src_blockchain/bc_wallet_net_data/NetworkWalletData.h b/src_blockchain/bc_wallet_net_data/NetworkWalletData.h index 539f7b27..1d9fb014 100644 --- a/src_blockchain/bc_wallet_net_data/NetworkWalletData.h +++ b/src_blockchain/bc_wallet_net_data/NetworkWalletData.h @@ -57,8 +57,11 @@ class NetworkWalletData : public IBlockchainStoreProvider { void close() noexcept; + void openHdWallet(const IWalletDataEncoder *encoder); void createHdWallet(const HdWalletSeed* seed, uint16_t defaultZone, const IWalletDataEncoder* encoder, int defaultMaxAddress); - void createBlank(); + + void openData(); + void createBlankData(); HdWallet* getHdWallet() const noexcept { return this->hdWallet; @@ -79,6 +82,7 @@ class NetworkWalletData : public IBlockchainStoreProvider { } void __saveStatus(); + void __loadStatus(); virtual BlockHeaderStoreManager* getHeaderManager(uint16_t zone) const noexcept; virtual BlockBodyStoreManager* getBlockBodyStoreManager(uint16_t zone) const noexcept; diff --git a/src_blockchain/bc_wallet_net_data/TransactionGroupDataStore.cpp b/src_blockchain/bc_wallet_net_data/TransactionGroupDataStore.cpp index 6ea922be..4c5cffc8 100644 --- a/src_blockchain/bc_wallet_net_data/TransactionGroupDataStore.cpp +++ b/src_blockchain/bc_wallet_net_data/TransactionGroupDataStore.cpp @@ -50,6 +50,7 @@ void TransactionGroupDataStore::initBlank() { config.nodeNumber = 8; config.defaultSize = 1024; config.blockSize = 32; + btree.create(&config); } @@ -64,8 +65,8 @@ void TransactionGroupDataStore::open() { BtreeOpenConfig opconf; opconf.numDataBuffer = 256; opconf.numNodeBuffer = 512; - this->headerGroupStore->open(&opconf); + this->headerGroupStore->open(&opconf); } void TransactionGroupDataStore::close() noexcept { diff --git a/src_blockchain/bc_wallet_net_processor/NetworkClientCommandProcessor.cpp b/src_blockchain/bc_wallet_net_processor/NetworkClientCommandProcessor.cpp index 0a31cdc0..ae6e0775 100644 --- a/src_blockchain/bc_wallet_net_processor/NetworkClientCommandProcessor.cpp +++ b/src_blockchain/bc_wallet_net_processor/NetworkClientCommandProcessor.cpp @@ -62,14 +62,16 @@ NetworkClientCommandProcessor::~NetworkClientCommandProcessor() { } void NetworkClientCommandProcessor::init() { - const File* baseDir = networkWallet->getBaseDir(); + if(this->queueProcessor == nullptr && this->pendingQueue == nullptr){ + const File* baseDir = networkWallet->getBaseDir(); - File* dir = baseDir->get(PROCESSER_DIR); __STP(dir); - dir->deleteDir(); - dir->mkdirs(); + File* dir = baseDir->get(PROCESSER_DIR); __STP(dir); + dir->deleteDir(); + dir->mkdirs(); - this->queueProcessor = new ClientCommandsQueueProcessor(this->networkWallet, dir, this->logger); - this->pendingQueue = new PendingClientCommandsQueue(dir); + this->queueProcessor = new ClientCommandsQueueProcessor(this->networkWallet, dir, this->logger); + this->pendingQueue = new PendingClientCommandsQueue(dir); + } } diff --git a/src_blockchain/bc_wallet_trx/AbstractWalletTransactionHandler.cpp b/src_blockchain/bc_wallet_trx/AbstractWalletTransactionHandler.cpp index 536db8f1..e0410f6d 100644 --- a/src_blockchain/bc_wallet_trx/AbstractWalletTransactionHandler.cpp +++ b/src_blockchain/bc_wallet_trx/AbstractWalletTransactionHandler.cpp @@ -61,7 +61,7 @@ void AbstractWalletTransactionHandler::__importTransaction(const AbstractBlockch const AddressDescriptor* addressDesc = utxo->getAddress(); - if(this->account->hasAddress(addressDesc)){ + if(!utxo->isRemote() && this->account->hasAddress(addressDesc)){ trxRepo->importUtxo(utxo); imported = true; } diff --git a/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp b/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp index 74fdb294..02dbcdec 100644 --- a/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp +++ b/src_blockchain/bc_wallet_trx/BalanceTransactionWalletHandler.cpp @@ -69,7 +69,7 @@ BalanceTransferTransaction* BalanceTransactionWalletHandler::createTransaction( BalanceTransferTransaction* BalanceTransactionWalletHandler::createTransaction(ArrayList* dest, const BalanceUnit& feeRate, bool feeIncluded, const IWalletDataEncoder *encoder, ITransactionBuilderContext *context) { if(feeIncluded){ - createFeeIncludedTransaction(dest, feeRate, encoder, context); + return createFeeIncludedTransaction(dest, feeRate, encoder, context); } IUtxoCollector* collector = context->getUtxoCollector(); __STP(collector); diff --git a/src_blockchain_p2p/data_history_data/TransactionTransferData.cpp b/src_blockchain_p2p/data_history_data/TransactionTransferData.cpp index 127ccbfb..9ec6f516 100644 --- a/src_blockchain_p2p/data_history_data/TransactionTransferData.cpp +++ b/src_blockchain_p2p/data_history_data/TransactionTransferData.cpp @@ -56,7 +56,7 @@ IBlockObject* TransactionTransferData::copyData() const noexcept { return new TransactionTransferData(*this); } -void TransactionTransferData::setTransaction( const AbstractBlockchainTransaction *trx) noexcept { +void TransactionTransferData::setTransaction(const AbstractBlockchainTransaction *trx) noexcept { delete this->trx; this->trx = dynamic_cast(trx->copyData()); } diff --git a/src_db/base/HashMapKeySet.h b/src_db/base/HashMapKeySet.h index e4232fe0..35d4d5e7 100644 --- a/src_db/base/HashMapKeySet.h +++ b/src_db/base/HashMapKeySet.h @@ -29,7 +29,7 @@ class HashMapKeySet { } virtual ~HashMapKeySet() noexcept { - typename HashMapRawArray::Iterator it = this->list->iterator(); + typename HashMapRawArray::InternalIterator it = this->list->iterator(); while(it.hasNext()){ HashMapInternalElement* element = it.next(); @@ -171,7 +171,7 @@ class HashMapKeySet { } private: - typename HashMapRawArray::Iterator internalIt; + typename HashMapRawArray::InternalIterator internalIt; bool outputNull; HashMapInternalElement* nullElement; }; diff --git a/src_db/base/HashMapRawArray.h b/src_db/base/HashMapRawArray.h index 65564170..3d6f04e6 100644 --- a/src_db/base/HashMapRawArray.h +++ b/src_db/base/HashMapRawArray.h @@ -39,6 +39,8 @@ class HashMapInternalElement { }; }; + + template class HashMapRawArray { public: @@ -107,13 +109,13 @@ class HashMapRawArray { bitset.clear(); numElements = 0; } - class Iterator { + class InternalIterator { public: int hashCode; int index; ArrayList, typename HashMapInternalElement::ValueCompare>** arrays; const RawBitSet* bitset; - Iterator(ArrayList, typename HashMapInternalElement::ValueCompare>** ptr, RawBitSet* bitset) throw() + InternalIterator(ArrayList, typename HashMapInternalElement::ValueCompare>** ptr, RawBitSet* bitset) throw() : hashCode(0), index(0), arrays(ptr), bitset(bitset) {} bool hasNext() const throw() { ArrayList, typename HashMapInternalElement::ValueCompare>* current = arrays[hashCode]; @@ -151,8 +153,8 @@ class HashMapRawArray { } }; - Iterator iterator() throw() { - return Iterator(arrays, &bitset); + InternalIterator iterator() throw() { + return InternalIterator(arrays, &bitset); } private: int getHash(const HashMapInternalElement* ptr) const throw() { diff --git a/src_db/base/RawBitSet.cpp b/src_db/base/RawBitSet.cpp index 36bae767..1a197e1f 100644 --- a/src_db/base/RawBitSet.cpp +++ b/src_db/base/RawBitSet.cpp @@ -24,7 +24,7 @@ void RawBitSet::BitsetArray::growLength(uint32_t len) noexcept { } RawBitSet::RawBitSet(uint32_t nbits) noexcept { - this->bits = new BitsetArray( ((nbits >> OFFSET) + ((nbits & RIGHT_BITS) > 0)) ? 1 : 0 ); + this->bits = new BitsetArray( ((nbits >> OFFSET) + (((nbits & RIGHT_BITS) > 0) ? 1 : 0)) ); this->_needClear = false; this->actualArrayLength = 0; this->isLengthActual = true; diff --git a/src_db/base_thread/SynchronizedLock.h b/src_db/base_thread/SynchronizedLock.h index 131d24e6..c0e5d8d2 100644 --- a/src_db/base_thread/SynchronizedLock.h +++ b/src_db/base_thread/SynchronizedLock.h @@ -26,7 +26,7 @@ class SynchronizedLock : public ILock { void wait(); void notifyAll(); void notify(); - int tryLock(); + //int tryLock(); static uint64_t getObjectSize() noexcept; diff --git a/src_db/btree/TreeNode.h b/src_db/btree/TreeNode.h index ee26661a..4bb68e2c 100644 --- a/src_db/btree/TreeNode.h +++ b/src_db/btree/TreeNode.h @@ -26,7 +26,7 @@ class TreeNode: public AbstractTreeNode { TreeNode(); public: TreeNode(const TreeNode& inst); - explicit TreeNode(int numChildren, AbstractBtreeKey* key, bool reaf); + explicit TreeNode(int numChildren, AbstractBtreeKey* key, bool leaf); explicit TreeNode(bool isroot, int numChildren, AbstractBtreeKey* key, bool reaf); virtual ~TreeNode(); diff --git a/src_db/filestore/LongRangeList.cpp b/src_db/filestore/LongRangeList.cpp index 6eaba753..10ee5c4d 100644 --- a/src_db/filestore/LongRangeList.cpp +++ b/src_db/filestore/LongRangeList.cpp @@ -65,7 +65,6 @@ void LongRangeList::removeRange(const LongRange* range) noexcept { delete r; } } - } diff --git a/src_db/filestore_variable_block/VariableBlockFileStore.h b/src_db/filestore_variable_block/VariableBlockFileStore.h index 19cc105d..f16178b5 100644 --- a/src_db/filestore_variable_block/VariableBlockFileStore.h +++ b/src_db/filestore_variable_block/VariableBlockFileStore.h @@ -25,7 +25,7 @@ class VariableBlockFileStore : public FileStore, public IBlockFileStore { virtual ~VariableBlockFileStore(); virtual void createStore(bool del, uint64_t defaultSize, uint64_t blockSize) noexcept(false); - void createStore(bool del, uint64_t defaultSize, uint64_t blockSize, uint64_t extendBlocks) noexcept(false); + void createStore(bool del, uint64_t defaultSize, uint64_t blockUnitSize, uint64_t extendBlocks) noexcept(false); virtual void open(bool sync) noexcept(false); virtual void close() noexcept; diff --git a/src_db/filestore_variable_block/VariableBlockHeader.cpp b/src_db/filestore_variable_block/VariableBlockHeader.cpp index e29b4ab4..d5552e60 100644 --- a/src_db/filestore_variable_block/VariableBlockHeader.cpp +++ b/src_db/filestore_variable_block/VariableBlockHeader.cpp @@ -165,7 +165,7 @@ VariableBlock* VariableBlockHeader::allocMaxFragment(uint64_t size) { return allocMaxFragment(range, size); } -VariableBlock* VariableBlockHeader::allocMaxFragment(const LongRange *range, uint64_t size) { +VariableBlock* VariableBlockHeader::allocMaxFragment(const LongRange *range, uint64_t size) { uint64_t maxAvailable = availableWithRange(range); if(size > maxAvailable){ return allocateAll(range); diff --git a/src_db/json_object/AbstractJsonObject.h b/src_db/json_object/AbstractJsonObject.h index 51b84371..97257368 100644 --- a/src_db/json_object/AbstractJsonObject.h +++ b/src_db/json_object/AbstractJsonObject.h @@ -11,6 +11,7 @@ namespace alinous { class ByteBuffer; +class UnicodeString; } using namespace alinous; @@ -36,6 +37,8 @@ class AbstractJsonObject { virtual void toBinary(ByteBuffer *out) const = 0; virtual void fromBinary(ByteBuffer *in) = 0; static AbstractJsonObject* createFromBinary(ByteBuffer* in); + + virtual UnicodeString* toString() const = 0; }; } /* namespace codablecash */ diff --git a/src_db/json_object/JsonArrayObject.cpp b/src_db/json_object/JsonArrayObject.cpp index 22c2e5b1..52af7bb8 100644 --- a/src_db/json_object/JsonArrayObject.cpp +++ b/src_db/json_object/JsonArrayObject.cpp @@ -12,6 +12,8 @@ #include "bc_base/BinaryUtils.h" +#include "base/UnicodeString.h" +#include "base/StackRelease.h" namespace codablecash { @@ -108,4 +110,23 @@ void JsonArrayObject::fromBinary(ByteBuffer *in) { } } +UnicodeString* JsonArrayObject::toString() const { + UnicodeString* str = new UnicodeString(L"["); + + int maxLoop = this->list->size(); + for(int i = 0; i != maxLoop; ++i){ + AbstractJsonObject* obj = this->list->get(i); + + if(i != 0){ + str->append(L", "); + } + + UnicodeString* inner = obj->toString(); __STP(inner); + str->append(inner); + } + + str->append(L"]"); + return str; +} + } /* namespace codablecash */ diff --git a/src_db/json_object/JsonArrayObject.h b/src_db/json_object/JsonArrayObject.h index f14e5720..31542f51 100644 --- a/src_db/json_object/JsonArrayObject.h +++ b/src_db/json_object/JsonArrayObject.h @@ -39,6 +39,8 @@ class JsonArrayObject : public AbstractJsonContainer { virtual void toBinary(ByteBuffer *out) const; virtual void fromBinary(ByteBuffer *in); + virtual UnicodeString* toString() const; + private: ArrayList* list; }; diff --git a/src_db/json_object/JsonBooleanValue.cpp b/src_db/json_object/JsonBooleanValue.cpp index 4b3f11e8..6a09679b 100644 --- a/src_db/json_object/JsonBooleanValue.cpp +++ b/src_db/json_object/JsonBooleanValue.cpp @@ -7,10 +7,13 @@ #include "json_object/JsonBooleanValue.h" +#include "base/UnicodeString.h" + #include "base_io/ByteBuffer.h" #include "ext_arguments/BoolArgument.h" + namespace codablecash { JsonBooleanValue::JsonBooleanValue(const JsonBooleanValue &inst) { @@ -56,4 +59,11 @@ AbstractFunctionExtArguments* JsonBooleanValue::toFunctionExtArgument() const { return new BoolArgument(this->value); } +UnicodeString* JsonBooleanValue::toString() const { + if(this->value == true){ + return new UnicodeString(L"true"); + } + return new UnicodeString(L"false"); +} + } /* namespace codablecash */ diff --git a/src_db/json_object/JsonBooleanValue.h b/src_db/json_object/JsonBooleanValue.h index 853eef93..dbe7e1b6 100644 --- a/src_db/json_object/JsonBooleanValue.h +++ b/src_db/json_object/JsonBooleanValue.h @@ -39,6 +39,8 @@ class JsonBooleanValue : public AbstractJsonValue { virtual AbstractFunctionExtArguments* toFunctionExtArgument() const; + virtual UnicodeString* toString() const; + private: bool value; }; diff --git a/src_db/json_object/JsonNumericValue.cpp b/src_db/json_object/JsonNumericValue.cpp index ea5b8a57..725c0fb9 100644 --- a/src_db/json_object/JsonNumericValue.cpp +++ b/src_db/json_object/JsonNumericValue.cpp @@ -13,6 +13,7 @@ #include "engine/sc_analyze/AnalyzedType.h" +#include "base/Integer.h" namespace codablecash { @@ -62,4 +63,8 @@ AbstractFunctionExtArguments* JsonNumericValue::toFunctionExtArgument() const { return new NumericArgument(this->value, AnalyzedType::TYPE_INT); } +UnicodeString* JsonNumericValue::toString() const { + return Integer::toString(this->value, 10); +} + } /* namespace codablecash */ diff --git a/src_db/json_object/JsonNumericValue.h b/src_db/json_object/JsonNumericValue.h index 3a42b7aa..b0d546e8 100644 --- a/src_db/json_object/JsonNumericValue.h +++ b/src_db/json_object/JsonNumericValue.h @@ -39,6 +39,8 @@ class JsonNumericValue : public AbstractJsonValue { virtual AbstractFunctionExtArguments* toFunctionExtArgument() const; + virtual UnicodeString* toString() const; + private: int value; }; diff --git a/src_db/json_object/JsonObject.cpp b/src_db/json_object/JsonObject.cpp index 2c40a230..f237639f 100644 --- a/src_db/json_object/JsonObject.cpp +++ b/src_db/json_object/JsonObject.cpp @@ -144,4 +144,23 @@ void JsonObject::fromBinary(ByteBuffer *in) { } } +UnicodeString* JsonObject::toString() const { + UnicodeString* str = new UnicodeString(L"{"); + + int maxLoop = this->list->size(); + for(int i = 0; i != maxLoop; ++i){ + AbstractJsonObject* obj = this->list->get(i); + + if(i != 0){ + str->append(L", "); + } + + UnicodeString* inner = obj->toString(); __STP(inner); + str->append(inner); + } + + str->append(L"}"); + return str; +} + } /* namespace codablecash */ diff --git a/src_db/json_object/JsonObject.h b/src_db/json_object/JsonObject.h index 571571bc..ca87a187 100644 --- a/src_db/json_object/JsonObject.h +++ b/src_db/json_object/JsonObject.h @@ -42,6 +42,8 @@ class JsonObject : public AbstractJsonContainer { virtual void toBinary(ByteBuffer *out) const; virtual void fromBinary(ByteBuffer *in); + virtual UnicodeString* toString() const; + private: ArrayList* list; }; diff --git a/src_db/json_object/JsonStringValue.cpp b/src_db/json_object/JsonStringValue.cpp index e188d1d2..a941e376 100644 --- a/src_db/json_object/JsonStringValue.cpp +++ b/src_db/json_object/JsonStringValue.cpp @@ -78,4 +78,8 @@ AbstractFunctionExtArguments* JsonStringValue::toFunctionExtArgument() const { return new StringArgument(this->value); } +UnicodeString* JsonStringValue::toString() const { + return new UnicodeString(this->value); +} + } /* namespace codablecash */ diff --git a/src_db/json_object/JsonStringValue.h b/src_db/json_object/JsonStringValue.h index 8e2434c8..e506d62a 100644 --- a/src_db/json_object/JsonStringValue.h +++ b/src_db/json_object/JsonStringValue.h @@ -43,6 +43,8 @@ class JsonStringValue : public AbstractJsonValue { virtual AbstractFunctionExtArguments* toFunctionExtArgument() const; + virtual UnicodeString* toString() const; + private: UnicodeString* value; }; diff --git a/src_db/json_object/JsonValuePair.cpp b/src_db/json_object/JsonValuePair.cpp index 081040be..be39f2db 100644 --- a/src_db/json_object/JsonValuePair.cpp +++ b/src_db/json_object/JsonValuePair.cpp @@ -14,6 +14,8 @@ #include "base_io/ByteBuffer.h" #include "base/StackRelease.h" +#include "base/UnicodeString.h" + namespace codablecash { JsonValuePair::JsonValuePair(const JsonValuePair& inst) { @@ -87,4 +89,18 @@ void JsonValuePair::fromBinary(ByteBuffer *in) { BinaryUtils::checkNotNull(this->value); } +UnicodeString* JsonValuePair::toString() const { + UnicodeString* str = new UnicodeString(L""); __STP(str); + + UnicodeString* kstr = this->key->toString(); __STP(kstr); + str->append(kstr); + + str->append(L" : "); + + UnicodeString* vstr = this->value->toString(); __STP(vstr); + str->append(vstr); + + return __STP_MV(str); +} + } /* namespace codablecash */ diff --git a/src_db/json_object/JsonValuePair.h b/src_db/json_object/JsonValuePair.h index 6cb36c8f..fc98ded4 100644 --- a/src_db/json_object/JsonValuePair.h +++ b/src_db/json_object/JsonValuePair.h @@ -42,6 +42,8 @@ class JsonValuePair : public AbstractJsonObject { virtual void toBinary(ByteBuffer *out) const; virtual void fromBinary(ByteBuffer *in); + virtual UnicodeString* toString() const; + private: AbstractJsonValue* key; AbstractJsonObject* value; diff --git a/src_simnet/CMakeLists.txt b/src_simnet/CMakeLists.txt new file mode 100644 index 00000000..f60069ae --- /dev/null +++ b/src_simnet/CMakeLists.txt @@ -0,0 +1,13 @@ + + +set(__dirsrc "") + +# import source codes +add_subdirectory(sim) +add_subdirectory(sim_net) +add_subdirectory(sim_net_client) + +message(STATUS "src_simnet : ${__dirsrc}") + +set_parentv("${__dirsrc}" src_simnet top_src_simnet) + diff --git a/src_simnet/sim/CMakeLists.txt b/src_simnet/sim/CMakeLists.txt new file mode 100644 index 00000000..c9740766 --- /dev/null +++ b/src_simnet/sim/CMakeLists.txt @@ -0,0 +1,11 @@ + +set(__src + CodableSimNet.cpp + InstanceSimulator.cpp + ZoneInstanceConfig.cpp + ZoneSimulator.cpp +) +handle_sub(codablecashlib "${__src}" simnet sim) + + + diff --git a/src_simnet/sim/CodableSimNet.cpp b/src_simnet/sim/CodableSimNet.cpp new file mode 100644 index 00000000..f1ab65e1 --- /dev/null +++ b/src_simnet/sim/CodableSimNet.cpp @@ -0,0 +1,59 @@ +/* + * CodableSimNet.cpp + * + * Created on: Sep 2, 2026 + * Author: iizuka + */ + +#include "sim/CodableSimNet.h" +#include "sim/ZoneSimulator.h" + +#include "json_object/JsonObject.h" +#include "json_object/JsonArrayObject.h" +#include "json_object/JsonStringValue.h" +#include "json_object/JsonValuePair.h" + +#include "base/StackRelease.h" + + +namespace codablecash { + +CodableSimNet::CodableSimNet() { + this->zones = new ArrayList(); +} + +CodableSimNet::~CodableSimNet() { + int maxLoop = this->zones->size(); + for(int i = 0; i != maxLoop; ++i){ + ZoneSimulator* zsim = this->zones->get(i); + zsim->shutdown(); + } + + this->zones->deleteElements(); + delete this->zones; +} + +JsonObject* CodableSimNet::makeJsonSettingObject() { + JsonObject* topObject = new JsonObject(); __STP(topObject); + + JsonArrayObject* zonesArray = new JsonArrayObject(); + + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"zoneConfigs")); + pair->setValue(zonesArray); + topObject->add(pair); + } + + int maxLoop = this->zones->size(); + for(int i = 0; i != maxLoop; ++i){ + ZoneSimulator* zsim = this->zones->get(i); + + JsonObject* obj = zsim->makeJsonSettingObject(); + zonesArray->add(obj); + } + + return __STP_MV(topObject); +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim/CodableSimNet.h b/src_simnet/sim/CodableSimNet.h new file mode 100644 index 00000000..3fc8a0ea --- /dev/null +++ b/src_simnet/sim/CodableSimNet.h @@ -0,0 +1,33 @@ +/* + * CodableSimNet.h + * + * Created on: Sep 2, 2026 + * Author: iizuka + */ + +#ifndef SIM_CODABLESIMNET_H_ +#define SIM_CODABLESIMNET_H_ + +#include "base/ArrayList.h" + +using namespace alinous; + +namespace codablecash { + +class ZoneSimulator; +class JsonObject; + +class CodableSimNet { +public: + CodableSimNet(); + virtual ~CodableSimNet(); + + JsonObject* makeJsonSettingObject(); + +private: + ArrayList* zones; +}; + +} /* namespace codablecash */ + +#endif /* SIM_CODABLESIMNET_H_ */ diff --git a/src_simnet/sim/InstanceSimulator.cpp b/src_simnet/sim/InstanceSimulator.cpp new file mode 100644 index 00000000..7a674944 --- /dev/null +++ b/src_simnet/sim/InstanceSimulator.cpp @@ -0,0 +1,45 @@ +/* + * InstanceSimulator.cpp + * + * Created on: Sep 6, 2026 + * Author: iizuka + */ + +#include "sim/InstanceSimulator.h" + +#include "bc_network_instance/CodablecashNetworkNode.h" + +#include "base/StackRelease.h" + +#include "json_object/JsonObject.h" + + +namespace codablecash { + +InstanceSimulator::InstanceSimulator(const ZoneInstanceConfig* config) { + this->netnode = nullptr; + +} + +InstanceSimulator::~InstanceSimulator() { + shutdown(); +} + +void InstanceSimulator::shutdown() { + if(this->netnode != nullptr){ + this->netnode->shutdown(); + delete this->netnode, this->netnode = nullptr; + } +} + +JsonObject* InstanceSimulator::makeJsonSettingObject() { + JsonObject* obj = new JsonObject(); __STP(obj); + + + + + return __STP_MV(obj); + // FIXME +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim/InstanceSimulator.h b/src_simnet/sim/InstanceSimulator.h new file mode 100644 index 00000000..973e32e2 --- /dev/null +++ b/src_simnet/sim/InstanceSimulator.h @@ -0,0 +1,33 @@ +/* + * InstanceSimulator.h + * + * Created on: Sep 6, 2026 + * Author: iizuka + */ + +#ifndef SIM_INSTANCESIMULATOR_H_ +#define SIM_INSTANCESIMULATOR_H_ + +namespace codablecash { + +class ZoneInstanceConfig; +class CodablecashNetworkNode; +class JsonObject; + +class InstanceSimulator { +public: + explicit InstanceSimulator(const ZoneInstanceConfig* config); + virtual ~InstanceSimulator(); + + void shutdown(); + + JsonObject* makeJsonSettingObject(); + +private: + ZoneInstanceConfig* config; + CodablecashNetworkNode* netnode; +}; + +} /* namespace codablecash */ + +#endif /* SIM_INSTANCESIMULATOR_H_ */ diff --git a/src_simnet/sim/ZoneInstanceConfig.cpp b/src_simnet/sim/ZoneInstanceConfig.cpp new file mode 100644 index 00000000..9c9f287a --- /dev/null +++ b/src_simnet/sim/ZoneInstanceConfig.cpp @@ -0,0 +1,64 @@ +/* + * ZoneInstanceConfig.cpp + * + * Created on: Sep 6, 2026 + * Author: iizuka + */ + +#include "sim/ZoneInstanceConfig.h" + +#include "bc_block_generator/MiningConfig.h" + +#include "base/UnicodeString.h" + +#include "bc_network_instance/FinalizerConfig.h" +#include "bc_network_instance/GenesisBalanceConfig.h" + + +namespace codablecash { + +ZoneInstanceConfig::ZoneInstanceConfig(const ZoneInstanceConfig &inst) { + this->genConfig = inst.genConfig != nullptr ? new GenesisBalanceConfig(*inst.genConfig) : nullptr; + +} + +ZoneInstanceConfig::ZoneInstanceConfig() { + this->genConfig = nullptr; + this->minerConfig = nullptr; + this->fconfig = nullptr; + this->name = nullptr; + this->port = 0; +} + +ZoneInstanceConfig::~ZoneInstanceConfig() { + delete this->genConfig; + delete this->minerConfig; + delete this->fconfig; + delete this->name; +} + +void ZoneInstanceConfig::setGenesisConfig(const GenesisBalanceConfig *genConfig) { + delete this->genConfig; + this->genConfig = new GenesisBalanceConfig(*genConfig); +} + +void ZoneInstanceConfig::setMiningConfig(const MiningConfig *minerConfig) { + delete this->minerConfig; + this->minerConfig = new MiningConfig(*minerConfig); +} + +void ZoneInstanceConfig::setFinalizerConfig(const FinalizerConfig *fconfig) { + delete this->fconfig; + this->fconfig = new FinalizerConfig(*fconfig); +} + +void ZoneInstanceConfig::setName(const UnicodeString *name) { + delete this->name; + this->name = new UnicodeString(*name); +} + +void ZoneInstanceConfig::setPort(int port) { + this->port = port; +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim/ZoneInstanceConfig.h b/src_simnet/sim/ZoneInstanceConfig.h new file mode 100644 index 00000000..aff1af29 --- /dev/null +++ b/src_simnet/sim/ZoneInstanceConfig.h @@ -0,0 +1,44 @@ +/* + * ZoneInstanceConfig.h + * + * Created on: Sep 6, 2026 + * Author: iizuka + */ + +#ifndef SIM_ZONEINSTANCECONFIG_H_ +#define SIM_ZONEINSTANCECONFIG_H_ + +namespace alinous { +class UnicodeString; +} +using namespace alinous; + +namespace codablecash { + +class GenesisBalanceConfig; +class MiningConfig; +class FinalizerConfig; + +class ZoneInstanceConfig { +public: + ZoneInstanceConfig(const ZoneInstanceConfig& inst); + ZoneInstanceConfig(); + virtual ~ZoneInstanceConfig(); + + void setGenesisConfig(const GenesisBalanceConfig* genConfig); + void setMiningConfig(const MiningConfig* minerConfig); + void setFinalizerConfig(const FinalizerConfig* fconfig); + void setName(const UnicodeString* name); + void setPort(int port); + +private: + GenesisBalanceConfig* genConfig; + MiningConfig* minerConfig; + FinalizerConfig* fconfig; + UnicodeString* name; + int port; +}; + +} /* namespace codablecash */ + +#endif /* SIM_ZONEINSTANCECONFIG_H_ */ diff --git a/src_simnet/sim/ZoneSimulator.cpp b/src_simnet/sim/ZoneSimulator.cpp new file mode 100644 index 00000000..1fbc1934 --- /dev/null +++ b/src_simnet/sim/ZoneSimulator.cpp @@ -0,0 +1,67 @@ +/* + * ZoneSimulator.cpp + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#include "sim/ZoneSimulator.h" +#include "sim/InstanceSimulator.h" + +#include "base/StackRelease.h" + +#include "json_object/JsonObject.h" +#include "json_object/JsonArrayObject.h" +#include "json_object/JsonValuePair.h" +#include "json_object/JsonStringValue.h" + + +namespace codablecash { + +ZoneSimulator::ZoneSimulator(uint16_t zone, INetworkSeeder* seeder) { + this->zone = zone; + this->seeder = seeder; + this->list = new ArrayList(); +} + +ZoneSimulator::~ZoneSimulator() { + shutdown(); +} + +void ZoneSimulator::shutdown() { + if(this->list != nullptr){ + int maxLoop = this->list->size(); + for(int i = 0; i != maxLoop; ++i){ + InstanceSimulator* node = this->list->get(i); + node->shutdown(); + } + + this->list->deleteElements(); + + delete this->list, this->list = nullptr; + } +} + +JsonObject* ZoneSimulator::makeJsonSettingObject() { + JsonObject* obj = new JsonObject(); __STP(obj); + + JsonArrayObject* instArray = new JsonArrayObject(); + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"zoneConfigs")); + pair->setValue(instArray); + obj->add(pair); + } + + int maxLoop = this->list->size(); + for(int i = 0; i != maxLoop; ++i){ + InstanceSimulator* node = this->list->get(i); + + JsonObject* jsonObject = node->makeJsonSettingObject(); + instArray->add(jsonObject); + } + + return __STP_MV(obj); +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim/ZoneSimulator.h b/src_simnet/sim/ZoneSimulator.h new file mode 100644 index 00000000..ee4f5624 --- /dev/null +++ b/src_simnet/sim/ZoneSimulator.h @@ -0,0 +1,44 @@ +/* + * ZoneSimulator.h + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#ifndef SIM_ZONESIMULATOR_H_ +#define SIM_ZONESIMULATOR_H_ +#include + +#include "base/ArrayList.h" + +using namespace alinous; + +namespace codablecash { + +class InstanceSimulator; +class INetworkSeeder; +class GenesisBalanceConfig; +class MiningConfig; +class FinalizerConfig; +class JsonObject; + +class ZoneSimulator { +public: + explicit ZoneSimulator(uint16_t zone, INetworkSeeder* seeder); + virtual ~ZoneSimulator(); + + void shutdown(); + + void firstInstance(const GenesisBalanceConfig* gen, const MiningConfig* minerConfig, const FinalizerConfig* fconfig, const UnicodeString* name); + + JsonObject* makeJsonSettingObject(); + +private: + INetworkSeeder* seeder; + uint16_t zone; + ArrayList* list; +}; + +} /* namespace codablecash */ + +#endif /* SIM_ZONESIMULATOR_H_ */ diff --git a/src_simnet/sim_net/CMakeLists.txt b/src_simnet/sim_net/CMakeLists.txt new file mode 100644 index 00000000..c7d482e0 --- /dev/null +++ b/src_simnet/sim_net/CMakeLists.txt @@ -0,0 +1,6 @@ + +set(__src + SimnetMainNet.cpp +) +handle_sub(codablecashlib "${__src}" simnet sim_net) + diff --git a/src_simnet/sim_net/SimnetMainNet.cpp b/src_simnet/sim_net/SimnetMainNet.cpp new file mode 100644 index 00000000..7a3be95c --- /dev/null +++ b/src_simnet/sim_net/SimnetMainNet.cpp @@ -0,0 +1,58 @@ +/* + * SimnetMainNet.cpp + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#include "SimnetMainNet.h" + +#include "bc/ISystemLogger.h" + +#include "bc_p2p_info/P2pNodeRecord.h" + +#include "p2pserver/P2pServer.h" + +#include "base/UnicodeString.h" + +namespace codablecash { + +SimnetMainNet::SimnetMainNet(ISystemLogger *logger) { + this->logger = logger; + this->p2pServer = nullptr; + + this->protocol = P2pNodeRecord::TCP_IP_V6; + this->srvhost = nullptr; + this->port = 18081; +} + +SimnetMainNet::~SimnetMainNet() { + shutdown(); + + delete this->srvhost; + + this->logger = nullptr; +} + +void SimnetMainNet::shutdown() { + if(this->p2pServer != nullptr){ + this->p2pServer->stopListning(); + this->p2pServer->dispose(); + delete this->p2pServer, this->p2pServer = nullptr; + } +} + +void SimnetMainNet::setServerNetInfo(int protocol, const UnicodeString *srvhost, int port) { + this->protocol = protocol; + this->srvhost = new UnicodeString(*srvhost); + this->port = port; +} + +void SimnetMainNet::startNetwork() { + this->p2pServer = new P2pServer(this->logger, this); + + UnicodeString node(L"simnetIf"); + this->p2pServer->startListening(this->protocol, this->srvhost, this->port, &node); +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim_net/SimnetMainNet.h b/src_simnet/sim_net/SimnetMainNet.h new file mode 100644 index 00000000..fc577860 --- /dev/null +++ b/src_simnet/sim_net/SimnetMainNet.h @@ -0,0 +1,45 @@ +/* + * SimnetMainNet.h + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#ifndef SIM_NET_SIMNETMAINNET_H_ +#define SIM_NET_SIMNETMAINNET_H_ + +#include "pubsub/IPubsubCommandExecutor.h" + +namespace alinous { +class UnicodeString; +} +using namespace alinous; + +namespace codablecash { + +class ISystemLogger; +class P2pServer; + +class SimnetMainNet : public IPubsubCommandExecutor { +public: + explicit SimnetMainNet(ISystemLogger *logger); + virtual ~SimnetMainNet(); + + void shutdown(); + + void setServerNetInfo(int protocol, const UnicodeString* srvhost, int port); + void startNetwork(); + + +private: + ISystemLogger *logger; + P2pServer* p2pServer; + + int protocol; + UnicodeString* srvhost; + int port; +}; + +} /* namespace codablecash */ + +#endif /* SIM_NET_SIMNETMAINNET_H_ */ diff --git a/src_simnet/sim_net_client/AbstractSimnetClientCommand.cpp b/src_simnet/sim_net_client/AbstractSimnetClientCommand.cpp new file mode 100644 index 00000000..6e5a87f0 --- /dev/null +++ b/src_simnet/sim_net_client/AbstractSimnetClientCommand.cpp @@ -0,0 +1,24 @@ +/* + * AbstractSimnetClientCommand.cpp + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#include "sim_net_client/AbstractSimnetClientCommand.h" + +namespace codablecash { + +AbstractSimnetClientCommand::AbstractSimnetClientCommand(const AbstractSimnetClientCommand &inst) + : AbstractPubSubCommand(inst) { +} + +AbstractSimnetClientCommand::AbstractSimnetClientCommand(uint32_t type) : AbstractPubSubCommand(type) { + +} + +AbstractSimnetClientCommand::~AbstractSimnetClientCommand() { + +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim_net_client/AbstractSimnetClientCommand.h b/src_simnet/sim_net_client/AbstractSimnetClientCommand.h new file mode 100644 index 00000000..bde36136 --- /dev/null +++ b/src_simnet/sim_net_client/AbstractSimnetClientCommand.h @@ -0,0 +1,24 @@ +/* + * AbstractSimnetClientCommand.h + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#ifndef SIM_NET_CLIENT_ABSTRACTSIMNETCLIENTCOMMAND_H_ +#define SIM_NET_CLIENT_ABSTRACTSIMNETCLIENTCOMMAND_H_ + +#include "pubsub_cmd/AbstractPubSubCommand.h" + +namespace codablecash { + +class AbstractSimnetClientCommand : public AbstractPubSubCommand { +public: + AbstractSimnetClientCommand(const AbstractSimnetClientCommand& inst); + explicit AbstractSimnetClientCommand(uint32_t type); + virtual ~AbstractSimnetClientCommand(); +}; + +} /* namespace codablecash */ + +#endif /* SIM_NET_CLIENT_ABSTRACTSIMNETCLIENTCOMMAND_H_ */ diff --git a/src_simnet/sim_net_client/CMakeLists.txt b/src_simnet/sim_net_client/CMakeLists.txt new file mode 100644 index 00000000..911e035c --- /dev/null +++ b/src_simnet/sim_net_client/CMakeLists.txt @@ -0,0 +1,7 @@ + +set(__src + SimnetClient.cpp + SimnetPubsubCommandExecutor.cpp +) +handle_sub(codablecashlib "${__src}" simnet sim_net_client) + diff --git a/src_simnet/sim_net_client/SimnetClient.cpp b/src_simnet/sim_net_client/SimnetClient.cpp new file mode 100644 index 00000000..888dddb6 --- /dev/null +++ b/src_simnet/sim_net_client/SimnetClient.cpp @@ -0,0 +1,49 @@ +/* + * SimnetClient.cpp + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#include "SimnetClient.h" +#include "sim_net_client/SimnetPubsubCommandExecutor.h" + +#include "bc/ISystemLogger.h" + +#include "pubsub/P2pHandshake.h" +#include "pubsub/PubSubId.h" + +#include "base/StackRelease.h" + + +namespace codablecash { + +SimnetClient::SimnetClient(ISystemLogger* logger) { + this->logger = logger; + this->handshake = nullptr; + this->exec = new SimnetPubsubCommandExecutor(this); +} + +SimnetClient::~SimnetClient() { + shutdown(); + + delete this->exec; +} + +void SimnetClient::shutdown() { + if(this->handshake != nullptr){ + this->handshake->dispose(); + delete this->handshake; + this->handshake = nullptr; + } +} + +void SimnetClient::start(int protocol, const UnicodeString *host, int port) { + PubSubId* psId = PubSubId::createNewId(); __STP(psId); + + // establish handshake + this->handshake = new P2pHandshake(psId, logger); + this->handshake->connect(protocol, host, port, this->exec, true); +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim_net_client/SimnetClient.h b/src_simnet/sim_net_client/SimnetClient.h new file mode 100644 index 00000000..a9b228ac --- /dev/null +++ b/src_simnet/sim_net_client/SimnetClient.h @@ -0,0 +1,42 @@ +/* + * SimnetClient.h + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#ifndef SIM_NET_CLIENT_SIMNETCLIENT_H_ +#define SIM_NET_CLIENT_SIMNETCLIENT_H_ + +#include "pubsub/IPubsubCommandExecutor.h" + +namespace alinous { +class UnicodeString; +} +using namespace alinous; + + +namespace codablecash { + +class ISystemLogger; +class P2pHandshake; +class SimnetPubsubCommandExecutor; + +class SimnetClient : public IPubsubCommandExecutor { +public: + explicit SimnetClient(ISystemLogger* logger); + virtual ~SimnetClient(); + + void start(int protocol, const UnicodeString *host, int port); + void shutdown(); + +private: + ISystemLogger* logger; + + P2pHandshake *handshake; + SimnetPubsubCommandExecutor* exec; +}; + +} /* namespace codablecash */ + +#endif /* SIM_NET_CLIENT_SIMNETCLIENT_H_ */ diff --git a/src_simnet/sim_net_client/SimnetPubsubCommandExecutor.cpp b/src_simnet/sim_net_client/SimnetPubsubCommandExecutor.cpp new file mode 100644 index 00000000..f49bdd1f --- /dev/null +++ b/src_simnet/sim_net_client/SimnetPubsubCommandExecutor.cpp @@ -0,0 +1,42 @@ +/* + * SimnetPubsubCommandExecutor.cpp + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#include "sim_net_client/SimnetPubsubCommandExecutor.h" +#include "sim_net_client/SimnetClient.h" + +#include "base/Exception.h" + +#include "pubsub/PubSubId.h" + +#include "pubsub_cmd/AbstractPubSubCommand.h" + + + +namespace codablecash { + +SimnetPubsubCommandExecutor::SimnetPubsubCommandExecutor(SimnetClient* client) { + this->client = client; +} + +SimnetPubsubCommandExecutor::~SimnetPubsubCommandExecutor() { + +} + +void SimnetPubsubCommandExecutor::fireOnExeptionOnSubscriber(const PubSubId *pubsubId, const Exception *e) { +} + +void SimnetPubsubCommandExecutor::fireExecuteCommand(const PubSubId *pubsubId, const AbstractPubSubCommand *cmd) { +} + +void SimnetPubsubCommandExecutor::fireOnSubscribeEnds(const PubSubId *pubsubId) { +} + +IPubsubCommandExecutor* SimnetPubsubCommandExecutor::getExecutor() const noexcept { + return this->client; +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim_net_client/SimnetPubsubCommandExecutor.h b/src_simnet/sim_net_client/SimnetPubsubCommandExecutor.h new file mode 100644 index 00000000..8bfccd33 --- /dev/null +++ b/src_simnet/sim_net_client/SimnetPubsubCommandExecutor.h @@ -0,0 +1,35 @@ +/* + * SimnetPubsubCommandExecutor.h + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#ifndef SIM_NET_CLIENT_SIMNETPUBSUBCOMMANDEXECUTOR_H_ +#define SIM_NET_CLIENT_SIMNETPUBSUBCOMMANDEXECUTOR_H_ + +#include "pubsub/IPubsubCommandListner.h" + +namespace codablecash { + +class SimnetClient; + +class SimnetPubsubCommandExecutor : public IPubsubCommandListner { +public: + explicit SimnetPubsubCommandExecutor(SimnetClient* client); + virtual ~SimnetPubsubCommandExecutor(); + + virtual void fireOnExeptionOnSubscriber( + const codablecash::PubSubId *pubsubId, const alinous::Exception *e); + virtual void fireExecuteCommand(const codablecash::PubSubId *pubsubId, + const codablecash::AbstractPubSubCommand *cmd); + virtual void fireOnSubscribeEnds(const codablecash::PubSubId *pubsubId); + virtual IPubsubCommandExecutor* getExecutor() const noexcept; + +private: + SimnetClient* client; +}; + +} /* namespace codablecash */ + +#endif /* SIM_NET_CLIENT_SIMNETPUBSUBCOMMANDEXECUTOR_H_ */ diff --git a/src_smartcontract_vm/instance/instance_parts/VMemHashMapKeySet.h b/src_smartcontract_vm/instance/instance_parts/VMemHashMapKeySet.h index 058deba2..12e78dc7 100644 --- a/src_smartcontract_vm/instance/instance_parts/VMemHashMapKeySet.h +++ b/src_smartcontract_vm/instance/instance_parts/VMemHashMapKeySet.h @@ -29,7 +29,7 @@ class VMemHashMapKeySet { this->nullElement = nullptr; } virtual ~VMemHashMapKeySet(){ - typename VMemHashMapRawArray::Iterator it = this->list->iterator(); + typename VMemHashMapRawArray::InternalIterator it = this->list->iterator(); while(it.hasNext()){ VMemHashMapInternalElement* element = it.next(); @@ -219,7 +219,7 @@ class VMemHashMapKeySet { } private: - typename VMemHashMapRawArray::Iterator internalIt; + typename VMemHashMapRawArray::InternalIterator internalIt; bool outputNull; VMemHashMapInternalElement* nullElement; }; diff --git a/src_smartcontract_vm/instance/instance_parts/VMemHashMapRawArray.h b/src_smartcontract_vm/instance/instance_parts/VMemHashMapRawArray.h index 2c5e5b43..b9764c00 100644 --- a/src_smartcontract_vm/instance/instance_parts/VMemHashMapRawArray.h +++ b/src_smartcontract_vm/instance/instance_parts/VMemHashMapRawArray.h @@ -163,13 +163,13 @@ class VMemHashMapRawArray { numElements = 0; } - class Iterator { + class InternalIterator { public: int hashCode; int index; VMemList, typename VMemHashMapInternalElement::ValueCompare>** arrays; const VMemRawBitSet* bitset; - Iterator(VMemList, typename VMemHashMapInternalElement::ValueCompare>** ptr, VMemRawBitSet* bitset) + InternalIterator(VMemList, typename VMemHashMapInternalElement::ValueCompare>** ptr, VMemRawBitSet* bitset) : hashCode(0), index(0), arrays(ptr), bitset(bitset) {} bool hasNext() const { @@ -208,8 +208,8 @@ class VMemHashMapRawArray { } }; - Iterator iterator() { - return Iterator(arrays, &bitset); + InternalIterator iterator() { + return InternalIterator(arrays, &bitset); } private: diff --git a/src_test/CMakeLists.txt b/src_test/CMakeLists.txt index 46bbe1af..570abbe5 100644 --- a/src_test/CMakeLists.txt +++ b/src_test/CMakeLists.txt @@ -38,6 +38,7 @@ add_subdirectory(p2p/p2pserver) add_subdirectory(p2p/parts) add_subdirectory(p2p/p2pserver/dummy) add_subdirectory(p2p/socket) +add_subdirectory(simnet) add_subdirectory(smartcontract) add_subdirectory(smartcontract_db/cache) add_subdirectory(smartcontract_db/engine) diff --git a/src_test/blockchain/wallet/test_client_command_queue.cpp b/src_test/blockchain/wallet/test_client_command_queue.cpp index b59b2205..934b9bae 100644 --- a/src_test/blockchain/wallet/test_client_command_queue.cpp +++ b/src_test/blockchain/wallet/test_client_command_queue.cpp @@ -53,31 +53,67 @@ TEST(TestClientCommandQueueGroup, case01) { DebugCodablecashSystemParamSetup::setupConfig02(param); WalletConfig walletConfig; - NetworkWallet* wallet = NetworkWallet::createNewWallet(baseDir, &pass, 0, 10, logger, ¶m, &walletConfig); __STP(wallet); + { + NetworkWallet* wallet = NetworkWallet::createNewWallet(baseDir, &pass, 0, 10, logger, ¶m, &walletConfig); __STP(wallet); - NetworkClientCommandProcessor* processor = wallet->getNetworkClientCommandProcessor(); + NetworkClientCommandProcessor* processor = wallet->getNetworkClientCommandProcessor(); - processor->startProcessors(false); + processor->startProcessors(false); - int maxLoop = 1; - for(int i = 0; i != maxLoop; ++i) { - ClientNewTransactionCommand cmd; - TransactionTransferData data; + int maxLoop = 1; + for(int i = 0; i != maxLoop; ++i) { + ClientNewTransactionCommand cmd; + TransactionTransferData data; - BalanceUnit amount(1L); - Coinbase coinbase; - coinbase.setAmount(&amount); + BalanceUnit amount(1L); + Coinbase coinbase; + coinbase.setAmount(&amount); - CoinbaseTransaction trx; - trx.setCoinbase(&coinbase); - trx.setHeight(1); + CoinbaseTransaction trx; + trx.setCoinbase(&coinbase); + trx.setHeight(1); - trx.build(); + trx.build(); - data.setTransaction(&trx); - cmd.setData(&data); + data.setTransaction(&trx); + cmd.setData(&data); - processor->addClientCommand(&cmd); + processor->addClientCommand(&cmd); + } + + wallet->shutdownNetwork(); + wallet->closeData(); + } + { + NetworkWallet* wallet = NetworkWallet::openWallet(baseDir, &pass, logger, ¶m, &walletConfig); __STP(wallet); + + NetworkClientCommandProcessor* processor = wallet->getNetworkClientCommandProcessor(); + + processor->startProcessors(false); + + int maxLoop = 1; + for(int i = 0; i != maxLoop; ++i) { + ClientNewTransactionCommand cmd; + TransactionTransferData data; + + BalanceUnit amount(1L); + Coinbase coinbase; + coinbase.setAmount(&amount); + + CoinbaseTransaction trx; + trx.setCoinbase(&coinbase); + trx.setHeight(1); + + trx.build(); + + data.setTransaction(&trx); + cmd.setData(&data); + + processor->addClientCommand(&cmd); + } + + wallet->shutdownNetwork(); + wallet->closeData(); } } diff --git a/src_test/simnet/CMakeLists.txt b/src_test/simnet/CMakeLists.txt new file mode 100644 index 00000000..74a1e322 --- /dev/null +++ b/src_test/simnet/CMakeLists.txt @@ -0,0 +1,10 @@ + +set(testsrc + test_sim_config.cpp + test_simnet_client.cpp +) +handle_sub(testall "${testsrc}" test simnet) + + + + diff --git a/src_test/simnet/test_sim_config.cpp b/src_test/simnet/test_sim_config.cpp new file mode 100644 index 00000000..0731caab --- /dev/null +++ b/src_test/simnet/test_sim_config.cpp @@ -0,0 +1,27 @@ +/* + * test_sim_config.cpp + * + * Created on: Sep 6, 2026 + * Author: iizuka + */ +#include "test_utils/t_macros.h" + +#include "json/JsonHandler.h" + +using namespace codablecash; + +// JsonHandler + +TEST_GROUP(TestSimConfigGroup) { + TEST_SETUP(){this->env->setup();} + TEST_TEARDOWN(){this->env->teardown();} +}; + +TEST(TestSimConfigGroup, case01){ + File projectFolder = this->env->testCaseDir(); + + //JsonHandler + // JsonArrayObject + + +} diff --git a/src_test/simnet/test_simnet_client.cpp b/src_test/simnet/test_simnet_client.cpp new file mode 100644 index 00000000..fa9e38da --- /dev/null +++ b/src_test/simnet/test_simnet_client.cpp @@ -0,0 +1,47 @@ +/* + * test_simnet_client.cpp + * + * Created on: Sep 3, 2026 + * Author: iizuka + */ + +#include "test_utils/t_macros.h" + +#include "../test_utils/TestPortSelection.h" + +#include "sim_net/SimnetMainNet.h" + +#include "sim_net_client/SimnetClient.h" + +#include "bc/DebugDefaultLogger.h" + +#include "bc_p2p_info/P2pNodeRecord.h" + + +using namespace codablecash; + +TEST_GROUP(TestSimnetClientGroup) { + TEST_SETUP(){this->env->setup();} + TEST_TEARDOWN(){this->env->teardown();} +}; + +TEST(TestSimnetClientGroup, case01){ + StackTestPortGetter portSel; + int port = portSel.allocPort(); + + DebugDefaultLogger logger; + logger.addSection(ISystemLogger::DEBUG_POOL_TRANSFER_RESPONSE); + + SimnetMainNet* net = new SimnetMainNet(&logger); __STP(net); + + UnicodeString srvhost(L"127.0.0.1"); + net->setServerNetInfo(P2pNodeRecord::TCP_IP_V4, &srvhost, port); + net->startNetwork(); + + { + SimnetClient client(&logger); + UnicodeString host(L"127.0.0.1"); + client.start(P2pNodeRecord::TCP_IP_V4, &host, port); + } + +} From 967b7eb4fc41c568a2c2b05cc63018b51e0d3fa5 Mon Sep 17 00:00:00 2001 From: iizuka Date: Tue, 8 Sep 2026 16:51:27 +0800 Subject: [PATCH 3/3] json config files --- .../bc_block_generator/MiningConfig.cpp | 132 +++++++++++++++- .../bc_block_generator/MiningConfig.h | 4 + .../bc_network/NodeIdentifierSource.cpp | 74 ++++++++- .../bc_network/NodeIdentifierSource.h | 4 + .../bc_network_instance/FinalizerConfig.cpp | 38 +++++ .../bc_network_instance/FinalizerConfig.h | 4 + .../GenesisBalanceConfig.cpp | 118 +++++++++++++++ .../GenesisBalanceConfig.h | 8 + src_db/json/JsonHandler.cpp | 7 + src_db/json/JsonHandler.h | 3 + src_db/json_object/JsonArrayObject.cpp | 2 +- src_db/json_object/JsonNumericValue.h | 6 +- src_db/json_object/JsonObject.cpp | 6 +- src_db/json_object/JsonStringValue.cpp | 10 +- src_db/json_object/JsonStringValue.h | 1 + src_simnet/sim/CMakeLists.txt | 1 + src_simnet/sim/InstanceSimulator.cpp | 10 +- src_simnet/sim/SimnetConfigException.cpp | 33 ++++ src_simnet/sim/SimnetConfigException.h | 29 ++++ src_simnet/sim/ZoneInstanceConfig.cpp | 142 +++++++++++++++++- src_simnet/sim/ZoneInstanceConfig.h | 10 +- src_simnet/sim/ZoneSimulator.cpp | 9 +- src_test/simnet/test_sim_config.cpp | 92 ++++++++++++ 23 files changed, 724 insertions(+), 19 deletions(-) create mode 100644 src_simnet/sim/SimnetConfigException.cpp create mode 100644 src_simnet/sim/SimnetConfigException.h diff --git a/src_blockchain/bc_block_generator/MiningConfig.cpp b/src_blockchain/bc_block_generator/MiningConfig.cpp index bb506c4d..7c59158a 100644 --- a/src_blockchain/bc_block_generator/MiningConfig.cpp +++ b/src_blockchain/bc_block_generator/MiningConfig.cpp @@ -13,13 +13,21 @@ #include "pow_pool/NetworkPoWPool.h" -#include "base/UnicodeString.h" - #include "ipconnect/IServerSocket.h" #include "bc_p2p_info/P2pNodeRecord.h" +#include "base/StackRelease.h" +#include "base/UnicodeString.h" + +#include "json_object/JsonObject.h" +#include "json_object/JsonValuePair.h" +#include "json_object/JsonStringValue.h" +#include "json_object/JsonNumericValue.h" + +#include "sim/SimnetConfigException.h" +#include "bc/ExceptionThrower.h" namespace codablecash { MiningConfig::MiningConfig(const MiningConfig &inst) { @@ -85,4 +93,124 @@ void MiningConfig::initNetworkPool(NetworkPoWPool *pool) const { } +JsonObject* MiningConfig::toJsonObject() const { + JsonObject* configObj = new JsonObject(); __STP(configObj); + + // reward address + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"address")); + + const char* cstr = this->addressDesc->toCString(); + StackArrayRelease __cstr(cstr); + + UnicodeString str(cstr); + pair->setValue(new JsonStringValue(&str)); + + configObj->add(pair); + } + // calc Type + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"type")); + + UnicodeString* typeStr = this->calcType == TYPE_POOL ? new UnicodeString(L"pool") : new UnicodeString("debug"); + __STP(typeStr); + + pair->setValue(new JsonStringValue(typeStr)); + + configObj->add(pair); + } + + // protocol + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"protocol")); + + JsonStringValue* v = this->protocol == P2pNodeRecord::TCP_IP_V4 ? new JsonStringValue(L"ipv4") : new JsonStringValue(L"ipv6"); + pair->setValue(v); + configObj->add(pair); + } + // host + if(this->srvhost != nullptr){ + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"host")); + + pair->setValue(new JsonStringValue(this->srvhost)); + configObj->add(pair); + } + // port + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"port")); + pair->setValue(new JsonNumericValue(this->port)); + configObj->add(pair); + } + + return __STP_MV(configObj); +} + +MiningConfig* MiningConfig::fromJson(const JsonObject *configObj) { + MiningConfig* config = new MiningConfig(); __STP(config); + + const JsonValuePair* pair = configObj->get(L"address"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonStringValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"address of the Mining Config must be string type.", __FILE__, __LINE__); + + AddressDescriptor desc(value->getValue()); + config->setAddressDescriptor(&desc); + } + + pair = configObj->get(L"type"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonStringValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"type of the Mining Config must be string type.", __FILE__, __LINE__); + + const UnicodeString* str = value->getValue(); + if(str->equals(L"pool")){ + config->setCalclatorType(TYPE_POOL); + }else{ + config->setCalclatorType(TYPE_DEBUG); + } + } + + pair = configObj->get(L"protocol"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonStringValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"protocol of the Mining Config must be string type.", __FILE__, __LINE__); + + const UnicodeString* str = value->getValue(); + if(str->equals(L"ipv4")){ + config->setProtocol(P2pNodeRecord::TCP_IP_V4); + }else{ + config->setProtocol(P2pNodeRecord::TCP_IP_V6); + } + } + + pair = configObj->get(L"host"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonStringValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"host of the Mining Config must be string type.", __FILE__, __LINE__); + + const UnicodeString* str = value->getValue(); + config->setServerHost(str); + } + + pair = configObj->get(L"port"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonNumericValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"port of the Mining Config must be numeric type.", __FILE__, __LINE__); + + config->setPort(value->getValue()); + } + + return __STP_MV(config); +} + } /* namespace codablecash */ diff --git a/src_blockchain/bc_block_generator/MiningConfig.h b/src_blockchain/bc_block_generator/MiningConfig.h index 0bcabb69..9c8103e0 100644 --- a/src_blockchain/bc_block_generator/MiningConfig.h +++ b/src_blockchain/bc_block_generator/MiningConfig.h @@ -20,6 +20,7 @@ class AddressDescriptor; class AbstractPoWCalculator; class NetworkPoWPool; class PoWManager; +class JsonObject; class MiningConfig { public: @@ -43,6 +44,9 @@ class MiningConfig { AbstractPoWCalculator* getPoWCalculator(PoWManager* powManager) const noexcept; + JsonObject* toJsonObject() const; + static MiningConfig* fromJson(const JsonObject* configObj); + private: void initNetworkPool(NetworkPoWPool* pool) const; diff --git a/src_blockchain/bc_network/NodeIdentifierSource.cpp b/src_blockchain/bc_network/NodeIdentifierSource.cpp index 8c6dd32c..7131851d 100644 --- a/src_blockchain/bc_network/NodeIdentifierSource.cpp +++ b/src_blockchain/bc_network/NodeIdentifierSource.cpp @@ -6,11 +6,25 @@ */ #include "bc_network/NodeIdentifierSource.h" +#include "bc_network/NodeIdentifier.h" #include "crypto/Schnorr.h" -#include "bc_network/NodeIdentifier.h" #include "base_io/ByteBuffer.h" + +#include "base/StackRelease.h" + +#include "json_object/JsonObject.h" + +#include "json_object/JsonValuePair.h" + +#include "json_object/JsonStringValue.h" + +#include "bc/ExceptionThrower.h" + +#include "sim/SimnetConfigException.h" + +#include "crypto/SchnorrKeyPair.h" namespace codablecash { NodeIdentifierSource::NodeIdentifierSource(IKeyPair* pair) { @@ -58,4 +72,62 @@ const BigInteger* NodeIdentifierSource::getSecretKey() const noexcept { return this->pair->getSecretKey(); } +JsonObject* NodeIdentifierSource::toJsonObject() const { + JsonObject* configObj = new JsonObject(); __STP(configObj); + + // pubkey + { + const BigInteger* pub = this->pair->getPubKey(); + + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"pubkey")); + + UnicodeString str = pub->toString(16); + pair->setValue(new JsonStringValue(&str)); + + configObj->add(pair); + } + // secretkey + { + const BigInteger* sec = this->pair->getSecretKey(); + + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"secretkey")); + + UnicodeString str = sec->toString(16); + pair->setValue(new JsonStringValue(&str)); + + configObj->add(pair); + } + + return __STP_MV(configObj); +} + +NodeIdentifierSource* NodeIdentifierSource::fromJson(const JsonObject *configObj) { + NodeIdentifierSource* ret = nullptr; + + const JsonValuePair* pubPair = configObj->get(L"pubkey"); + const JsonValuePair* secPair = configObj->get(L"secretkey"); + + ExceptionThrower::throwExceptionIfCondition(pubPair == nullptr || secPair == nullptr, L"secretkey and publickey is essential.", __FILE__, __LINE__); + + if(pubPair != nullptr && secPair != nullptr){ + AbstractJsonObject* pv = pubPair->getValue(); + JsonStringValue* pvalue = dynamic_cast(pv); + ExceptionThrower::throwExceptionIfCondition(pvalue == nullptr, L"pubkey of the voter must be string type.", __FILE__, __LINE__); + + AbstractJsonObject* sv = secPair->getValue(); + JsonStringValue* svalue = dynamic_cast(sv); + ExceptionThrower::throwExceptionIfCondition(svalue == nullptr, L"secretkey of the voter must be string type.", __FILE__, __LINE__); + + BigInteger p(pvalue->getValue(), 16); + BigInteger s(svalue->getValue(), 16); + + SchnorrKeyPair* sch = new SchnorrKeyPair(s, p); + ret = new NodeIdentifierSource(sch); + } + + return ret; +} + } /* namespace codablecash */ diff --git a/src_blockchain/bc_network/NodeIdentifierSource.h b/src_blockchain/bc_network/NodeIdentifierSource.h index f1af584e..864adac6 100644 --- a/src_blockchain/bc_network/NodeIdentifierSource.h +++ b/src_blockchain/bc_network/NodeIdentifierSource.h @@ -20,6 +20,7 @@ namespace codablecash { class IKeyPair; class NodeIdentifier; +class JsonObject; class NodeIdentifierSource : public IBlockObject { public: @@ -38,6 +39,9 @@ class NodeIdentifierSource : public IBlockObject { const BigInteger* getSecretKey() const noexcept; + JsonObject* toJsonObject() const; + static NodeIdentifierSource* fromJson(const JsonObject* configObj); + private: IKeyPair* pair; }; diff --git a/src_blockchain/bc_network_instance/FinalizerConfig.cpp b/src_blockchain/bc_network_instance/FinalizerConfig.cpp index 96e2ef4d..646f60bd 100644 --- a/src_blockchain/bc_network_instance/FinalizerConfig.cpp +++ b/src_blockchain/bc_network_instance/FinalizerConfig.cpp @@ -9,6 +9,15 @@ #include "bc_network/NodeIdentifierSource.h" +#include "base/StackRelease.h" + +#include "json_object/JsonObject.h" +#include "json_object/JsonStringValue.h" +#include "json_object/JsonValuePair.h" + +#include "bc/ExceptionThrower.h" + +#include "sim/SimnetConfigException.h" namespace codablecash { FinalizerConfig::FinalizerConfig(const FinalizerConfig &inst) { @@ -28,4 +37,33 @@ void FinalizerConfig::setVoterSource(const NodeIdentifierSource *source) noexcep this->voterSource = dynamic_cast(source->copyData()); } +JsonObject* FinalizerConfig::toJsonObject() const { + JsonObject* configObj = new JsonObject(); __STP(configObj); + if(this->voterSource != nullptr){ + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"voter")); + pair->setValue(this->voterSource->toJsonObject()); + + configObj->add(pair); + } + + return __STP_MV(configObj); +} + +FinalizerConfig* FinalizerConfig::fromJson(const JsonObject *configObj) { + FinalizerConfig* config = new FinalizerConfig(); __STP(config); + + const JsonValuePair* pair = configObj->get(L"voter"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonObject* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"voter of the Finalizer Config must be object type.", __FILE__, __LINE__); + + NodeIdentifierSource* source = NodeIdentifierSource::fromJson(value); __STP(source); + config->setVoterSource(source); + } + + return __STP_MV(config); +} + } /* namespace codablecash */ diff --git a/src_blockchain/bc_network_instance/FinalizerConfig.h b/src_blockchain/bc_network_instance/FinalizerConfig.h index 720bddfa..25736d9c 100644 --- a/src_blockchain/bc_network_instance/FinalizerConfig.h +++ b/src_blockchain/bc_network_instance/FinalizerConfig.h @@ -11,6 +11,7 @@ namespace codablecash { class NodeIdentifierSource; +class JsonObject; class FinalizerConfig { public: @@ -23,6 +24,9 @@ class FinalizerConfig { return this->voterSource; } + JsonObject* toJsonObject() const; + static FinalizerConfig* fromJson(const JsonObject* configObj); + private: NodeIdentifierSource* voterSource; }; diff --git a/src_blockchain/bc_network_instance/GenesisBalanceConfig.cpp b/src_blockchain/bc_network_instance/GenesisBalanceConfig.cpp index af13d3c0..4df32bfb 100644 --- a/src_blockchain/bc_network_instance/GenesisBalanceConfig.cpp +++ b/src_blockchain/bc_network_instance/GenesisBalanceConfig.cpp @@ -9,6 +9,20 @@ #include "bc_base/AddressDescriptor.h" +#include "json_object/JsonObject.h" +#include "json_object/JsonValuePair.h" +#include "json_object/JsonStringValue.h" +#include "json_object/JsonArrayObject.h" +#include "json_object/JsonNumericValue.h" + +#include "base/StackRelease.h" +#include "base/UnicodeString.h" + +#include "bc/ExceptionThrower.h" + +#include "sim/SimnetConfigException.h" + +#include "bc_base/BalanceUnit.h" namespace codablecash { GenesisBalance::GenesisBalance(const GenesisBalance &inst) : amount(inst.amount) { @@ -30,6 +44,63 @@ void GenesisBalance::init(const BalanceUnit amount, const AddressDescriptor *des this->addressDesc = new AddressDescriptor(*desc); } +JsonObject* GenesisBalance::toJsonObject() const { + JsonObject* configObj = new JsonObject(); __STP(configObj); + + // address + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"address")); + + const char* cstr = this->addressDesc->toCString(); + StackArrayRelease __cstr(cstr); + + UnicodeString str(cstr); + pair->setValue(new JsonStringValue(&str)); + + configObj->add(pair); + } + // balance + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"balance")); + + uint64_t amout = this->amount.getAmount(); + pair->setValue(new JsonNumericValue(amout)); + + configObj->add(pair); + } + + return __STP_MV(configObj); +} + +GenesisBalance* GenesisBalance::fromJson(const JsonObject *balanceObj) { + GenesisBalance* balance = new GenesisBalance(); __STP(balance); + + const JsonValuePair* apair = balanceObj->get(L"address"); + const JsonValuePair* bpair = balanceObj->get(L"balance"); + if(apair != nullptr && bpair != nullptr){ + AbstractJsonObject* av = apair->getValue(); + JsonStringValue* avalue = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(avalue == nullptr, L"address of the balance must be string type.", __FILE__, __LINE__); + + AbstractJsonObject* bv = bpair->getValue(); + JsonNumericValue* bvalue = dynamic_cast(bv); + ExceptionThrower::throwExceptionIfCondition(bvalue == nullptr, L"amount of the balance must be numeric type.", __FILE__, __LINE__); + + // address desc + const UnicodeString* str = avalue->getValue(); + AddressDescriptor* desc = new AddressDescriptor(str); __STP(desc); + + // amount + BalanceUnit amount((uint64_t)bvalue->getValue()); + + balance->init(amount, desc); + } + + return __STP_MV(balance); +} + GenesisBalanceConfig::GenesisBalanceConfig(const GenesisBalanceConfig &inst) { this->list = new ArrayList(); @@ -57,4 +128,51 @@ void GenesisBalanceConfig::addBalance(const BalanceUnit amount, const AddressDes this->list->addElement(bl); } +void GenesisBalanceConfig::addBalance(const GenesisBalance *balance) { + this->list->addElement(new GenesisBalance(*balance)); +} + +JsonObject* GenesisBalanceConfig::toJsonObject() const { + JsonObject* configObj = new JsonObject(); __STP(configObj); + + JsonArrayObject* balances = new JsonArrayObject(); + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"balances")); + pair->setValue(balances); + configObj->add(pair); + } + + int maxLoop = this->list->size(); + for(int i = 0; i != maxLoop; ++i){ + GenesisBalance* balance = this->list->get(i); + + balances->add(balance->toJsonObject()); + } + + return __STP_MV(configObj); +} + + + +GenesisBalanceConfig* GenesisBalanceConfig::fromJson(const JsonObject* configObj) { + GenesisBalanceConfig* config = new GenesisBalanceConfig(); __STP(config); + + const JsonValuePair* pair = configObj->get(L"balances"); + AbstractJsonObject* __av = pair->getValue(); + JsonArrayObject* value = dynamic_cast(__av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"balances of the Genesis Balance Config must be array type.", __FILE__, __LINE__); + + int maxLoop = value->size(); + for(int i = 0; i != maxLoop; ++i){ + AbstractJsonObject* av = value->get(i); + JsonObject* balanceObj = dynamic_cast(av); + + GenesisBalance* balance = GenesisBalance::fromJson(balanceObj); __STP(balance); + config->addBalance(balance); + } + + return __STP_MV(config); +} + } /* namespace codablecash */ diff --git a/src_blockchain/bc_network_instance/GenesisBalanceConfig.h b/src_blockchain/bc_network_instance/GenesisBalanceConfig.h index 833133a8..0a3b0fd2 100644 --- a/src_blockchain/bc_network_instance/GenesisBalanceConfig.h +++ b/src_blockchain/bc_network_instance/GenesisBalanceConfig.h @@ -15,6 +15,7 @@ namespace codablecash { class AddressDescriptor; +class JsonObject; class GenesisBalance { public: @@ -31,6 +32,9 @@ class GenesisBalance { return this->addressDesc; } + JsonObject* toJsonObject() const; + static GenesisBalance* fromJson(const JsonObject* balanceObj); + private: BalanceUnit amount; AddressDescriptor* addressDesc; @@ -43,11 +47,15 @@ class GenesisBalanceConfig { virtual ~GenesisBalanceConfig(); void addBalance(const BalanceUnit amount, const AddressDescriptor* desc) noexcept; + void addBalance(const GenesisBalance* balance); const ArrayList* getList() const noexcept { return this->list; } + JsonObject* toJsonObject() const; + static GenesisBalanceConfig* fromJson(const JsonObject* configObj); + private: ArrayList* list; }; diff --git a/src_db/json/JsonHandler.cpp b/src_db/json/JsonHandler.cpp index 7b2784d8..55483b50 100644 --- a/src_db/json/JsonHandler.cpp +++ b/src_db/json/JsonHandler.cpp @@ -50,6 +50,12 @@ void JsonHandler::loadFile(const File* file, int buffSize) { this->tokenizer = new JsonTokenizer(jsonStringStream); } +void JsonHandler::loadString(const UnicodeString *str) { + // create tokenizer + JsonStringStream* jsonStringStream = new JsonStringStream(str); + this->tokenizer = new JsonTokenizer(jsonStringStream); +} + AbstractJsonObject* JsonHandler::parse() { JsonParser parser(this->tokenizer); @@ -57,4 +63,5 @@ AbstractJsonObject* JsonHandler::parse() { return object; } + } /* namespace codablecash */ diff --git a/src_db/json/JsonHandler.h b/src_db/json/JsonHandler.h index 48931129..2719ea62 100644 --- a/src_db/json/JsonHandler.h +++ b/src_db/json/JsonHandler.h @@ -10,6 +10,7 @@ namespace alinous { class File; +class UnicodeString; } using namespace alinous; @@ -25,6 +26,8 @@ class JsonHandler { virtual ~JsonHandler(); void loadFile(const File* file, int buffSize); + void loadString(const UnicodeString* str); + AbstractJsonObject* parse(); JsonTokenizer* getTokenizer() const noexcept { diff --git a/src_db/json_object/JsonArrayObject.cpp b/src_db/json_object/JsonArrayObject.cpp index 52af7bb8..4b01da44 100644 --- a/src_db/json_object/JsonArrayObject.cpp +++ b/src_db/json_object/JsonArrayObject.cpp @@ -118,7 +118,7 @@ UnicodeString* JsonArrayObject::toString() const { AbstractJsonObject* obj = this->list->get(i); if(i != 0){ - str->append(L", "); + str->append(L","); } UnicodeString* inner = obj->toString(); __STP(inner); diff --git a/src_db/json_object/JsonNumericValue.h b/src_db/json_object/JsonNumericValue.h index b0d546e8..cae9c215 100644 --- a/src_db/json_object/JsonNumericValue.h +++ b/src_db/json_object/JsonNumericValue.h @@ -23,10 +23,10 @@ class JsonNumericValue : public AbstractJsonValue { return JSON_TYPE_NUMERIC_VALUE; } - void setValue(int v) { + void setValue(int64_t v) { this->value = v; } - int getValue() const noexcept { + int64_t getValue() const noexcept { return this->value; } @@ -42,7 +42,7 @@ class JsonNumericValue : public AbstractJsonValue { virtual UnicodeString* toString() const; private: - int value; + int64_t value; }; } /* namespace codablecash */ diff --git a/src_db/json_object/JsonObject.cpp b/src_db/json_object/JsonObject.cpp index f237639f..b6d0da64 100644 --- a/src_db/json_object/JsonObject.cpp +++ b/src_db/json_object/JsonObject.cpp @@ -145,21 +145,21 @@ void JsonObject::fromBinary(ByteBuffer *in) { } UnicodeString* JsonObject::toString() const { - UnicodeString* str = new UnicodeString(L"{"); + UnicodeString* str = new UnicodeString(L"{\n"); int maxLoop = this->list->size(); for(int i = 0; i != maxLoop; ++i){ AbstractJsonObject* obj = this->list->get(i); if(i != 0){ - str->append(L", "); + str->append(L",\n"); } UnicodeString* inner = obj->toString(); __STP(inner); str->append(inner); } - str->append(L"}"); + str->append(L"}\n"); return str; } diff --git a/src_db/json_object/JsonStringValue.cpp b/src_db/json_object/JsonStringValue.cpp index a941e376..bf9271c5 100644 --- a/src_db/json_object/JsonStringValue.cpp +++ b/src_db/json_object/JsonStringValue.cpp @@ -25,6 +25,10 @@ JsonStringValue::JsonStringValue() { this->value = nullptr; } +JsonStringValue::JsonStringValue(const UnicodeString *str) { + this->value = new UnicodeString(str); +} + JsonStringValue::JsonStringValue(const wchar_t *str) { this->value = new UnicodeString(str); } @@ -79,7 +83,11 @@ AbstractFunctionExtArguments* JsonStringValue::toFunctionExtArgument() const { } UnicodeString* JsonStringValue::toString() const { - return new UnicodeString(this->value); + UnicodeString* ret = new UnicodeString(L"\""); + ret->append(this->value); + ret->append(L"\""); + + return ret; } } /* namespace codablecash */ diff --git a/src_db/json_object/JsonStringValue.h b/src_db/json_object/JsonStringValue.h index e506d62a..efa8b147 100644 --- a/src_db/json_object/JsonStringValue.h +++ b/src_db/json_object/JsonStringValue.h @@ -22,6 +22,7 @@ class JsonStringValue : public AbstractJsonValue { public: JsonStringValue(const JsonStringValue& inst); JsonStringValue(); + explicit JsonStringValue(const UnicodeString* str); explicit JsonStringValue(const wchar_t* str); virtual ~JsonStringValue(); diff --git a/src_simnet/sim/CMakeLists.txt b/src_simnet/sim/CMakeLists.txt index c9740766..13de55d8 100644 --- a/src_simnet/sim/CMakeLists.txt +++ b/src_simnet/sim/CMakeLists.txt @@ -2,6 +2,7 @@ set(__src CodableSimNet.cpp InstanceSimulator.cpp + SimnetConfigException.cpp ZoneInstanceConfig.cpp ZoneSimulator.cpp ) diff --git a/src_simnet/sim/InstanceSimulator.cpp b/src_simnet/sim/InstanceSimulator.cpp index 7a674944..f5969ea2 100644 --- a/src_simnet/sim/InstanceSimulator.cpp +++ b/src_simnet/sim/InstanceSimulator.cpp @@ -6,6 +6,7 @@ */ #include "sim/InstanceSimulator.h" +#include "sim/ZoneInstanceConfig.h" #include "bc_network_instance/CodablecashNetworkNode.h" @@ -13,12 +14,14 @@ #include "json_object/JsonObject.h" +#include "json_object/JsonValuePair.h" +#include "json_object/JsonStringValue.h" namespace codablecash { InstanceSimulator::InstanceSimulator(const ZoneInstanceConfig* config) { this->netnode = nullptr; - + this->config = new ZoneInstanceConfig(*config); } InstanceSimulator::~InstanceSimulator() { @@ -35,7 +38,10 @@ void InstanceSimulator::shutdown() { JsonObject* InstanceSimulator::makeJsonSettingObject() { JsonObject* obj = new JsonObject(); __STP(obj); - + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"")); + } return __STP_MV(obj); diff --git a/src_simnet/sim/SimnetConfigException.cpp b/src_simnet/sim/SimnetConfigException.cpp new file mode 100644 index 00000000..8e89e367 --- /dev/null +++ b/src_simnet/sim/SimnetConfigException.cpp @@ -0,0 +1,33 @@ +/* + * SimnetConfigException.cpp + * + * Created on: Sep 7, 2026 + * Author: iizuka + */ + +#include "sim/SimnetConfigException.h" + +#include "base/UnicodeString.h" + +namespace codablecash { + +const wchar_t* SimnetConfigException::defaultMessage = L"Simulartor config error. "; + +SimnetConfigException::SimnetConfigException(const char* srcfile, int srcline) noexcept : Exception(srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); +} +SimnetConfigException::SimnetConfigException(Exception* cause, const char* srcfile, int srcline) noexcept : Exception(cause, srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); +} +SimnetConfigException::SimnetConfigException(const wchar_t* message, const char* srcfile, int srcline) noexcept : Exception(message, srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); + this->message->append(message); +} +SimnetConfigException::SimnetConfigException(const wchar_t* message, Exception* cause, const char* srcfile, int srcline) noexcept : Exception(message, cause, srcfile, srcline) { + this->message = new UnicodeString(defaultMessage); + this->message->append(message); +} +SimnetConfigException::~SimnetConfigException() { +} + +} /* namespace codablecash */ diff --git a/src_simnet/sim/SimnetConfigException.h b/src_simnet/sim/SimnetConfigException.h new file mode 100644 index 00000000..d7d5bca0 --- /dev/null +++ b/src_simnet/sim/SimnetConfigException.h @@ -0,0 +1,29 @@ +/* + * SimnetConfigException.h + * + * Created on: Sep 7, 2026 + * Author: iizuka + */ + +#ifndef SIM_SIMNETCONFIGEXCEPTION_H_ +#define SIM_SIMNETCONFIGEXCEPTION_H_ + +#include "base/Exception.h" + +using namespace alinous; + +namespace codablecash { + +class SimnetConfigException : public Exception { +public: + SimnetConfigException(const char* srcfile, int srcline) noexcept; + SimnetConfigException(Exception* cause, const char* srcfile, int srcline) noexcept; + SimnetConfigException(const wchar_t* message, const char* srcfile, int srcline) noexcept; + SimnetConfigException(const wchar_t* message, Exception* cause, const char* srcfile, int srcline) noexcept; + virtual ~SimnetConfigException(); + static const wchar_t* defaultMessage; +}; + +} /* namespace codablecash */ + +#endif /* SIM_SIMNETCONFIGEXCEPTION_H_ */ diff --git a/src_simnet/sim/ZoneInstanceConfig.cpp b/src_simnet/sim/ZoneInstanceConfig.cpp index 9c9f287a..9fee7ee7 100644 --- a/src_simnet/sim/ZoneInstanceConfig.cpp +++ b/src_simnet/sim/ZoneInstanceConfig.cpp @@ -6,20 +6,35 @@ */ #include "sim/ZoneInstanceConfig.h" +#include "sim/SimnetConfigException.h" #include "bc_block_generator/MiningConfig.h" -#include "base/UnicodeString.h" - #include "bc_network_instance/FinalizerConfig.h" #include "bc_network_instance/GenesisBalanceConfig.h" +#include "base/StackRelease.h" +#include "base/UnicodeString.h" + +#include "bc_p2p_info/P2pNodeRecord.h" + +#include "json_object/JsonObject.h" +#include "json_object/JsonValuePair.h" +#include "json_object/JsonStringValue.h" +#include "json_object/JsonNumericValue.h" + +#include "bc/ExceptionThrower.h" + namespace codablecash { ZoneInstanceConfig::ZoneInstanceConfig(const ZoneInstanceConfig &inst) { this->genConfig = inst.genConfig != nullptr ? new GenesisBalanceConfig(*inst.genConfig) : nullptr; - + this->minerConfig = inst.minerConfig != nullptr ? new MiningConfig(*inst.minerConfig) : nullptr; + this->fconfig = inst.fconfig != nullptr ? new FinalizerConfig(*inst.fconfig) : nullptr; + this->name = inst.name != nullptr ? new UnicodeString(inst.name) : nullptr; + this->protocol = inst.protocol; + this->port = inst.port; } ZoneInstanceConfig::ZoneInstanceConfig() { @@ -27,6 +42,7 @@ ZoneInstanceConfig::ZoneInstanceConfig() { this->minerConfig = nullptr; this->fconfig = nullptr; this->name = nullptr; + this->protocol = P2pNodeRecord::TCP_IP_V6; this->port = 0; } @@ -57,8 +73,128 @@ void ZoneInstanceConfig::setName(const UnicodeString *name) { this->name = new UnicodeString(*name); } +void ZoneInstanceConfig::setProtocol(int protocol) { + this->protocol = protocol; +} + void ZoneInstanceConfig::setPort(int port) { this->port = port; } +JsonObject* ZoneInstanceConfig::toJsonObject() const { + JsonObject* configObj = new JsonObject(); __STP(configObj); + + // name + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"name")); + pair->setValue(new JsonStringValue(this->name)); + configObj->add(pair); + } + // protocol + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"protocol")); + + JsonStringValue* v = this->protocol == P2pNodeRecord::TCP_IP_V4 ? new JsonStringValue(L"ipv4") : new JsonStringValue(L"ipv6"); + pair->setValue(v); + configObj->add(pair); + } + // port + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"port")); + pair->setValue(new JsonNumericValue(this->port)); + configObj->add(pair); + } + + if(this->genConfig != nullptr){ + JsonValuePair* pair = new JsonValuePair(); __STP(pair); + pair->setKey(new JsonStringValue(L"genesis")); + pair->setValue(this->genConfig->toJsonObject()); + + configObj->add(__STP_MV(pair)); + } + if(this->minerConfig != nullptr){ + JsonValuePair* pair = new JsonValuePair(); __STP(pair); + pair->setKey(new JsonStringValue(L"mining")); + pair->setValue(this->minerConfig->toJsonObject()); + + configObj->add(__STP_MV(pair)); + } + if(this->fconfig != nullptr){ + JsonValuePair* pair = new JsonValuePair(); __STP(pair); + pair->setKey(new JsonStringValue(L"staking")); + pair->setValue(this->fconfig->toJsonObject()); + + configObj->add(__STP_MV(pair)); + } + + return __STP_MV(configObj); +} + +ZoneInstanceConfig* ZoneInstanceConfig::fromJson(const JsonObject *jobj) { + ZoneInstanceConfig* config = new ZoneInstanceConfig(); __STP(config); + + const JsonValuePair* pair = jobj->get(L"name"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonStringValue* value = dynamic_cast(av); + + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"name of the Zone Instance must be String type.", __FILE__, __LINE__); + config->setName(value->getValue()); + } + pair = jobj->get(L"protocol"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonStringValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"protocol of the Zone Instance must be String type.", __FILE__, __LINE__); + + const UnicodeString* str = value->getValue(); + if(str->equals(L"ipv4")){ + config->setProtocol(P2pNodeRecord::TCP_IP_V4); + }else{ + config->setProtocol(P2pNodeRecord::TCP_IP_V6); + } + } + pair = jobj->get(L"port"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonNumericValue* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"port of the Zone Instance must be Numeric type.", __FILE__, __LINE__); + + config->setPort(value->getValue()); + } + + pair = jobj->get(L"genesis"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonObject* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"genesis of the Zone Instance must be object type.", __FILE__, __LINE__); + + GenesisBalanceConfig* cfg = GenesisBalanceConfig::fromJson(value); __STP(cfg); + config->setGenesisConfig(cfg); + } + pair = jobj->get(L"mining"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonObject* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"mining of the Zone Instance must be object type.", __FILE__, __LINE__); + + MiningConfig*cfg = MiningConfig::fromJson(value); __STP(cfg); + config->setMiningConfig(cfg); + } + pair = jobj->get(L"staking"); + if(pair != nullptr){ + AbstractJsonObject* av = pair->getValue(); + JsonObject* value = dynamic_cast(av); + ExceptionThrower::throwExceptionIfCondition(value == nullptr, L"staking of the Zone Instance must be object type.", __FILE__, __LINE__); + + FinalizerConfig* cfg = FinalizerConfig::fromJson(value); __STP(cfg); + config->setFinalizerConfig(cfg); + } + + return __STP_MV(config); +} + } /* namespace codablecash */ diff --git a/src_simnet/sim/ZoneInstanceConfig.h b/src_simnet/sim/ZoneInstanceConfig.h index aff1af29..3359e746 100644 --- a/src_simnet/sim/ZoneInstanceConfig.h +++ b/src_simnet/sim/ZoneInstanceConfig.h @@ -18,6 +18,7 @@ namespace codablecash { class GenesisBalanceConfig; class MiningConfig; class FinalizerConfig; +class JsonObject; class ZoneInstanceConfig { public: @@ -29,14 +30,19 @@ class ZoneInstanceConfig { void setMiningConfig(const MiningConfig* minerConfig); void setFinalizerConfig(const FinalizerConfig* fconfig); void setName(const UnicodeString* name); + void setProtocol(int protocol); void setPort(int port); + JsonObject* toJsonObject() const; + static ZoneInstanceConfig* fromJson(const JsonObject* jobj); + private: + int protocol; + UnicodeString* name; + int port; GenesisBalanceConfig* genConfig; MiningConfig* minerConfig; FinalizerConfig* fconfig; - UnicodeString* name; - int port; }; } /* namespace codablecash */ diff --git a/src_simnet/sim/ZoneSimulator.cpp b/src_simnet/sim/ZoneSimulator.cpp index 1fbc1934..7fc7e76b 100644 --- a/src_simnet/sim/ZoneSimulator.cpp +++ b/src_simnet/sim/ZoneSimulator.cpp @@ -14,7 +14,7 @@ #include "json_object/JsonArrayObject.h" #include "json_object/JsonValuePair.h" #include "json_object/JsonStringValue.h" - +#include "json_object/JsonNumericValue.h" namespace codablecash { @@ -45,6 +45,13 @@ void ZoneSimulator::shutdown() { JsonObject* ZoneSimulator::makeJsonSettingObject() { JsonObject* obj = new JsonObject(); __STP(obj); + { + JsonValuePair* pair = new JsonValuePair(); + pair->setKey(new JsonStringValue(L"zone")); + pair->setValue(new JsonNumericValue(this->zone)); + obj->add(pair); + } + JsonArrayObject* instArray = new JsonArrayObject(); { JsonValuePair* pair = new JsonValuePair(); diff --git a/src_test/simnet/test_sim_config.cpp b/src_test/simnet/test_sim_config.cpp index 0731caab..9cac4f55 100644 --- a/src_test/simnet/test_sim_config.cpp +++ b/src_test/simnet/test_sim_config.cpp @@ -6,8 +6,35 @@ */ #include "test_utils/t_macros.h" +#include "sim/ZoneInstanceConfig.h" + +#include "bc_wallet_encoder/PasswordEncoder.h" + +#include "bc_wallet_net/WalletConfig.h" +#include "bc_wallet_net/NetworkWallet.h" + +#include "bc/DebugDefaultLogger.h" +#include "bc/CodablecashSystemParam.h" + +#include "../blockchain/utils/DebugCodablecashSystemParamSetup.h" + +#include "bc_base/AddressDescriptor.h" +#include "bc_base/BalanceUnit.h" + +#include "bc_block_generator/MiningConfig.h" + +#include "bc_p2p_info/P2pNodeRecord.h" + +#include "bc_network/NodeIdentifierSource.h" + +#include "bc_network_instance/FinalizerConfig.h" +#include "bc_network_instance/GenesisBalanceConfig.h" + #include "json/JsonHandler.h" +#include "json_object/JsonObject.h" + + using namespace codablecash; // JsonHandler @@ -20,6 +47,71 @@ TEST_GROUP(TestSimConfigGroup) { TEST(TestSimConfigGroup, case01){ File projectFolder = this->env->testCaseDir(); + DebugDefaultLogger logger; + logger.addSection(ISystemLogger::DEBUG_NODE_TRANSFER_RESPONSE); + logger.addSection(ISystemLogger::DEBUG_TRX_MEMPOOL_REGISTER); + + CodablecashSystemParam param; + DebugCodablecashSystemParamSetup::setupConfig02(param); + + // wallet + UnicodeString pass(L"changeit"); + PasswordEncoder enc(&pass); + WalletConfig walletConfig; + File* dirWallet00 = projectFolder.get(L"wallet00"); __STP(dirWallet00); + NetworkWallet* wallet = NetworkWallet::createNewWallet(dirWallet00, &pass, 0, 10, &logger, ¶m, &walletConfig); __STP(wallet); + + + ZoneInstanceConfig* conf = new ZoneInstanceConfig(); __STP(conf); + + { + // genesis address + AddressDescriptor* desc = wallet->getAddressDescriptor(0, 0); __STP(desc); + + GenesisBalanceConfig gconfig; + BalanceUnit amount(1000L * 10000L * 10000L); + gconfig.addBalance(amount, desc); + conf->setGenesisConfig(&gconfig); + } + { + // mining + MiningConfig minerConfig; + AddressDescriptor* desc2 = wallet->getAddressDescriptor(0, 1); __STP(desc2); + minerConfig.setAddressDescriptor(desc2); + minerConfig.setCalclatorType(MiningConfig::TYPE_POOL); + + minerConfig.setProtocol(P2pNodeRecord::TCP_IP_V4); + UnicodeString host(L"127.0.0.1"); + minerConfig.setServerHost(&host); + minerConfig.setPort(1111); + + conf->setMiningConfig(&minerConfig); + } + { + // finalizer + FinalizerConfig fconfig; + NodeIdentifierSource* voteSource = NodeIdentifierSource::create(); __STP(voteSource); + fconfig.setVoterSource(voteSource); + conf->setFinalizerConfig(&fconfig); + } + + { + UnicodeString name(L"node.codablecash.org"); + conf->setName(&name); + conf->setPort(18080); + conf->setProtocol(P2pNodeRecord::TCP_IP_V4); + } + + JsonObject* jobj = conf->toJsonObject(); __STP(jobj); + UnicodeString* json = jobj->toString(); __STP(json); + + JsonHandler handler; + handler.loadString(json); + + AbstractJsonObject* parsedObj = handler.parse(); __STP(parsedObj); + + ZoneInstanceConfig* cfg = ZoneInstanceConfig::fromJson(dynamic_cast(parsedObj)); __STP(cfg); + //JsonHandler // JsonArrayObject