Skip to content

Commit

Permalink
Merge branch 'clear_cathode_3.1RC' into testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolse committed Aug 8, 2019
2 parents e3ad1f1 + 22f2fc1 commit 5e627b9
Show file tree
Hide file tree
Showing 122 changed files with 7,933 additions and 3,428 deletions.
23 changes: 19 additions & 4 deletions 3rdparty/libbitcoin/examples/CMakeLists.txt
Expand Up @@ -5,8 +5,6 @@ add_executable(${TARGET_NAME} sign_tx.cpp)
add_dependencies(${TARGET_NAME} libbitcoin)
target_link_libraries(${TARGET_NAME} libbitcoin)

#target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/libbitcoin/include")

if(MSVC)
target_compile_options(${TARGET_NAME} PRIVATE "/wd4245")
target_compile_options(${TARGET_NAME} PRIVATE "/wd4505")
Expand All @@ -24,7 +22,6 @@ endif()
set(TARGET_NAME get_info)

add_executable(${TARGET_NAME} get_info.cpp)
#target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/libbitcoin/include")
add_dependencies(${TARGET_NAME} http libbitcoin)
target_link_libraries(${TARGET_NAME} http libbitcoin)

Expand All @@ -44,10 +41,28 @@ set(TARGET_NAME atomic_swap)

add_executable(${TARGET_NAME} atomic_swap.cpp)

#target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/libbitcoin/include")
add_dependencies(${TARGET_NAME} http libbitcoin)
target_link_libraries(${TARGET_NAME} http libbitcoin)

if(MSVC)
target_compile_options(${TARGET_NAME} PRIVATE "/wd4244")
target_compile_options(${TARGET_NAME} PRIVATE "/wd4245")
target_compile_options(${TARGET_NAME} PRIVATE "/wd4505")
target_compile_options(${TARGET_NAME} PRIVATE "/wd4996")
elseif(APPLE)
target_compile_options(${TARGET_NAME} PRIVATE -Wno-mismatched-tags)
target_compile_options(${TARGET_NAME} PRIVATE -Wno-missing-braces)
elseif(ANDROID)
target_compile_options(${TARGET_NAME} PRIVATE -Wno-tautological-constant-compare)
target_compile_options(${TARGET_NAME} PRIVATE -Wno-mismatched-tags)
else()
target_compile_options(${TARGET_NAME} PRIVATE -Wno-reorder)
endif()

set(TARGET_NAME electrum_get_balance)
add_executable(${TARGET_NAME} electrum_get_balance.cpp)
add_dependencies(${TARGET_NAME} utility libbitcoin)
target_link_libraries(${TARGET_NAME} utility libbitcoin)
if(MSVC)
target_compile_options(${TARGET_NAME} PRIVATE "/wd4244")
target_compile_options(${TARGET_NAME} PRIVATE "/wd4245")
Expand Down
121 changes: 121 additions & 0 deletions 3rdparty/libbitcoin/examples/electrum_get_balance.cpp
@@ -0,0 +1,121 @@
// Copyright 2018 The Beam Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "utility/io/reactor.h"
#include "utility/io/timer.h"
#include "utility/io/tcpstream.h"
#include "utility/config.h"
#include "utility/helpers.h"
#include "utility/logger.h"

#include "bitcoin/bitcoin.hpp"

#include <iostream>

using namespace beam;
using namespace beam::io;

namespace
{
uint64_t tag_ok = 100;
std::vector<TcpStream::Ptr> streams;

bool on_recv(ErrorCode what, void* data, size_t size) {
if (data && size) {
LOG_DEBUG() << "RECEIVED " << size << " bytes";
LOG_DEBUG() << "\n" << std::string((const char*)data, size);
}
else {
LOG_DEBUG() << __FUNCTION__ << " ERROR: " << error_str(what);
}
io::Reactor::get_Current().stop();
return true;
};

void on_connected(uint64_t tag, std::unique_ptr<TcpStream>&& newStream, ErrorCode status)
{
LOG_INFO() << "on_connected";
if (newStream) {
assert(status == EC_OK);
newStream->enable_read(on_recv);

// legacy address mkgTKdapn48BM8BaMTDSnd1miT1AZSjV7P
std::string hexPubKey = "76a91438a49a6f46ab5f3c7ab7f79e7cd142ac3b57bccf88ac";
//libbitcoin::data_chunk t(hexPubKey.begin(), hexPubKey.end());
libbitcoin::data_chunk t;
libbitcoin::decode_base16(t, hexPubKey);
libbitcoin::data_chunk secretHash = libbitcoin::sha256_hash_chunk(t);
std::string hash = libbitcoin::encode_base16(secretHash);
std::string reverseHash = "";
for (auto idx = hash.rbegin(); idx != hash.rend(); ++idx)
{
auto tmp = idx;

++idx;
if (tmp != hash.rend())
{
reverseHash += *idx;
reverseHash += *tmp;
}
}

LOG_INFO() << reverseHash;
std::string request = R"({"method":"blockchain.scripthash.get_balance","params":[")" + reverseHash +R"("], "id": "teste"})";
request += "\n";

LOG_INFO() << request;
Result res = newStream->write(request.data(), request.size());
if (!res) {
LOG_ERROR() << error_str(res.error());
}

LOG_INFO() << "after write";
streams.emplace_back(move(newStream));
}
else {
LOG_DEBUG() << __FUNCTION__ << " ERROR: " << error_str(status);
io::Reactor::get_Current().stop();
}
}
}

int main() {
int logLevel = LOG_LEVEL_DEBUG;
#if LOG_VERBOSE_ENABLED
logLevel = LOG_LEVEL_VERBOSE;
#endif
auto logger = Logger::create(logLevel, logLevel);

try {
io::Reactor::Ptr reactor = io::Reactor::create();
io::Reactor::Scope scope(*reactor);

Address address;
/*address.resolve("testnet.hsmiths.com");
address.port(53012);*/

/*address.resolve("testnet.qtornado.com");
address.port(51002);*/
address.resolve("testnet1.bauerj.eu");
address.port(50002);

reactor->tcp_connect(address, tag_ok, on_connected, 2000, true);
reactor->run();
}
catch (const std::exception& e) {
LOG_ERROR() << e.what();
}

return 0;
}
6 changes: 3 additions & 3 deletions CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0074 NEW)

set(VERSION_MAJOR 3)
set(VERSION_MINOR 0)
set(VERSION_MINOR 1)
set(VERSION_REVISION 0)
set(GIT_COMMIT_HASH "unknown")

Expand Down Expand Up @@ -98,8 +98,8 @@ enable_testing()

function(add_test_snippet EXE_NAME LIB_NAME)
add_executable(${EXE_NAME} ${EXE_NAME}.cpp)
add_dependencies(${EXE_NAME} ${LIB_NAME})
target_link_libraries(${EXE_NAME} ${LIB_NAME})
add_dependencies(${EXE_NAME} ${LIB_NAME} ${ARGN})
target_link_libraries(${EXE_NAME} ${LIB_NAME} ${ARGN})
add_test(NAME ${EXE_NAME} COMMAND $<TARGET_FILE:${EXE_NAME}>)
endfunction()

Expand Down
19 changes: 19 additions & 0 deletions SECURITY.md
@@ -0,0 +1,19 @@
# Security Policy

## Supported Versions

See our Github releases page for versions of Beam that are currently supported: https://github.com/BeamMW/beam/releases

## Reporting a Vulnerability

To report security issues send an email to security@beam.mw (not for support).

The following keys may be used to communicate sensitive information to developers:

| Name | Fingerprint |
|------|-------------|
| BeamMW | A6C6 2C9F 5593 1860 AFF8 3BBB 997E AB9F 3DF7 F375 |
| Alex Romanov | 4180 5296 741F F4C3 ADEC 3DF5 17B7 D9D7 A8FA C483 |


You can import a key by running the following command with that individual’s fingerprint: `gpg --recv-keys "<fingerprint>"` Ensure that you put quotes around fingerprints containing spaces.
6 changes: 5 additions & 1 deletion android/com/mw/beam/beamwallet/core/entities/Wallet.java
Expand Up @@ -31,7 +31,7 @@ public class Wallet
public native void getAddresses(boolean own);
public native void generateNewAddress();
public native void saveAddress(WalletAddressDTO address, boolean own);
public native void saveAddressChanges(String addr, String name, boolean isNever, boolean makeActive, boolean makeExpired);
public native void updateAddress(String addr, String name, int addressExpirationEnum);
public native void cancelTx(String id);
public native void deleteTx(String id);
public native void deleteAddress(String walletID);
Expand All @@ -42,6 +42,10 @@ public class Wallet
public native void getCoinsByTx(String txID);
public native void changeNodeAddress(String address);
public native String exportOwnerKey(String pass);
public native void importRecovery(String path);

// deprecated
public native void saveAddressChanges(String addr, String name, boolean isNever, boolean makeActive, boolean makeExpired);

// not implemented
public native void changeCurrentWalletIDs(); //const beam::WalletID& senderID, const beam::WalletID& receiverID);
Expand Down
Expand Up @@ -24,4 +24,11 @@ public class WalletAddressDTO
public long createTime;
public long duration;
public long own;

public enum WalletAddressExpirationStatus
{
Expired,
OneDay,
Never
}
}
15 changes: 15 additions & 0 deletions android/com/mw/beam/beamwallet/core/listeners/WalletListener.java
Expand Up @@ -170,6 +170,16 @@ static void onStoppedNode()
System.out.println(">>>>>>>>>>>>>> async onStoppedNode() in Java");
}

static void onNodeCreated()
{
System.out.println(">>>>>>>>>>>>>> async onNodeCreated() in Java");
}

static void onNodeDestroyed()
{
System.out.println(">>>>>>>>>>>>>> async onNodeDestroyed() in Java");
}

static void onFailedToStartNode()
{
System.out.println(">>>>>>>>>>>>>> async onFailedToStartNode() in Java");
Expand All @@ -184,4 +194,9 @@ static void onNodeThreadFinished()
{
System.out.println(">>>>>>>>>>> onNodeThreadFinished called");
}

static void onImportRecoveryProgress(long done, long total)
{
System.out.println(">>>>>>>>>>>>>> async onImportRecoveryProgress in Java [ " + done + " / " + total + " ]");
}
}
61 changes: 58 additions & 3 deletions android/jni.cpp
Expand Up @@ -143,8 +143,8 @@ JNIEXPORT jobject JNICALL BEAM_JAVA_API_INTERFACE(createWallet)(JNIEnv *env, job
}

// generate default address
WalletAddress address = storage::createAddress(*walletDB);
address.m_label = "default";
WalletAddress address = storage::createAddress(*walletDB);
address.m_label = "default";
walletDB->saveAddress(address);

if (restore)
Expand Down Expand Up @@ -377,6 +377,48 @@ JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(saveAddress)(JNIEnv *env, jobj
walletModel->getAsync()->saveAddress(addr, own);
}

JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(importRecovery)(JNIEnv *env, jobject thiz, jstring jpath)
{
auto path = JString(env, jpath).value();

LOG_DEBUG() << "importRecovery path = " << path;

walletModel->getAsync()->importRecovery(path);
}

JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(updateAddress)(JNIEnv *env, jobject thiz,
jstring addr, jstring name, jint addressExpirationEnum)
{
WalletID walletID(Zero);

if (!walletID.FromHex(JString(env, addr).value()))
{
LOG_ERROR() << "Address is not valid!!!";

return;
}

WalletAddress::ExpirationStatus expirationStatus;
switch (addressExpirationEnum)
{
case 0:
expirationStatus = WalletAddress::ExpirationStatus::Expired;
break;
case 1:
expirationStatus = WalletAddress::ExpirationStatus::OneDay;
break;
case 2:
expirationStatus = WalletAddress::ExpirationStatus::Never;
break;

default:
LOG_ERROR() << "Address expiration is not valid!!!";
return;
}

walletModel->getAsync()->updateAddress(walletID, JString(env, name).value(), expirationStatus);
}

JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(saveAddressChanges)(JNIEnv *env, jobject thiz,
jstring addr, jstring name, jboolean isNever, jboolean makeActive, jboolean makeExpired)
{
Expand All @@ -385,10 +427,23 @@ JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(saveAddressChanges)(JNIEnv *en
if (!walletID.FromHex(JString(env, addr).value()))
{
LOG_ERROR() << "Address is not valid!!!";
return;
}

WalletAddress::ExpirationStatus expirationStatus;
if (isNever)
expirationStatus = WalletAddress::ExpirationStatus::Never;
else if (makeActive)
expirationStatus = WalletAddress::ExpirationStatus::OneDay;
else if (makeExpired)
expirationStatus = WalletAddress::ExpirationStatus::Expired;
else
{
LOG_ERROR() << "Address expiration is not valid!!!";
return;
}
walletModel->getAsync()->saveAddressChanges(walletID, JString(env, name).value(), isNever, makeActive, makeExpired);

walletModel->getAsync()->updateAddress(walletID, JString(env, name).value(), expirationStatus);
}

// don't use it. i don't check it
Expand Down
18 changes: 18 additions & 0 deletions android/node_model.cpp
Expand Up @@ -89,6 +89,24 @@ void NodeModel::onStoppedNode()
env->CallStaticVoidMethod(WalletListenerClass, callback);
}

void NodeModel::onNodeCreated()
{
JNIEnv* env = Android_JNI_getEnv();

jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onNodeCreated", "()V");

env->CallStaticVoidMethod(WalletListenerClass, callback);
}

void NodeModel::onNodeDestroyed()
{
JNIEnv* env = Android_JNI_getEnv();

jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onNodeDestroyed", "()V");

env->CallStaticVoidMethod(WalletListenerClass, callback);
}

// void NodeModel::onFailedToStartNode()
// {
// JNIEnv* env = Android_JNI_getEnv();
Expand Down
2 changes: 2 additions & 0 deletions android/node_model.h
Expand Up @@ -38,6 +38,8 @@ class NodeModel

protected:
void onSyncProgressUpdated(int done, int total) override;
void onNodeCreated() override;
void onNodeDestroyed() override;
void onStartedNode() override;
void onStoppedNode() override;
// void onFailedToStartNode() override;
Expand Down

0 comments on commit 5e627b9

Please sign in to comment.