Skip to content
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions sh/parttest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -eux


pushd target

make all -j6

./testall -v -g TestAllocationIfGroup
make report

popd


5 changes: 5 additions & 0 deletions src/ecda/ScPrivateKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace codablecash {
const BigInteger ScPrivateKey::p(L"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16);

ScPrivateKey::ScPrivateKey(const BigInteger* seed, uint64_t solt) : keyvalue((int64_t)0) {
assert(solt != 0);
BigInteger pow(solt);

this->keyvalue = seed->multiply(pow).mod(ScPrivateKey::p);
Expand All @@ -37,4 +38,8 @@ ScPublicKey ScPrivateKey::generatePublicKey() {
return ScPublicKey(pt);
}

int ScPrivateKey::compareTo(const ScPrivateKey *other) const {
return this->keyvalue.compareTo(other->keyvalue);
}

} /* namespace codablecash */
7 changes: 7 additions & 0 deletions src/ecda/ScPrivateKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ScPrivateKey {
public:
static const BigInteger p; // = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16);

/**
* solt must not be 0
* @param seed
* @param solt
*/
ScPrivateKey(const BigInteger* seed, uint64_t solt);
ScPrivateKey();
virtual ~ScPrivateKey();
Expand All @@ -32,6 +37,8 @@ class ScPrivateKey {
return keyvalue;
}

int compareTo(const ScPrivateKey* other) const;

private:
BigInteger keyvalue;

Expand Down
9 changes: 9 additions & 0 deletions src/ecda/Secp256k1CompressedPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,13 @@ IBlockObject* Secp256k1CompressedPoint::copyData() const noexcept {
return new Secp256k1CompressedPoint(this->x, this->prefix);
}

int Secp256k1CompressedPoint::compareTo(const Secp256k1CompressedPoint *other) {
int cmp = this->prefix - other->prefix;
if(cmp != 0){
return cmp;
}

return this->x.compareTo(other->x);
}

} /* namespace codablecash */
2 changes: 2 additions & 0 deletions src/ecda/Secp256k1CompressedPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Secp256k1CompressedPoint : public IBlockObject {

virtual IBlockObject* copyData() const noexcept;

int compareTo(const Secp256k1CompressedPoint* other);

private:
uint8_t prefix;
BigInteger x;
Expand Down
26 changes: 26 additions & 0 deletions src_blockchain/bc/SoftwareVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
#include "base/StackRelease.h"
#include "base/Integer.h"

#include "base_io/ByteBuffer.h"


namespace codablecash {

SoftwareVersion::SoftwareVersion(const SoftwareVersion &inst) {
this->major = inst.major;
this->minor = inst.minor;
this->patch = inst.patch;
}

SoftwareVersion::SoftwareVersion(int major, int minor, int patch) {
this->major = major;
this->minor = minor;
Expand Down Expand Up @@ -76,4 +84,22 @@ SoftwareVersion* SoftwareVersion::parseString(const UnicodeString *str) {
return new SoftwareVersion(major, minor, patch);
}

int SoftwareVersion::binarySize() const {
return sizeof(uint8_t) * 3;
}

void SoftwareVersion::toBinary(ByteBuffer *out) const {
out->put(this->major);
out->put(this->minor);
out->put(this->patch);
}

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

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

} /* namespace codablecash */
7 changes: 7 additions & 0 deletions src_blockchain/bc/SoftwareVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

namespace alinous {
class UnicodeString;
class ByteBuffer;
}
using namespace alinous;

namespace codablecash {

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

Expand All @@ -38,6 +40,11 @@ class SoftwareVersion {

static SoftwareVersion* parseString(const UnicodeString* str);

// binary
virtual int binarySize() const;
virtual void toBinary(ByteBuffer* out) const;
static SoftwareVersion* createFromBinary(ByteBuffer* in);

protected:
int major;
int minor;
Expand Down
22 changes: 22 additions & 0 deletions src_blockchain/bc_base/Abstract32BytesId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
#include "numeric/BigInteger.h"

#include "base/StackRelease.h"

#include "bc_wallet/HdWalletSeed.h"
namespace codablecash {

const BigInteger Abstract32BytesId::Q(L"ff66c4652cbb54e13e4cc75898014aef72332e147343a95031cf416ca9f77ce7", 16);
const BigInteger Abstract32BytesId::G(L"e000000000000000000000000000000000000000000000000000000000000002", 16);

Abstract32BytesId::Abstract32BytesId() {
this->id = nullptr;
}
Expand Down Expand Up @@ -87,4 +92,21 @@ int Abstract32BytesId::ValueCompare::operator ()(const Abstract32BytesId *const
return a->compareTo(b);
}

ByteBuffer* Abstract32BytesId::makeRandom16Bytes() {
int size = 0;
BigInteger p(L"0", 16);
do{
BigInteger seed = BigInteger::ramdom();

BigInteger s = seed.mod(Abstract32BytesId::Q);
p = G.modPow(s, Abstract32BytesId::Q);
size = p.binarySize();
} while(size != 32);

ByteBuffer* buff = p.toBinary(); __STP(buff);
buff->position(0);

return __STP_MV(buff);
}

} /* namespace codablecash */
6 changes: 6 additions & 0 deletions src_blockchain/bc_base/Abstract32BytesId.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Abstract32BytesId : public IBlockObject {
protected:
Abstract32BytesId();
public:
static const BigInteger Q;
static const BigInteger G;

explicit Abstract32BytesId(const Abstract32BytesId& inst);
Abstract32BytesId(const char* binary, int length);
virtual ~Abstract32BytesId();
Expand Down Expand Up @@ -55,6 +58,9 @@ class Abstract32BytesId : public IBlockObject {
int operator () (const Abstract32BytesId* const a, const Abstract32BytesId* const b) const;
};

protected:
static ByteBuffer* makeRandom16Bytes();

protected:
ByteBuffer* id; // 32 bytes
};
Expand Down
10 changes: 10 additions & 0 deletions src_blockchain/bc_base/AbstractAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,14 @@ AddressDescriptor* AbstractAddress::toAddressDescriptor() const noexcept {
return new AddressDescriptor(prefix, zonech, charstr, length);
}

UnicodeString* AbstractAddress::toString() const noexcept {
AddressDescriptor* desc = toAddressDescriptor(); __STP(desc);

const char* ch = desc->toCString();

UnicodeString* str = new UnicodeString(ch);
delete [] ch;
return str;
}

} /* namespace codablecash */
2 changes: 2 additions & 0 deletions src_blockchain/bc_base/AbstractAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class AbstractAddress : public alinous::IBlockObject {
virtual ByteBuffer* getBodyPart() const noexcept = 0;
AddressDescriptor* toAddressDescriptor() const noexcept;

UnicodeString* toString() const noexcept;

protected:
uint16_t zone;
};
Expand Down
8 changes: 8 additions & 0 deletions src_blockchain/bc_block/BlockHeaderId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ IBlockObject* BlockHeaderId::copyData() const noexcept {
return new BlockHeaderId(*this);
}

BlockHeaderId* BlockHeaderId::makeRandomHeaderId() {
ByteBuffer* buff = makeRandom16Bytes(); __STP(buff);

BlockHeaderId* blockHeaderId = new BlockHeaderId((const char *)buff->array(), buff->capacity());

return blockHeaderId;
}

} /* namespace codablecash */
2 changes: 2 additions & 0 deletions src_blockchain/bc_block/BlockHeaderId.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class BlockHeaderId : public Abstract32BytesId {
BlockHeaderId(const char* binary, int length);
virtual ~BlockHeaderId();

static BlockHeaderId* makeRandomHeaderId();

static BlockHeaderId* fromBinary(ByteBuffer* in);

virtual IBlockObject* copyData() const noexcept;
Expand Down
4 changes: 2 additions & 2 deletions src_blockchain/bc_blockstore/CodablecashBlockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ void CodablecashBlockchain::initZonesStore() {
}

void CodablecashBlockchain::initZone(uint16_t zone) {
char tmp[4];
Mem::memset(tmp, 0, 4);
char tmp[6];
Mem::memset(tmp, 0, 6);

::sprintf(tmp, "%03d", zone);

Expand Down
17 changes: 3 additions & 14 deletions src_blockchain/bc_wallet/HdWalletSeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

namespace codablecash {

const BigInteger HdWalletSeed::Q(L"ff66c4652cbb54e13e4cc75898014aef72332e147343a95031cf416ca9f77ce7", 16);
const BigInteger HdWalletSeed::G(L"e000000000000000000000000000000000000000000000000000000000000002", 16);



HdWalletSeed::HdWalletSeed() : Abstract32BytesId() {
Expand All @@ -33,21 +32,11 @@ HdWalletSeed::~HdWalletSeed() {
}

HdWalletSeed* HdWalletSeed::newSeed() noexcept {
int size = 0;
BigInteger p(L"0", 16);
do{
BigInteger seed = BigInteger::ramdom();

BigInteger s = seed.mod(HdWalletSeed::Q);
p = G.modPow(s, HdWalletSeed::Q);
size = p.binarySize();
} while(size != 32);

ByteBuffer* buff = p.toBinary(); __STP(buff);
ByteBuffer* buff = makeRandom16Bytes(); __STP(buff);
buff->position(0);

HdWalletSeed* walletSeed = new HdWalletSeed();
walletSeed->id = ByteBuffer::wrapWithEndian(buff->array(), size, true);
walletSeed->id = ByteBuffer::wrapWithEndian(buff->array(), buff->capacity(), true);

return walletSeed;

Expand Down
3 changes: 0 additions & 3 deletions src_blockchain/bc_wallet/HdWalletSeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class HdWalletSeed : public Abstract32BytesId {
protected:
HdWalletSeed();
public:
static const BigInteger Q;
static const BigInteger G;

HdWalletSeed(const char* binary, int length);

virtual ~HdWalletSeed();
Expand Down
2 changes: 1 addition & 1 deletion src_db/base/ArrayList.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ template <typename T, typename C = RawCompare> class ArrayList {
T* search(const T* value) noexcept
{
if(this->numArray == 0){
return 0;
return nullptr;
}

if(!this->sorted){
Expand Down
1 change: 1 addition & 0 deletions src_db/base/Long.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UnicodeString;

class Long {
public:
static const constexpr uint64_t MAX_UINT64 = 0xFFFFFFFFFFFFFFFF;
Long();
virtual ~Long();

Expand Down
9 changes: 6 additions & 3 deletions src_db/base/UnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,13 @@ ArrayList<UnicodeString>* UnicodeString::split(const UnicodeString* regex, bool

std::wsregex_token_iterator it(str.begin(), str.end(), wreg, -1), end;
for (; it != end; ++it) {
const std::wstring res = *it;//(it->first, it->second);
const std::wstring partres = *it;//(it->first, it->second); // @suppress("Invalid arguments")

int len = res.length();
int len = partres.length();
if(!addBlankString && len == 0){
continue;
}
const wchar_t *cwstr = res.c_str();
const wchar_t *cwstr = partres.c_str();

UnicodeString* result = new UnicodeString(cwstr);
list->addElement(result);
Expand Down Expand Up @@ -585,6 +585,9 @@ bool UnicodeString::equals(const UnicodeString& str) const noexcept {

bool UnicodeString::equals(const UnicodeString* str) const noexcept
{
if(str == nullptr){
return false;
}
int hash = str->hashCode();
int _this_hash = this->hashCode();
if(hash != _this_hash){
Expand Down
39 changes: 39 additions & 0 deletions src_db/base/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,43 @@ IllegalArgumentException::IllegalArgumentException(const wchar_t* message, Excep
IllegalArgumentException::~IllegalArgumentException() {
}

const wchar_t* UnsupportedFunctionException::defaultMessage = L"Unsupported Function is called. ";

UnsupportedFunctionException::UnsupportedFunctionException(const char* srcfile, int srcline) noexcept : Exception(srcfile, srcline) {
this->message = new UnicodeString(defaultMessage);
}
UnsupportedFunctionException::UnsupportedFunctionException(Exception* cause, const char* srcfile, int srcline) noexcept : Exception(cause, srcfile, srcline) {
this->message = new UnicodeString(defaultMessage);
}
UnsupportedFunctionException::UnsupportedFunctionException(const wchar_t* message, const char* srcfile, int srcline) noexcept : Exception(message, srcfile, srcline) {
this->message = new UnicodeString(defaultMessage);
this->message->append(message);
}
UnsupportedFunctionException::UnsupportedFunctionException(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);
}
UnsupportedFunctionException::~UnsupportedFunctionException() {
}

const wchar_t* CompilantUnitAnalyzeException::defaultMessage = L"Analayze Unit has failed. ";

CompilantUnitAnalyzeException::CompilantUnitAnalyzeException(const char* srcfile, int srcline) noexcept : Exception(srcfile, srcline) {
this->message = new UnicodeString(defaultMessage);
}
CompilantUnitAnalyzeException::CompilantUnitAnalyzeException(Exception* cause, const char* srcfile, int srcline) noexcept : Exception(cause, srcfile, srcline) {
this->message = new UnicodeString(defaultMessage);
}
CompilantUnitAnalyzeException::CompilantUnitAnalyzeException(const wchar_t* message, const char* srcfile, int srcline) noexcept : Exception(message, srcfile, srcline) {
this->message = new UnicodeString(defaultMessage);
this->message->append(message);
}
CompilantUnitAnalyzeException::CompilantUnitAnalyzeException(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);
}
CompilantUnitAnalyzeException::~CompilantUnitAnalyzeException() {
}


} /* namespace alinous */
Loading