Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release_v0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
heropan committed May 24, 2019
2 parents 8a02f6c + b2bdbf9 commit 4aa2c26
Show file tree
Hide file tree
Showing 59 changed files with 699 additions and 314 deletions.
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Define helper macro option_with_default
macro(option_with_default OPTION_NAME OPTION_STRING OPTION_DEFAULT)
if(NOT DEFINED ${OPTION_NAME})
set(${OPTION_NAME} ${OPTION_DEFAULT})
endif(NOT DEFINED ${OPTION_NAME})
option(${OPTION_NAME} "${OPTION_STRING}" ${${OPTION_NAME}})
endmacro(option_with_default OPTION_NAME OPTION_STRING OPTION_DEFAULT)

set(SPV_PLATFORM_ANDROID "Android" CACHE INTERNAL "SPV platform" FORCE)
set(SPV_PLATFORM_IOS "IOS" CACHE INTERNAL "SPV platform" FORCE)

Expand Down Expand Up @@ -106,12 +98,10 @@ if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr/local/" CACHE PATH "Install prefix prepended to target to create install location")
endif(NOT DEFINED CMAKE_INSTALL_PREFIX)

option_with_default(SPVSDK_DEBUG "SPV debug" OFF)
option_with_default(SPV_BUILD_TEST_CASES "Build test cases" OFF)
option_with_default(SPV_BUILD_SAMPLE "Build sample" OFF)
option_with_default(CMAKE_EXPORT_COMPILE_COMMANDS "Export to compile_commands.json" OFF)

option_with_default(SPV_EXTRA_WARNINGS "Enable Maximum Warnings Level" OFF)
option(SPVSDK_DEBUG "SPV debug" OFF)
option(SPV_BUILD_TEST_CASES "Build test cases" OFF)
option(SPV_BUILD_SAMPLE "Build sample" OFF)
option(SPV_EXTRA_WARNINGS "Enable Maximum Warnings Level" OFF)

set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_RELEASE NDEBUG)
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_MINSIZEREL NDEBUG)
Expand Down
9 changes: 0 additions & 9 deletions Data/CoinConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,5 @@
"ReconnectSeconds": 300,
"PluginType": "SideStandard",
"GenesisAddress" : "XKUh4GLhFJiqAMTF6HyWQrV9pK9HcGUdfJ"
},
"TokenChain": {
"Type": "Tokenchain",
"CoinIndex": 2,
"NetType": "MainNet",
"MinFee": 10000,
"ReconnectSeconds": 300,
"PluginType": "Token",
"GenesisAddress" : ""
}
}
2 changes: 1 addition & 1 deletion Interface/IIdAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <string>

#include <nlohmann/json.hpp>
#include "nlohmann/json.hpp"

namespace Elastos {
namespace ElaWallet {
Expand Down
2 changes: 1 addition & 1 deletion Interface/ISubWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <string>

#include <nlohmann/json.hpp>
#include "nlohmann/json.hpp"

#include "ISubWalletCallback.h"

Expand Down
5 changes: 3 additions & 2 deletions Interface/ISubWalletCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <string>

#include <nlohmann/json.hpp>
#include "nlohmann/json.hpp"

namespace Elastos {
namespace ElaWallet {
Expand Down Expand Up @@ -38,8 +38,9 @@ namespace Elastos {
* Callback method fired when best block chain height increased. This callback could be used to show progress.
* @param currentBlockHeight is the of current block when callback fired.
* @param estimatedHeight is max height of blockchain.
* @param lastBlockTime timestamp of the last block.
*/
virtual void OnBlockSyncProgress(uint32_t currentBlockHeight, uint32_t estimatedHeight) = 0;
virtual void OnBlockSyncProgress(uint32_t currentBlockHeight, uint32_t estimatedHeight, time_t lastBlockTime) = 0;

/**
* Callback method fired when block end synchronizing with a peer. This callback could be used to show progress.
Expand Down
2 changes: 1 addition & 1 deletion Platforms/iOS/CMake/Toolchains/iOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)

# Set the find root to the iOS developer roots and to user defined paths.
set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT}
${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root" FORCE)
${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root" FORCE)

# Default to searching for frameworks first.
set(CMAKE_FIND_FRAMEWORK FIRST)
Expand Down
45 changes: 39 additions & 6 deletions SDK/Account/HDSubAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ namespace Elastos {



HDSubAccount::HDSubAccount(const HDKeychain &masterPubKey, const bytes_t &votePubKey,
HDSubAccount::HDSubAccount(const HDKeychain &masterPubKey, const bytes_t &ownerPubKey,
IAccount *account, uint32_t coinIndex) :
SubAccountBase(account) {
_coinIndex = coinIndex;
_masterPubKey = masterPubKey;
_votePublicKey = votePubKey;
if (votePubKey.size() > 0)
_depositAddress = Address(PrefixDeposit, votePubKey);
_ownerPublicKey = ownerPubKey;
if (ownerPubKey.size() > 0) {
_depositAddress = Address(PrefixDeposit, ownerPubKey);
_ownerAddress = Address(PrefixStandard, ownerPubKey);
}
}

void HDSubAccount::InitAccount(const std::vector<TransactionPtr> &transactions, Lockable *lock) {
Expand All @@ -44,10 +46,15 @@ namespace Elastos {
bytes_t pubKey;

if (IsDepositAddress(addr)) {
pubKey = GetVotePublicKey();
pubKey = GetOwnerPublicKey();
return Address(PrefixDeposit, pubKey).RedeemScript();
}

if (IsOwnerAddress(addr)) {
pubKey = GetOwnerPublicKey();
return Address(PrefixStandard, pubKey).RedeemScript();
}

for (index = internalChain.size(); index > 0; index--) {
if (internalChain[index - 1] == addr) {
pubKey = _masterPubKey.getChild(SEQUENCE_INTERNAL_CHAIN).getChild(index - 1).pubkey();
Expand Down Expand Up @@ -210,20 +217,46 @@ namespace Elastos {
return true;
}

if (IsOwnerAddress(address)) {
return true;
}

return allAddrs.find(address) != allAddrs.end();
}

void HDSubAccount::ClearUsedAddresses() {
usedAddrs.clear();
}

Key HDSubAccount::DeriveVoteKey(const std::string &payPasswd) {
Key HDSubAccount::DeriveOwnerKey(const std::string &payPasswd) {
HDSeed hdseed(_parentAccount->DeriveSeed(payPasswd).bytes());
HDKeychain rootKey(hdseed.getExtendedKey(true));

// 44'/coinIndex'/account'/change/index
return rootKey.getChild("44'/0'/1'/0/0");
}

size_t HDSubAccount::TxInternalChainIndex(const TransactionPtr &tx) const {
for (size_t i = internalChain.size(); i > 0; --i) {
for (size_t o = 0; o < tx->GetOutputs().size(); o++) {
if (internalChain[i] == tx->GetOutputs()[o].GetAddress())
return i - 1;
}
}

return -1;
}

size_t HDSubAccount::TxExternalChainIndex(const TransactionPtr &tx) const {
for (size_t i = externalChain.size(); i > 0; --i) {
for (size_t o = 0; o < tx->GetOutputs().size(); ++o) {
if (externalChain[i] == tx->GetOutputs()[o].GetAddress())
return i - 1;
}
}

return -1;
}

}
}
8 changes: 6 additions & 2 deletions SDK/Account/HDSubAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Elastos {

class HDSubAccount : public SubAccountBase {
public:
HDSubAccount(const HDKeychain &masterPubKey, const bytes_t &votePubKey,
HDSubAccount(const HDKeychain &masterPubKey, const bytes_t &ownerPubKey,
IAccount *account, uint32_t coinIndex);

virtual nlohmann::json GetBasicInfo() const;
Expand All @@ -39,7 +39,11 @@ namespace Elastos {

virtual void ClearUsedAddresses();

virtual Key DeriveVoteKey(const std::string &payPasswd);
virtual Key DeriveOwnerKey(const std::string &payPasswd);

virtual size_t TxInternalChainIndex(const TransactionPtr &tx) const;

virtual size_t TxExternalChainIndex(const TransactionPtr &tx) const;

private:
HDKeychain _masterPubKey;
Expand Down
10 changes: 8 additions & 2 deletions SDK/Account/ISubAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ namespace Elastos {

virtual bool IsDepositAddress(const Address &address) const = 0;

virtual bool IsOwnerAddress(const Address &address) const = 0;

virtual bool IsAddressUsed(const Address &address) const = 0;

virtual void ClearUsedAddresses() = 0;

virtual Key DeriveVoteKey(const std::string &payPasswd) = 0;
virtual Key DeriveOwnerKey(const std::string &payPasswd) = 0;

virtual bytes_t GetOwnerPublicKey() const = 0;

virtual size_t TxInternalChainIndex(const TransactionPtr &tx) const = 0;

virtual bytes_t GetVotePublicKey() const = 0;
virtual size_t TxExternalChainIndex(const TransactionPtr &tx) const = 0;

};

Expand Down
2 changes: 1 addition & 1 deletion SDK/Account/MultiSignAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace Elastos {
std::string innerType;
if (_me != nullptr) {
nlohmann::json basicInfo = _me->GetBasicInfo();
innerType = basicInfo["Type"];
innerType = basicInfo["Type"].get<std::string>();
signers.push_back(_me->GetMultiSignPublicKey().getHex());
} else {
innerType = "Readonly";
Expand Down
21 changes: 19 additions & 2 deletions SDK/Account/MultiSignSubAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,31 @@ namespace Elastos {
return j;
}

bytes_t MultiSignSubAccount::GetVotePublicKey() const {
bytes_t MultiSignSubAccount::GetOwnerPublicKey() const {
return bytes_t();
}

Key MultiSignSubAccount::DeriveVoteKey(const std::string &payPasswd) {
Key MultiSignSubAccount::DeriveOwnerKey(const std::string &payPasswd) {
ErrorChecker::ThrowLogicException(Error::AccountNotSupportVote, "This account do not support vote");
return Key();
}

size_t MultiSignSubAccount::TxInternalChainIndex(const TransactionPtr &tx) const {
for (size_t i = 0; i < tx->GetOutputs().size(); ++i) {
if (_parentAccount->GetAddress() == tx->GetOutputs()[i].GetAddress())
return 0;
}

return -1;
}

size_t MultiSignSubAccount::TxExternalChainIndex(const TransactionPtr &tx) const {
for (size_t i = 0; i < tx->GetOutputs().size(); ++i) {
if (_parentAccount->GetAddress() == tx->GetOutputs()[i].GetAddress())
return 0;
}

return -1;
}
}
}
8 changes: 6 additions & 2 deletions SDK/Account/MultiSignSubAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ namespace Elastos {

virtual bool FindKey(Key &key, const bytes_t &pubKey, const std::string &payPasswd);

virtual bytes_t GetVotePublicKey() const;
virtual bytes_t GetOwnerPublicKey() const;

virtual Key DeriveVoteKey(const std::string &payPasswd);
virtual Key DeriveOwnerKey(const std::string &payPasswd);

virtual size_t TxInternalChainIndex(const TransactionPtr &tx) const;

virtual size_t TxExternalChainIndex(const TransactionPtr &tx) const;

private:
MultiSignAccount *_multiSignAccount;
Expand Down
2 changes: 1 addition & 1 deletion SDK/Account/SingleSubAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace Elastos {
return address == GetParent()->GetAddress();
}

Key SingleSubAccount::DeriveVoteKey(const std::string &payPasswd) {
Key SingleSubAccount::DeriveOwnerKey(const std::string &payPasswd) {
ErrorChecker::ThrowLogicException(Error::AccountNotSupportVote, "This account do not support vote");
return Key();
}
Expand Down
2 changes: 1 addition & 1 deletion SDK/Account/SingleSubAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Elastos {

virtual bool IsAddressUsed(const Address &address) const;

virtual Key DeriveVoteKey(const std::string &payPasswd);
virtual Key DeriveOwnerKey(const std::string &payPasswd);

};

Expand Down
34 changes: 28 additions & 6 deletions SDK/Account/StandardSingleSubAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ namespace Elastos {
namespace ElaWallet {

StandardSingleSubAccount::StandardSingleSubAccount(const HDKeychain &masterPubKey,
const bytes_t &votePubKey,
const bytes_t &ownerPubKey,
IAccount *account,
uint32_t coinIndex) :
SingleSubAccount(account) {
_masterPubKey = masterPubKey;
_coinIndex = coinIndex;
_votePublicKey = votePubKey;
if (votePubKey.size() > 0)
_depositAddress = Address(PrefixDeposit, votePubKey);
_ownerPublicKey = ownerPubKey;
if (ownerPubKey.size() > 0) {
_depositAddress = Address(PrefixDeposit, ownerPubKey);
_ownerAddress = Address(PrefixStandard, ownerPubKey);
}

_address = Address(PrefixStandard, _masterPubKey.getChild("0/0").pubkey());
}
Expand All @@ -33,7 +35,7 @@ namespace Elastos {
Key key;

if (IsDepositAddress(addr)) {
pubKey = GetVotePublicKey();
pubKey = GetOwnerPublicKey();
return Address(PrefixDeposit, pubKey).RedeemScript();
}

Expand Down Expand Up @@ -74,15 +76,35 @@ namespace Elastos {
if (IsDepositAddress(address))
return true;

if (IsOwnerAddress(address))
return true;

return address == _address;
}

Key StandardSingleSubAccount::DeriveVoteKey(const std::string &payPasswd) {
Key StandardSingleSubAccount::DeriveOwnerKey(const std::string &payPasswd) {
HDSeed hdseed(_parentAccount->DeriveSeed(payPasswd).bytes());
HDKeychain rootKey(hdseed.getExtendedKey(true));
// account is 1
return rootKey.getChild("44'/0'/1'/0/0");
}

size_t StandardSingleSubAccount::TxInternalChainIndex(const TransactionPtr &tx) const {
for (size_t i = 0; i < tx->GetOutputs().size(); ++i) {
if (tx->GetOutputs()[i].GetAddress() == _address)
return 0;
}

return -1;
}

size_t StandardSingleSubAccount::TxExternalChainIndex(const TransactionPtr &tx) const {
for (size_t i = 0; i < tx->GetOutputs().size(); ++i) {
if (tx->GetOutputs()[i].GetAddress() == _address)
return 0;
}

return -1;
}
}
}
8 changes: 6 additions & 2 deletions SDK/Account/StandardSingleSubAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Elastos {

class StandardSingleSubAccount : public SingleSubAccount {
public:
StandardSingleSubAccount(const HDKeychain &masterPubKey, const bytes_t &votePubKey,
StandardSingleSubAccount(const HDKeychain &masterPubKey, const bytes_t &ownerPubKey,
IAccount *account, uint32_t coinIndex);

virtual bytes_t GetRedeemScript(const Address &addr) const;
Expand All @@ -25,7 +25,11 @@ namespace Elastos {

virtual bool ContainsAddress(const Address &address) const;

virtual Key DeriveVoteKey(const std::string &payPasswd);
virtual Key DeriveOwnerKey(const std::string &payPasswd);

virtual size_t TxInternalChainIndex(const TransactionPtr &tx) const;

virtual size_t TxExternalChainIndex(const TransactionPtr &tx) const;

private:
Address _address;
Expand Down
Loading

0 comments on commit 4aa2c26

Please sign in to comment.