Skip to content
  •  
  •  
  •  
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
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
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 */
21 changes: 21 additions & 0 deletions src_db/base/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ class IllegalArgumentException : public Exception{
static const wchar_t* defaultMessage;
};

class UnsupportedFunctionException : public Exception{
public:
UnsupportedFunctionException(const char* srcfile, int srcline) noexcept;
UnsupportedFunctionException(Exception* cause, const char* srcfile, int srcline) noexcept;
UnsupportedFunctionException(const wchar_t* message, const char* srcfile, int srcline) noexcept;
UnsupportedFunctionException(const wchar_t* message, Exception* cause, const char* srcfile, int srcline) noexcept;
virtual ~UnsupportedFunctionException();
static const wchar_t* defaultMessage;
};

class CompilantUnitAnalyzeException : public Exception{
public:
CompilantUnitAnalyzeException(const char* srcfile, int srcline) noexcept;
CompilantUnitAnalyzeException(Exception* cause, const char* srcfile, int srcline) noexcept;
CompilantUnitAnalyzeException(const wchar_t* message, const char* srcfile, int srcline) noexcept;
CompilantUnitAnalyzeException(const wchar_t* message, Exception* cause, const char* srcfile, int srcline) noexcept;
virtual ~CompilantUnitAnalyzeException();
static const wchar_t* defaultMessage;
};


} /* namespace alinous */

#endif /* BASE_EXCEPTIONS_H_ */
14 changes: 13 additions & 1 deletion src_db/btree/NodePosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,23 @@ uint64_t NodePosition::getNextChildPrevious(const AbstractBtreeKey* key) {
for(int i = maxLoop - 1; i >= 0; --i){
NodeHandle* nh = this->innerNodes->get(i);

if(key->compareTo(nh->getKey()) <= 0){
if(key->compareTo(nh->getKey()) == 0){
ret = nh->getFpos();
this->pos = i - 1;
break;
}
else if(key->compareTo(nh->getKey()) > 0){
nh = this->innerNodes->get(i + 1);
ret = nh->getFpos();
this->pos = i;
break;
}
}

if(ret == 0){
NodeHandle* nh = this->innerNodes->get(0);
ret = nh->getFpos();
this->pos = -1;
}

return ret;
Expand Down
42 changes: 42 additions & 0 deletions src_db/json_object/AbstractJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
*/

#include "json_object/AbstractJsonObject.h"
#include "json_object/JsonObject.h"
#include "json_object/JsonValuePair.h"
#include "json_object/JsonArrayObject.h"

#include "base_io/ByteBuffer.h"

#include "json_object/JsonStringValue.h"

#include "json_object/JsonBooleanValue.h"

#include "json_object/JsonNumericValue.h"
namespace codablecash {

AbstractJsonObject::AbstractJsonObject() {
Expand All @@ -17,4 +27,36 @@ AbstractJsonObject::~AbstractJsonObject() {

}

AbstractJsonObject* AbstractJsonObject::createFromBinary(ByteBuffer *in) {
AbstractJsonObject* object = nullptr;

uint8_t type = in->get();
switch(type){
case JSON_TYPE_OBJECT:
object = new JsonObject();
break;
case JSON_TYPE_ARRAY_OBJECT:
object = new JsonArrayObject();
break;
case JSON_TYPE_VALUE_PAIR:
object = new JsonValuePair();
break;
case JSON_TYPE_STRING_VALUE:
object = new JsonStringValue();
break;
case JSON_TYPE_BOOLEAN_VALUE:
object = new JsonBooleanValue();
break;
case JSON_TYPE_NUMERIC_VALUE:
object = new JsonNumericValue();
break;
default:
return nullptr;
}

object->fromBinary(in);

return object;
}

} /* namespace codablecash */
10 changes: 10 additions & 0 deletions src_db/json_object/AbstractJsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#define JSON_OBJECT_ABSTRACTJSONOBJECT_H_
#include <cstdint>

namespace alinous {
class ByteBuffer;
}
using namespace alinous;

namespace codablecash {

class AbstractJsonObject {
Expand All @@ -26,6 +31,11 @@ class AbstractJsonObject {
virtual uint8_t getType() const noexcept = 0;
virtual AbstractJsonObject* copy() const noexcept = 0;
virtual bool equals(const AbstractJsonObject* other) const noexcept = 0;

virtual int binarySize() const = 0;
virtual void toBinary(ByteBuffer *out) const = 0;
virtual void fromBinary(ByteBuffer *in) = 0;
static AbstractJsonObject* createFromBinary(ByteBuffer* in);
};

} /* namespace codablecash */
Expand Down
8 changes: 8 additions & 0 deletions src_db/json_object/AbstractJsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@

#include "json_object/AbstractJsonObject.h"

namespace alinous {
class AbstractFunctionExtArguments;


} // namespace alinous

namespace codablecash {

class AbstractJsonValue : public AbstractJsonObject {
public:
AbstractJsonValue();
virtual ~AbstractJsonValue();

virtual AbstractFunctionExtArguments* toFunctionExtArgument() const = 0;
};

} /* namespace codablecash */
Expand Down
40 changes: 40 additions & 0 deletions src_db/json_object/JsonArrayObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "json_object/JsonArrayObject.h"
#include "json_object/AbstractJsonObject.h"

#include "base_io/ByteBuffer.h"

#include "bc_base/BinaryUtils.h"


namespace codablecash {

Expand Down Expand Up @@ -68,4 +72,40 @@ bool JsonArrayObject::equals(const AbstractJsonObject *other) const noexcept {
return bl;
}

int JsonArrayObject::binarySize() const {
int total = sizeof(uint8_t);

int maxLoop = this->list->size();
total += sizeof(uint16_t);

for(int i = 0; i != maxLoop; ++i){
AbstractJsonObject* obj = this->list->get(i);
total += obj->binarySize();
}

return total;
}

void JsonArrayObject::toBinary(ByteBuffer *out) const {
out->put(getType());

int maxLoop = this->list->size();
out->putShort(maxLoop);

for(int i = 0; i != maxLoop; ++i){
AbstractJsonObject* obj = this->list->get(i);
obj->toBinary(out);
}
}

void JsonArrayObject::fromBinary(ByteBuffer *in) {
int maxLoop = in->getShort();
for(int i = 0; i != maxLoop; ++i){
AbstractJsonObject* obj = AbstractJsonObject::createFromBinary(in);
BinaryUtils::checkNotNull(obj);

this->list->addElement(obj);
}
}

} /* namespace codablecash */
4 changes: 4 additions & 0 deletions src_db/json_object/JsonArrayObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class JsonArrayObject : public AbstractJsonContainer {
virtual AbstractJsonObject* copy() const noexcept;
virtual bool equals(const AbstractJsonObject* other) const noexcept;

virtual int binarySize() const;
virtual void toBinary(ByteBuffer *out) const;
virtual void fromBinary(ByteBuffer *in);

private:
ArrayList<AbstractJsonObject>* list;
};
Expand Down
Loading