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
33 changes: 33 additions & 0 deletions src_blockchain/bc/BlockchainSoftwareVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* BlockchainSoftwareVersion.cpp
*
* Created on: May 5, 2026
* Author: iizuka
*/

#include "bc/BlockchainSoftwareVersion.h"

#include "base_io/ByteBuffer.h"

namespace codablecash {
/*
BlockchainSoftwareVersion::BlockchainSoftwareVersion(const BlockchainSoftwareVersion &inst) : SoftwareVersion(inst) {
}*/

BlockchainSoftwareVersion::BlockchainSoftwareVersion(int major, int minor, int patch) : SoftwareVersion(major, minor, patch) {

}

BlockchainSoftwareVersion::~BlockchainSoftwareVersion() {

}
/*
BlockchainSoftwareVersion* BlockchainSoftwareVersion::createFromBinary(ByteBuffer *in) {
uint8_t major = in->get();
uint8_t minor = in->get();
uint8_t pathch = in->get();

return new BlockchainSoftwareVersion(major, minor, pathch);
}
*/
} /* namespace codablecash */
26 changes: 26 additions & 0 deletions src_blockchain/bc/BlockchainSoftwareVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* BlockchainSoftwareVersion.h
*
* Created on: May 5, 2026
* Author: iizuka
*/

#ifndef BC_BLOCKCHAINSOFTWAREVERSION_H_
#define BC_BLOCKCHAINSOFTWAREVERSION_H_

#include "bc/SoftwareVersion.h"

namespace codablecash {

class BlockchainSoftwareVersion : public SoftwareVersion {
public:
//BlockchainSoftwareVersion(const BlockchainSoftwareVersion& inst);
BlockchainSoftwareVersion(int major, int minor, int patch);
virtual ~BlockchainSoftwareVersion();

//static BlockchainSoftwareVersion* createFromBinary(ByteBuffer* in);
};

} /* namespace codablecash */

#endif /* BC_BLOCKCHAINSOFTWAREVERSION_H_ */
1 change: 1 addition & 0 deletions src_blockchain/bc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


set(__src
BlockchainSoftwareVersion.cpp
CodablecashNodeInstance.cpp
CodablecashSystemParam.cpp
DebugDefaultLogger.cpp
Expand Down
2 changes: 1 addition & 1 deletion src_blockchain/bc/DebugDefaultLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void DebugDefaultLogger::log(const UnicodeString *message) noexcept {
delete [] str;
}

void DebugDefaultLogger::setSection(int section) noexcept {
void DebugDefaultLogger::addSection(int section) noexcept {
this->sections.addElement(section);
}

Expand Down
2 changes: 1 addition & 1 deletion src_blockchain/bc/DebugDefaultLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DebugDefaultLogger: public ISystemLogger {
DebugDefaultLogger();
virtual ~DebugDefaultLogger();

void setSection(int section) noexcept;
void addSection(int section) noexcept;

virtual void logException(const Exception* e) noexcept;
virtual void log(const UnicodeString* message) noexcept;
Expand Down
27 changes: 23 additions & 4 deletions src_blockchain/bc_block/BlockHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "bc_block/BlockHeader.h"
#include "bc_block/BlockHeaderId.h"
#include "bc_block/BlockVersion.h"

#include "base/StackRelease.h"

Expand All @@ -25,11 +26,12 @@
#include "bc_block_vote/VotePart.h"
#include "bc_block_vote/VotedHeaderIdGroup.h"


#include "bc_base/BinaryUtils.h"

namespace codablecash {

BlockHeader::BlockHeader() {
this->version = new BlockVersion(1, 0, 0);
this->zone = 0;
this->height = 0;
this->id = new BlockHeaderId();
Expand All @@ -47,10 +49,11 @@ BlockHeader::BlockHeader() {
this->nonce = new PoWNonce(&defaultNonce);

this->votePart = new VotePart();
this->lastNouceCalculated = dynamic_cast<SystemTimestamp*>(Os::now().copyData());;
this->lastNouceCalculated = dynamic_cast<SystemTimestamp*>(Os::now().copyData());
}

BlockHeader::~BlockHeader() {
delete this->version;
delete this->id;
delete this->merkleRoot;
delete this->lastid;
Expand All @@ -63,7 +66,9 @@ BlockHeader::~BlockHeader() {
}

int BlockHeader::binarySize() const {
int total = sizeof(this->zone) + sizeof(this->height);
BinaryUtils::checkNotNull(this->version);

int total = this->version->binarySize() + sizeof(this->zone) + sizeof(this->height);

total += this->timestamp->binarySize();
total += this->nonceGeneratedtimestamp->binarySize();
Expand All @@ -77,6 +82,9 @@ int BlockHeader::binarySize() const {
}

void BlockHeader::toBinary(ByteBuffer *out) const {
BinaryUtils::checkNotNull(this->version);

this->version->toBinary(out);
out->putShort(this->zone);
out->putLong(this->height);

Expand All @@ -92,6 +100,9 @@ void BlockHeader::toBinary(ByteBuffer *out) const {
BlockHeader* BlockHeader::createFromBinary(ByteBuffer* in) {
BlockHeader* header = new BlockHeader(); __STP(header);

BlockVersion* ver = BlockVersion::createFromBinary(in); __STP(ver);
header->setVersion(ver);

uint16_t zone = in->getShort();
header->setZone(zone);

Expand Down Expand Up @@ -134,13 +145,20 @@ IBlockObject* BlockHeader::copyData() const noexcept {
return BlockHeader::createFromBinary(buff);
}

void BlockHeader::setVersion(const BlockVersion *ver) {
delete this->version, this->version = nullptr;
this->version = new BlockVersion(*ver);
}

void BlockHeader::setHeaderId(BlockHeaderId* id) noexcept {
delete this->id;
this->id = id;
}

void BlockHeader::buildHeaderId() {
int total = sizeof(this->zone) + sizeof(this->height);
BinaryUtils::checkNotNull(this->version);

int total = this->version->binarySize() + sizeof(this->zone) + sizeof(this->height);
total += this->timestamp->binarySize();
//total += this->nonceGeneratedtimestamp->binarySize(); // do not include calculated time

Expand All @@ -151,6 +169,7 @@ void BlockHeader::buildHeaderId() {
total += this->lastNouceCalculated->binarySize();

ByteBuffer* buff = ByteBuffer::allocateWithEndian(total, true); __STP(buff);
this->version->toBinary(buff);
buff->putShort(this->zone);
buff->putLong(this->height);
this->timestamp->toBinary(buff);
Expand Down
5 changes: 5 additions & 0 deletions src_blockchain/bc_block/BlockHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Block;
class IVoteTransactionIdCertificateBuilder;
class IVoteTransactionIdCertificatevisitor;
class TransactionId;
class BlockVersion;

class BlockHeader : public alinous::IBlockObject {
public:
Expand All @@ -41,6 +42,8 @@ class BlockHeader : public alinous::IBlockObject {

virtual IBlockObject* copyData() const noexcept;

void setVersion(const BlockVersion* ver);

void setHeight(uint64_t height) noexcept {
this->height = height;
}
Expand Down Expand Up @@ -104,6 +107,8 @@ class BlockHeader : public alinous::IBlockObject {
void visitVoteTransactionIdCertificate(IVoteTransactionIdCertificatevisitor* visitor) const;

private:
BlockVersion* version;

uint16_t zone;
uint64_t height;
SystemTimestamp* timestamp;
Expand Down
36 changes: 36 additions & 0 deletions src_blockchain/bc_block/BlockVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* BlockVersion.cpp
*
* Created on: May 5, 2026
* Author: iizuka
*/

#include "bc_block/BlockVersion.h"

#include "bc/SoftwareVersion.h"

#include "base_io/ByteBuffer.h"

namespace codablecash {


BlockVersion::BlockVersion(const BlockVersion &inst) : SoftwareVersion(inst.major, inst.minor, inst.patch) {
}

BlockVersion::BlockVersion(int major, int minor, int patch) : SoftwareVersion(major, minor, patch) {

}

BlockVersion::~BlockVersion() {

}

BlockVersion* BlockVersion::createFromBinary(ByteBuffer *in) {
uint8_t major = in->get();
uint8_t minor = in->get();
uint8_t pathch = in->get();

return new BlockVersion(major, minor, pathch);
}

} /* namespace codablecash */
26 changes: 26 additions & 0 deletions src_blockchain/bc_block/BlockVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* BlockVersion.h
*
* Created on: May 5, 2026
* Author: iizuka
*/

#ifndef BC_BLOCK_BLOCKVERSION_H_
#define BC_BLOCK_BLOCKVERSION_H_

#include "bc/SoftwareVersion.h"

namespace codablecash {

class BlockVersion : public SoftwareVersion {
public:
BlockVersion(const BlockVersion& inst);
BlockVersion(int major, int minor, int patch);
virtual ~BlockVersion();

static BlockVersion* createFromBinary(ByteBuffer* in);
};

} /* namespace codablecash */

#endif /* BC_BLOCK_BLOCKVERSION_H_ */
1 change: 1 addition & 0 deletions src_blockchain/bc_block/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ set(__src
BlockMerkleRoot.cpp
BlockMerkleRootKey.cpp
BlockMerkleRootKeyFactory.cpp
BlockVersion.cpp
)
handle_sub(codablecashlib "${__src}" blockchain bc_block)
14 changes: 12 additions & 2 deletions src_blockchain/bc_block_body/AbstractBlockRewordTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "bc_trx/AbstractUtxo.h"
#include "bc_trx/AbstractUtxoReference.h"
#include "bc_trx/TransactionVersion.h"

#include "base/StackRelease.h"

Expand Down Expand Up @@ -81,8 +82,9 @@ AbstractUtxoReference* AbstractBlockRewordTransaction::getUtxoReference(int i) c
void AbstractBlockRewordTransaction::setUtxoNonce() noexcept {
assert(this->height != 0L);
BinaryUtils::checkNotNull(this->timestamp);
BinaryUtils::checkNotNull(this->version);

int capacity = sizeof(uint8_t) + this->timestamp->binarySize() + sizeof(this->height);
int capacity = sizeof(uint8_t) + this->version->binarySize() + this->timestamp->binarySize() + sizeof(this->height);
{
int maxLoop = getUtxoReferenceSize();
for(int i = 0; i != maxLoop; ++i){
Expand All @@ -94,6 +96,7 @@ void AbstractBlockRewordTransaction::setUtxoNonce() noexcept {

ByteBuffer* buff = ByteBuffer::allocateWithEndian(capacity, true); __STP(buff);
buff->put(getType());
this->version->toBinary(buff);
this->timestamp->toBinary(buff);
buff->putLong(this->height);
{
Expand All @@ -119,9 +122,11 @@ void AbstractBlockRewordTransaction::setUtxoNonce() noexcept {
}

int AbstractBlockRewordTransaction::__binarySize() const {
BinaryUtils::checkNotNull(this->version);
BinaryUtils::checkNotNull(this->timestamp);

int total = sizeof(uint8_t);
total += this->version->binarySize();
total += this->timestamp->binarySize();
total += sizeof(this->height);

Expand Down Expand Up @@ -149,9 +154,11 @@ int AbstractBlockRewordTransaction::__binarySize() const {
}

void AbstractBlockRewordTransaction::__toBinary(ByteBuffer *out) const {
BinaryUtils::checkNotNull(this->version);
BinaryUtils::checkNotNull(this->timestamp);

out->put(getType());
this->version->toBinary(out);
this->timestamp->toBinary(out);
out->putLong(this->height);

Expand Down Expand Up @@ -181,7 +188,10 @@ BalanceUnit AbstractBlockRewordTransaction::getFee() const noexcept {
}

void AbstractBlockRewordTransaction::__fromBinary(ByteBuffer *in) {
delete this->timestamp;
delete this->version, this->version = nullptr;
this->version = TransactionVersion::createFromBinary(in);

delete this->timestamp, timestamp = nullptr;
this->timestamp = SystemTimestamp::fromBinary(in);
this->height = in->getLong();

Expand Down
10 changes: 6 additions & 4 deletions src_blockchain/bc_blockstore/CodablecashBlockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "base_thread/ConcurrentGate.h"
#include "base_thread/SysMutex.h"

#include "bc/SoftwareVersion.h"
#include "bc/BlockchainSoftwareVersion.h"

#include "bc_block/Block.h"
#include "bc_block/BlockHeader.h"
Expand All @@ -36,6 +36,8 @@
#include "base_thread/StackUnlocker.h"

#include "bc_block/BlockMerkleRoot.h"


namespace codablecash {

const UnicodeString CodablecashBlockchain::CONFIG_BIN_FILE(L"config.bin");
Expand All @@ -57,7 +59,7 @@ CodablecashBlockchain::CodablecashBlockchain(const File *baseDir, uint16_t zoneS
this->sectionLimit = DEFAULT_SECTION_LIMIT;

this->configStore = nullptr;
this->version = new SoftwareVersion(0, 1, 0);
this->version = new BlockchainSoftwareVersion(0, 1, 0);

this->rwLock = new ConcurrentGate();
this->processor = nullptr;
Expand All @@ -71,7 +73,7 @@ CodablecashBlockchain::CodablecashBlockchain(const File* baseDir) {
this->numZones = 0;
this->sectionLimit = 0;
this->configStore = nullptr;
this->version = new SoftwareVersion(0, 1, 0);
this->version = new BlockchainSoftwareVersion(0, 1, 0);

this->rwLock = new ConcurrentGate();
this->processor = nullptr;
Expand Down Expand Up @@ -223,7 +225,7 @@ void CodablecashBlockchain::loadCondig() {
int patch = this->configStore->getShortValue(&KEY_BLOCK_VERSION_PATCH);

delete this->version;
this->version = new SoftwareVersion(major, minor, patch);
this->version = new BlockchainSoftwareVersion(major, minor, patch);
}

void CodablecashBlockchain::addBlock(MemPoolTransaction* memTrx, const Block *block) {
Expand Down
Loading