Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
heropan committed Dec 9, 2021
2 parents bbc29ff + 8966746 commit 9b7fe0d
Show file tree
Hide file tree
Showing 182 changed files with 6,930 additions and 4,914 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ubuntu-and-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Ubuntu & macOS
on:
push:
pull_request:

jobs:
Build:
name: Build and Test
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- run: echo "Build branch ${{ github.ref }} on ${{ runner.os }}"
- uses: actions/checkout@v1

- name: cmake
run: |
mkdir ${{ github.workspace }}/Build/install
cd ${{ github.workspace }}/Build
cmake -DSPV_BUILD_TEST_CASES=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/Build/install ..
- name: build
run: cmake --build ${{ github.workspace }}/Build --target all -- -j 4

- name: run testcase
run: cmake --build ${{ github.workspace }}/Build --target RunTestCase -- -j 4

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
cmake_policy(VERSION 3.10)

execute_process(
COMMAND git describe --tags --no-abbrev --exclude "*-pre"
COMMAND git describe --tags --no-abbrev --exclude "*-*" --match "v[0-9]*.[0-9]*.[0-9]*"
COMMAND tr -d "v\n"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE SPVSDK_VERSION
Expand Down
2 changes: 2 additions & 0 deletions Interface/IEthSidechainSubWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef __ELASTOS_SDK_IETHSIDECHAINSUBWALLET_H__
#define __ELASTOS_SDK_IETHSIDECHAINSUBWALLET_H__

#include "ISubWallet.h"

namespace Elastos {
namespace ElaWallet {

Expand Down
147 changes: 147 additions & 0 deletions Interface/IMainchainSubWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,153 @@ namespace Elastos {
virtual nlohmann::json CreateTerminateProposalTransaction(
const nlohmann::json &payload, const std::string &memo = "") = 0;

//////////////////////////////////////////////////
/* Reserve Custom ID */
//////////////////////////////////////////////////
/**
* @param payload Reserve Custom ID payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "ReservedCustomIDList": ["...", "...", ...],
* }
* @return
*/
virtual nlohmann::json ReserveCustomIDOwnerDigest(const nlohmann::json &payload) const = 0;

/**
* @param payload Reserve Custom ID payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "ReservedCustomIDList": ["...", "...", ...],
* "Signature": "...",
* "CRCouncilMemberDID": "icwTktC5M6fzySQ5yU7bKAZ6ipP623apFY",
* }
* @return
*/
virtual nlohmann::json ReserveCustomIDCRCouncilMemberDigest(const nlohmann::json &payload) const = 0;

/**
* @param payload Reserve Custom ID payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "ReservedCustomIDList": ["...", "...", ...],
* "Signature": "...",
* "CRCouncilMemberDID": "icwTktC5M6fzySQ5yU7bKAZ6ipP623apFY",
* "CRCouncilMemberSignature": "...",
* }
* @return
*/
virtual nlohmann::json CreateReserveCustomIDTransaction(
const nlohmann::json &payload, const std::string &memo = "") = 0;

//////////////////////////////////////////////////
/* Receive Custom ID */
//////////////////////////////////////////////////
/**
* @param payload Receive Custom ID payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "ReceivedCustomIDList": ["...", "...", ...],
* "ReceiverDID": "iT42VNGXNUeqJ5yP4iGrqja6qhSEdSQmeP"
* }
* @return
*/
virtual nlohmann::json ReceiveCustomIDOwnerDigest(const nlohmann::json &payload) const = 0;

/**
* @param payload Receive Custom ID payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "ReceivedCustomIDList": ["...", "...", ...],
* "ReceiverDID": "iT42VNGXNUeqJ5yP4iGrqja6qhSEdSQmeP"
* "Signature": "...",
* "CRCouncilMemberDID": "icwTktC5M6fzySQ5yU7bKAZ6ipP623apFY",
* }
* @return
*/
virtual nlohmann::json ReceiveCustomIDCRCouncilMemberDigest(const nlohmann::json &payload) const = 0;

/**
* @param payload Receive Custom ID payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "ReceivedCustomIDList": ["...", "...", ...],
* "ReceiverDID": "iT42VNGXNUeqJ5yP4iGrqja6qhSEdSQmeP"
* "Signature": "...",
* "CRCouncilMemberDID": "icwTktC5M6fzySQ5yU7bKAZ6ipP623apFY",
* "CRCouncilMemberSignature": "...",
* }
* @return
*/
virtual nlohmann::json CreateReceiveCustomIDTransaction(
const nlohmann::json &payload, const std::string &memo = "") = 0;

//////////////////////////////////////////////////
/* Change Custom ID Fee */
//////////////////////////////////////////////////
/**
* @param payload Change custom ID fee payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "RateOfCustomIDFee": 10000,
* }
* @return
*/
virtual nlohmann::json ChangeCustomIDFeeOwnerDigest(const nlohmann::json &payload) const = 0;

/**
* @param payload Change custom ID fee payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "RateOfCustomIDFee": 10000,
* "Signature": "...",
* "CRCouncilMemberDID": "icwTktC5M6fzySQ5yU7bKAZ6ipP623apFY",
* }
* @return
*/
virtual nlohmann::json ChangeCustomIDFeeCRCouncilMemberDigest(const nlohmann::json &payload) const = 0;

/**
* @param payload Change custom ID fee payload
* {
* "CategoryData": "testdata", // limit: 4096 bytes
* "OwnerPublicKey": "...",
* "DraftHash": "...",
* "DraftData": "", // Optional, string format, limit 1 Mbytes
* "RateOfCustomIDFee": 10000,
* "Signature": "...",
* "CRCouncilMemberDID": "icwTktC5M6fzySQ5yU7bKAZ6ipP623apFY",
* "CRCouncilMemberSignature": "...",
* }
* @return
*/
virtual nlohmann::json CreateChangeCustomIDFeeTransaction(
const nlohmann::json &payload, const std::string &memo = "") = 0;

//////////////////////////////////////////////////
/* Proposal Withdraw */
//////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions Interface/ISubWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ namespace Elastos {
*/
virtual void Resync() = 0;

/**
* @param mode 0: deserialization priority. 1: speed priority
*/
virtual void SetSyncMode(int mode) = 0;

};

}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Elastos SPV C++

[![Ubuntu & macOS](https://github.com/elastos/Elastos.ELA.SPV.Cpp/actions/workflows/ubuntu-and-macos.yml/badge.svg)](https://github.com/elastos/Elastos.ELA.SPV.Cpp/actions/workflows/ubuntu-and-macos.yml)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/elastos/Elastos.ELA.SPV.Cpp/master/LICENSE)
[![GitHub Releases](https://img.shields.io/github/release/elastos/Elastos.ELA.SPV.Cpp.svg)](https://github.com/elastos/Elastos.ELA.SPV.Cpp/releases)

- [Summary](#summary)
- [Build Guide](#build-guide)
- [Build on Ubuntu/MacOS](#build-on-ubuntumacos)
Expand Down
12 changes: 5 additions & 7 deletions SDK/Common/BigInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ namespace Elastos {

void BigInt::allocate() {
this->autoclear = false;
if (!(this->bn = BN_new())) {
ErrorChecker::ThrowLogicException(Error::BigInt, "BigInt allocate error");
}
if (!(this->ctx = BN_CTX_new())) {
if (this->bn) BN_free(this->bn);
ErrorChecker::ThrowLogicException(Error::BigInt, "BigInt ctx new");
if ((this->bn = BN_new())) {
if (!(this->ctx = BN_CTX_new())) {
if (this->bn) BN_free(this->bn);
}
}
}

Expand Down Expand Up @@ -291,7 +289,7 @@ namespace Elastos {

char *hex = BN_bn2hex(this->bn);
if (!hex) {
ErrorChecker::ThrowLogicException(Error::BigInt, "BigInt bn2hex");
return bytes;
}

bytes.setHex(std::string(hex));
Expand Down
66 changes: 60 additions & 6 deletions SDK/Database/AddressUsed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,71 @@ namespace Elastos {
namespace ElaWallet {

AddressUsed::AddressUsed(Sqlite *sqlite, SqliteTransactionType type) :
SimpleTable(sqlite, type) {
TableBase(type, sqlite) {
TableBase::ExecInTransaction(_tableCreation);
}

AddressUsed::~AddressUsed() {
}

void AddressUsed::InitializeTable() {
_tableName = "UsedAddressTable";
_columnName = "Address";
_tableCreation = "CREATE TABLE IF NOT EXISTS " + _tableName + "(" + _columnName + " TEXT NOT NULL UNIQUE);";
TableBase::InitializeTable(_tableCreation);
bool AddressUsed::Puts(const std::vector<std::string> &items, bool replace) {
return DoTransaction([&items, &replace, this]() {
if (replace) {
std::string sql("DELETE FROM " + _tableName + ";");

if (!_sqlite->exec(sql, nullptr, nullptr)) {
Log::error("exec sql: {}" + sql);
return false;
}
}

for (const std::string &item : items) {
if (!this->PutInternal(item))
return false;
}

return true;
});
}

std::vector<std::string> AddressUsed::Gets() const {
std::vector<std::string> items;
std::string sql("SELECT " + _columnName + " FROM " + _tableName + ";");

if (!SqliteWrapper(sql, [&items, this](sqlite3_stmt *stmt) {
while (SQLITE_ROW == _sqlite->Step(stmt)) {
std::string item;
item = _sqlite->ColumnText(stmt, 0);
items.push_back(item);
}

return true;
})) {
return {};
}

return items;
}

bool AddressUsed::DeleteAll() {
return TableBase::DeleteAll(_tableName);
}

bool AddressUsed::PutInternal(const std::string &item) {
std::string sql("INSERT OR REPLACE INTO " + _tableName + "(" + _columnName + ") VALUES (?);");
return SqliteWrapper(sql, [&item, this](sqlite3_stmt *stmt) {
if (!_sqlite->BindText(stmt, 1, item, nullptr)) {
Log::error("bind args");
return false;
}

if (SQLITE_DONE != _sqlite->Step(stmt)) {
Log::error("step");
return false;
}

return true;
});
}

}
Expand Down
18 changes: 15 additions & 3 deletions SDK/Database/AddressUsed.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,30 @@
#ifndef __ELASTOS_SDK_ADDRESSUSED_H__
#define __ELASTOS_SDK_ADDRESSUSED_H__

#include "SimpleTable.h"
#include "TableBase.h"

namespace Elastos {
namespace ElaWallet {

class AddressUsed : public SimpleTable {
class AddressUsed : public TableBase {
public:
AddressUsed(Sqlite *sqlite, SqliteTransactionType type = IMMEDIATE);

~AddressUsed();

virtual void InitializeTable();
bool Puts(const std::vector<std::string> &items, bool replace);

std::vector<std::string> Gets() const;

bool DeleteAll();

private:
bool PutInternal(const std::string &item);

private:
const std::string _tableName = "UsedAddressTable";
const std::string _columnName = "Address";
const std::string _tableCreation = "CREATE TABLE IF NOT EXISTS " + _tableName + "(" + _columnName + " TEXT NOT NULL UNIQUE);";
};

}
Expand Down
Loading

0 comments on commit 9b7fe0d

Please sign in to comment.