Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ endmacro(handle_sub)
#[[ =========================================================================================== ]]#

set(srcmain
AlinousStore.cpp
Codablecash.cpp
)
set(srcsim
CodableSim.cpp
)

include_directories(${PROJECT_SOURCE_DIR}/src/)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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}
)
Expand Down
13 changes: 13 additions & 0 deletions CodableSim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* CodableSim.cpp
*
* Created on: Sep 2, 2026
* Author: iizuka
*/


int main(int ac, char** av) {

return 0;
}

25 changes: 25 additions & 0 deletions Codablecash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//============================================================================
// Name : AlinousStore.cpp
// Author : Tomohiro Iizuka
// Version :
// Copyright : MIT License
// Description : Hello World in C, Ansi-style
//============================================================================

#include <stdio.h>
#include <stdlib.h>

#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;
}
1 change: 1 addition & 0 deletions src_blockchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions src_blockchain/bc_base/AddressCheckDigitException.cpp
Original file line number Diff line number Diff line change
@@ -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 */
29 changes: 29 additions & 0 deletions src_blockchain/bc_base/AddressCheckDigitException.h
Original file line number Diff line number Diff line change
@@ -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_ */
22 changes: 22 additions & 0 deletions src_blockchain/bc_base/AddressDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

#include <cstdio>

#include "bc/ExceptionThrower.h"

#include "bc_base/AddressCheckDigitException.h"

#include "base/Integer.h"
using namespace alinous;

namespace codablecash {
Expand Down Expand Up @@ -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<AddressCheckDigitException>::throwExceptionIfCondition(cmp != 0, L"Check digit error.", __FILE__, __LINE__);
}

void AddressDescriptor::makeCheckDigit() {
Expand Down Expand Up @@ -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 */
8 changes: 5 additions & 3 deletions src_blockchain/bc_base/AddressDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src_blockchain/bc_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set(__src
Abstract32BytesId.cpp
AbstractAddress.cpp
AddressCheckDigitException.cpp
AddressDescriptor.cpp
BalanceAddress.cpp
BalanceUnit.cpp
Expand Down
2 changes: 1 addition & 1 deletion src_blockchain/bc_base_conf_store/StatusStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void StatusStore::write() {
int StatusStore::binarySize() const {
int total = 0;

total += sizeof(int);
total += sizeof(uint32_t);

Iterator<UnicodeString>* it = this->map.keySet()->iterator(); __STP(it);
while(it->hasNext()){
Expand Down
1 change: 1 addition & 0 deletions src_blockchain/bc_block_body/Stakebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
134 changes: 132 additions & 2 deletions src_blockchain/bc_block_generator/MiningConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +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) {
Expand Down Expand Up @@ -83,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<const char> __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<JsonStringValue*>(av);
ExceptionThrower<SimnetConfigException>::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<JsonStringValue*>(av);
ExceptionThrower<SimnetConfigException>::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<JsonStringValue*>(av);
ExceptionThrower<SimnetConfigException>::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<JsonStringValue*>(av);
ExceptionThrower<SimnetConfigException>::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<JsonNumericValue*>(av);
ExceptionThrower<SimnetConfigException>::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 */
Loading