Convert monero-cpp to wownero-cpp, make it compat. with wownero-ng

This commit is contained in:
dsc
2024-03-30 09:31:15 +02:00
parent 1e74300d12
commit 2277be574f
38 changed files with 1696 additions and 2555 deletions
-25
View File
@@ -1,25 +0,0 @@
name: Comment to label
on:
issues:
types: [labeled]
workflow_call:
jobs:
issueLabeled:
runs-on: ubuntu-latest
steps:
- name: Bounty explanation
uses: peter-evans/create-or-update-comment@v2
if: github.event.label.name == '💰bounty'
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: >
There is a bounty on this issue. The amount is in the title. The reward will be awarded to the first person or group of people who resolve this issue.
If you are starting to work on this bounty, please write a comment so that we can assign the issue to you. We expect contributors to provide a PR in a reasonable timeframe or, in case of an extensive work, updates on their progress. We will unassign the issue if we feel the assignee is not responsive or has abandoned the task.
Read the [full conditions and details](https://github.com/woodser/monero-cpp/blob/master/docs/bounties.md) of the bounty system.
-3
View File
@@ -1,3 +0,0 @@
[submodule "external/monero-project"]
path = external/monero-project
url = https://github.com/woodser/monero
-11
View File
@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>monero-cpp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
+27 -501
View File
@@ -1,510 +1,36 @@
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake") cmake_minimum_required(VERSION 3.25)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")
cmake_minimum_required(VERSION 3.4.1) project(wownero_cpp VERSION "1.0.0")
set(CMAKE_CXX_STANDARD 17)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
if (WIN32) set(STATIC OFF)
add_definitions( "-D_GLIBCXX_USE_NANOSLEEP=1" ) # "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_definitions( "-DWIN32_LEAN_AND_MEAN" ) set(THREADS_PREFER_PTHREAD_FLAG ON)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -O2 -fPIC -std=c++14 -F/Library/Frameworks -pthread -lcrypto -lcrypt32")
else() # debug
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -F/Library/Frameworks -pthread") set(_CMAKE_BUILD_TYPE "")
string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE)
if("${_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
set(DEBUG ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(Boost_DEBUG ON)
endif() endif()
#SET(CMAKE_C_COMPILER /path/to/c/compiler) find_package(Git)
#SET(CMAKE_CXX_COMPILER /path/to/cpp/compiler) find_package(Wownero REQUIRED)
#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") include(FindCcache)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -F/Library/Frameworks -pthread -fsanitize=address") # TODO: way to enable sanitize? get runtime error with this on
project(MoneroCppLibrary) if(STATIC)
set(COMMON_EXE_LINKER_FLAGS "${COMMON_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
set(BUILD_LIBRARY ON)
set(BUILD_SAMPLE OFF)
set(BUILD_SCRATCHPAD OFF)
set(BUILD_TESTS OFF)
###################
# monero-project
###################
set(MONERO_PROJECT "${CMAKE_SOURCE_DIR}/external/monero-project" CACHE STRING "Monero project source directory")
set(MONERO_PROJECT_SRC "${MONERO_PROJECT}/src")
# header includes
include_directories(src/)
include_directories("${MONERO_PROJECT}/contrib/epee/include")
include_directories("${MONERO_PROJECT}/external/")
include_directories("${MONERO_PROJECT}/external/easylogging++")
include_directories("${MONERO_PROJECT}/external/rapidjson/include")
include_directories("${MONERO_PROJECT_SRC}/")
include_directories("${MONERO_PROJECT_SRC}/wallet")
include_directories("${MONERO_PROJECT_SRC}/wallet/api")
include_directories("${MONERO_PROJECT_SRC}/hardforks")
include_directories("${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/")
set(EXTERNAL_LIBS_DIR ${CMAKE_SOURCE_DIR}/external-libs)
message(STATUS EXTERNAL_LIBS_DIR : ${EXTERNAL_LIBS_DIR})
####################
# Extra libraries
####################
if (APPLE)
if (DEPENDS)
list(APPEND EXTRA_LIBRARIES "-framework Foundation -framework IOKit -framework AppKit")
else()
find_library(COREFOUNDATION CoreFoundation)
find_library(IOKIT IOKit)
find_library(APPKIT AppKit)
list(APPEND EXTRA_LIBRARIES ${IOKIT})
list(APPEND EXTRA_LIBRARIES ${COREFOUNDATION})
list(APPEND EXTRA_LIBRARIES ${APPKIT})
endif()
endif()
if (WIN32)
list(APPEND EXTRA_LIBRARIES setupapi)
endif() endif()
message(STATUS EXTRA_LIBRARIES: ${EXTRA_LIBRARIES}) # Install hook on throw for dumping stack on exception (implemented in libcommon)
set(WRAP_CXA_THROW_FLAG "-Wl,--wrap=__cxa_throw")
############ add_subdirectory(src)
# Protobuf
############
if (NOT APPLE) add_executable(test main.cpp)
include(FindProtobuf) target_link_libraries(test PUBLIC wownero_cpp)
find_package(Protobuf)
message(STATUS "Protobuf lib: ${Protobuf_LIBRARY}, inc: ${Protobuf_INCLUDE_DIR}, protoc: ${Protobuf_PROTOC_EXECUTABLE}")
include_directories(${Protobuf_INCLUDE_DIR})
endif()
############
# LibUSB
############
find_library(usb_LIBRARY NAMES usb-1.0 libusb usb)
set(LibUSB_LIBRARIES ${usb_LIBRARY})
############
# Boost
############
set(Boost_NO_BOOST_CMAKE 1)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS chrono date_time filesystem program_options regex serialization wserialization system thread)
message(STATUS "Using Boost include dir at ${Boost_INCLUDE_DIR}")
include_directories(${Boost_INCLUDE_DIR})
############
# OpenSSL
############
if (APPLE AND NOT IOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -std=c++14")
if (NOT OPENSSL_ROOT_DIR)
EXECUTE_PROCESS(COMMAND brew --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Using OpenSSL found at ${OPENSSL_ROOT_DIR}")
endif()
endif()
find_package(OpenSSL REQUIRED)
message(STATUS "Using OpenSSL include dir at ${OPENSSL_INCLUDE_DIR}")
include_directories(${OPENSSL_INCLUDE_DIR})
if(STATIC AND NOT IOS)
if(UNIX)
set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${CMAKE_DL_LIBS};${CMAKE_THREAD_LIBS_INIT}")
endif()
endif()
if (WIN32)
list(APPEND OPENSSL_LIBRARIES ws2_32 crypt32)
endif()
############
# libsodium
############
include_directories(external/libsodium/include/sodium)
find_library(SODIUM_LIBRARY sodium REQUIRED)
message(STATUS "Using libsodium library at ${SODIUM_LIBRARY}")
############
# HIDAPI
############
if(APPLE)
include_directories(SYSTEM /usr/include/malloc)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
endif()
find_package(HIDAPI REQUIRED)
message(STATUS "Using HIDAPI include dir at ${HIDAPI_INCLUDE_DIR}")
add_definitions(-DHAVE_HIDAPI)
include_directories(${HIDAPI_INCLUDE_DIR})
#############
# Monero
#############
set(MONERO_PROJECT_BUILD "${MONERO_PROJECT}/build/release" CACHE STRING "Monero project build directory")
message(STATUS "Using monero-project build: " ${MONERO_PROJECT_BUILD})
list(APPEND CMAKE_MODULE_PATH "${MONERO_PROJECT}/cmake")
add_library(wallet STATIC IMPORTED)
set_target_properties(wallet PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/lib/libwallet.a)
# libwallet-crypto.a provides x86_64 asm for some wallet functions
if (EXISTS ${MONERO_PROJECT_BUILD}/src/crypto/wallet/libwallet-crypto.a)
add_library(wallet_crypto_lib STATIC IMPORTED)
set_target_properties(wallet_crypto_lib PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/crypto/wallet/libwallet-crypto.a)
set(wallet_crypto wallet_crypto_lib)
endif()
add_library(lmdb STATIC IMPORTED)
set_target_properties(lmdb PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/external/db_drivers/liblmdb/liblmdb.a)
add_library(epee STATIC IMPORTED)
set_target_properties(epee PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/contrib/epee/src/libepee.a)
############
# Unbound
############
find_package(Unbound)
if(NOT UNBOUND_INCLUDE_DIR)
message(FATAL_ERROR "Could not find libunbound")
else()
message(STATUS "Found libunbound include (unbound.h) in ${UNBOUND_INCLUDE_DIR}")
if(UNBOUND_LIBRARIES)
message(STATUS "Found libunbound library")
include_directories(${UNBOUND_INCLUDE_DIR})
if (WIN32)
add_library(unbound STATIC IMPORTED)
else()
add_library(unbound SHARED IMPORTED)
endif()
set_target_properties(unbound PROPERTIES IMPORTED_LOCATION ${UNBOUND_LIBRARIES})
else()
message(FATAL_ERROR "Found libunbound includes, but could not find libunbound library. Please make sure you have installed libunbound or libunbound-dev or the equivalent")
endif()
endif()
add_library(rpc_base STATIC IMPORTED)
set_target_properties(rpc_base PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/rpc/librpc_base.a)
add_library(net STATIC IMPORTED)
set_target_properties(net PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/net/libnet.a)
add_library(hardforks STATIC IMPORTED)
set_target_properties(hardforks PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/hardforks/libhardforks.a)
add_library(easylogging STATIC IMPORTED)
set_target_properties(easylogging PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/external/easylogging++/libeasylogging.a)
add_library(cryptonote_core STATIC IMPORTED)
set_target_properties(cryptonote_core PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/cryptonote_core/libcryptonote_core.a)
add_library(cryptonote_protocol STATIC IMPORTED)
set_target_properties(cryptonote_protocol PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/cryptonote_protocol/libcryptonote_protocol.a)
add_library(cryptonote_basic STATIC IMPORTED)
set_target_properties(cryptonote_basic PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_basic.a)
add_library(cryptonote_format_utils_basic STATIC IMPORTED)
set_target_properties(cryptonote_format_utils_basic PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_format_utils_basic.a)
add_library(mnemonics STATIC IMPORTED)
set_target_properties(mnemonics PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/mnemonics/libmnemonics.a)
add_library(common STATIC IMPORTED)
set_target_properties(common PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/common/libcommon.a)
add_library(cncrypto STATIC IMPORTED)
set_target_properties(cncrypto PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/crypto/libcncrypto.a)
add_library(ringct STATIC IMPORTED)
set_target_properties(ringct PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/ringct/libringct.a)
add_library(ringct_basic STATIC IMPORTED)
set_target_properties(ringct_basic PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/ringct/libringct_basic.a)
add_library(blockchain_db STATIC IMPORTED)
set_target_properties(blockchain_db PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/blockchain_db/libblockchain_db.a)
add_library(blocks STATIC IMPORTED)
set_target_properties(blocks PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/blocks/libblocks.a)
add_library(checkpoints STATIC IMPORTED)
set_target_properties(checkpoints PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/checkpoints/libcheckpoints.a)
add_library(device STATIC IMPORTED)
set_target_properties(device PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/device/libdevice.a)
add_library(device_trezor STATIC IMPORTED)
set_target_properties(device_trezor PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/device_trezor/libdevice_trezor.a)
add_library(multisig STATIC IMPORTED)
set_target_properties(multisig PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/multisig/libmultisig.a)
add_library(version STATIC IMPORTED)
set_target_properties(version PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/src/libversion.a)
add_library(randomx STATIC IMPORTED)
set_target_properties(randomx PROPERTIES IMPORTED_LOCATION
${MONERO_PROJECT_BUILD}/external/randomx/librandomx.a)
########################
# Build c++ library
########################
set(
LIBRARY_SRC_FILES
src/utils/gen_utils.cpp
src/utils/monero_utils.cpp
src/daemon/monero_daemon_model.cpp
src/daemon/monero_daemon.cpp
src/wallet/monero_wallet_model.cpp
src/wallet/monero_wallet_keys.cpp
src/wallet/monero_wallet_full.cpp
)
if (BUILD_LIBRARY)
add_library(monero-cpp SHARED ${LIBRARY_SRC_FILES})
target_link_libraries(monero-cpp
wallet
rpc_base
net
lmdb
unbound
easylogging
cryptonote_core
cryptonote_protocol
cryptonote_basic
cryptonote_format_utils_basic
mnemonics
ringct
ringct_basic
common
cncrypto
blockchain_db
blocks
checkpoints
device
device_trezor
multisig
version
randomx
epee
hardforks
${wallet_crypto}
${UNBOUND_LIBRARIES}
${Boost_LIBRARIES}
${Protobuf_LIBRARY}
${LibUSB_LIBRARIES}
${OPENSSL_LIBRARIES}
${SODIUM_LIBRARY}
${HIDAPI_LIBRARIES}
${EXTRA_LIBRARIES}
)
if (WIN32)
target_link_options(monero-cpp PUBLIC "-Wl,--enable-auto-import,--export-all-symbols")
endif()
INSTALL(FILES src/daemon/monero_daemon.h
src/daemon/monero_daemon_model.h
DESTINATION include/daemon)
INSTALL(FILES src/utils/gen_utils.h
src/utils/monero_utils.h
DESTINATION include/utils)
INSTALL(FILES src/wallet/monero_wallet_full.h
src/wallet/monero_wallet.h
src/wallet/monero_wallet_keys.h
src/wallet/monero_wallet_model.h
DESTINATION include/wallet)
INSTALL(TARGETS monero-cpp
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
endif()
########################
# Build C++ sample Code
########################
if (BUILD_SAMPLE)
set(SAMPLE_CODE_SRC_FILES test/sample_code.cpp)
add_executable(sample_code ${LIBRARY_SRC_FILES} ${SAMPLE_CODE_SRC_FILES})
target_link_libraries(sample_code
wallet
rpc_base
net
lmdb
easylogging
cryptonote_core
cryptonote_protocol
cryptonote_basic
cryptonote_format_utils_basic
mnemonics
ringct
ringct_basic
common
cncrypto
blockchain_db
blocks
checkpoints
device
device_trezor
multisig
version
randomx
epee
hardforks
${wallet_crypto}
${UNBOUND_LIBRARIES}
${Boost_LIBRARIES}
${Protobuf_LIBRARY}
${LibUSB_LIBRARIES}
${OPENSSL_LIBRARIES}
${SODIUM_LIBRARY}
${HIDAPI_LIBRARIES}
${EXTRA_LIBRARIES}
)
if (NOT WIN32)
target_link_libraries(sample_code dl)
endif()
endif()
########################
# Build C++ scratchpad
########################
if (BUILD_SCRATCHPAD)
set(SCRATCHPAD_SRC_FILES test/scratchpad.cpp)
add_executable(scratchpad ${LIBRARY_SRC_FILES} ${SCRATCHPAD_SRC_FILES})
target_link_libraries(scratchpad
wallet
rpc_base
net
lmdb
easylogging
cryptonote_core
cryptonote_protocol
cryptonote_basic
cryptonote_format_utils_basic
mnemonics
ringct
ringct_basic
common
cncrypto
blockchain_db
blocks
checkpoints
device
device_trezor
multisig
version
randomx
epee
hardforks
${wallet_crypto}
${UNBOUND_LIBRARIES}
${Boost_LIBRARIES}
${Protobuf_LIBRARY}
${LibUSB_LIBRARIES}
${OPENSSL_LIBRARIES}
${SODIUM_LIBRARY}
${HIDAPI_LIBRARIES}
${EXTRA_LIBRARIES}
)
if (NOT WIN32)
target_link_libraries(scratchpad dl)
endif()
endif()
########################
# Build C++ tests
########################
if (BUILD_TESTS)
set(TEST_SRC_FILES test/monero_tests.cpp)
add_executable(monero_tests ${LIBRARY_SRC_FILES} ${TEST_SRC_FILES})
target_link_libraries(monero_tests
wallet
rpc_base
net
lmdb
easylogging
cryptonote_core
cryptonote_protocol
cryptonote_basic
cryptonote_format_utils_basic
mnemonics
ringct
ringct_basic
common
cncrypto
blockchain_db
blocks
checkpoints
device
device_trezor
multisig
version
randomx
epee
hardforks
${wallet_crypto}
${UNBOUND_LIBRARIES}
${Boost_LIBRARIES}
${Protobuf_LIBRARY}
${LibUSB_LIBRARIES}
${OPENSSL_LIBRARIES}
${SODIUM_LIBRARY}
${HIDAPI_LIBRARIES}
${EXTRA_LIBRARIES}
)
if (NOT WIN32)
target_link_libraries(monero_tests dl)
endif()
endif()
-21
View File
@@ -1,21 +0,0 @@
MIT License
Copyright (c) woodser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+53 -262
View File
@@ -1,285 +1,76 @@
# Monero C++ Library # Wownero C++ Library
A C++ library for creating Monero applications using native bindings to [monero v0.18.3.3 'Fluorine Fermi'](https://github.com/monero-project/monero/tree/v0.18.3.3). A C++ library for creating Wownero applications using native bindings to Wownero.
* Supports fully client-side wallets by wrapping [wallet2.h](https://github.com/monero-project/monero/blob/master/src/wallet/wallet2.h). * Supports fully client-side wallets by wrapping wallet2.
* Supports multisig, view-only, and offline wallets. * Supports multisig, view-only, and offline wallets.
* Uses a clearly defined [data model and API specification](https://woodser.github.io/monero-java/monero-spec.pdf) intended to be intuitive and robust.
* Query wallet transactions, transfers, and outputs by their properties. * Query wallet transactions, transfers, and outputs by their properties.
* Receive notifications when wallets sync, send, or receive. * Receive notifications when wallets sync, send, or receive.
* Tested by over 100 tests in [monero-java](https://github.com/woodser/monero-java) and [monero-ts](https://github.com/woodser/monero-ts) using JNI and WebAssembly bindings. * Unit tests
## Table of contents Forked from [monero-cpp](https://github.com/woodser/monero-cpp) and modified, credits
go to the original author.
* [Sample code](#sample-code) ## Example usage
* [Documentation](#documentation)
* [Using monero-cpp in your project](#using-monero-cpp-in-your-project)
* [Related projects](#related-projects)
* [License](#license)
* [Donations](#donations)
## Sample code Install the following into, for example, `/usr/local/`:
```c++ 1. [wownero-ng](https://git.wownero.com/dsc/wownero-ng/)
// create a wallet from a seed phrase 2. This repository
monero_wallet_config wallet_config;
wallet_config.m_seed = "hefty value later extra artistic firm radar yodel talent future fungal nutshell because sanity awesome nail unjustly rage unafraid cedar delayed thumbs comb custom sanity";
wallet_config.m_path = "MyWalletRestored";
wallet_config.m_password = "supersecretpassword123";
wallet_config.m_network_type = monero_network_type::STAGENET;
wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123");
wallet_config.m_restore_height = 380104;
wallet_config.m_seed_offset = "";
monero_wallet* wallet_restored = monero_wallet_full::create_wallet(wallet_config);
// synchronize the wallet and receive progress notifications Install commands:
struct : monero_wallet_listener {
void on_sync_progress(uint64_t height, uint64_t start_height, uint64_t end_height, double percent_done, const string& message) {
// feed a progress bar?
}
} my_sync_listener;
wallet_restored->sync(my_sync_listener);
// start syncing the wallet continuously in the background ```bash
wallet_restored->start_syncing(); cmake -Bbuild .
make -Cbuild -j8 install
// get balance, account, subaddresses
string restored_primary = wallet_restored->get_primary_address();
uint64_t balance = wallet_restored->get_balance(); // can specify account and subaddress indices
monero_account account = wallet_restored->get_account(1, true); // get account with subaddresses
uint64_t unlocked_account_balance = account.m_unlocked_balance.get(); // get boost::optional value
// query a transaction by hash
monero_tx_query tx_query;
tx_query.m_hash = "314a0f1375db31cea4dac4e0a51514a6282b43792269b3660166d4d2b46437ca";
vector<shared_ptr<monero_tx_wallet>> txs = wallet_restored->get_txs(tx_query);
shared_ptr<monero_tx_wallet> tx = txs[0];
for (const shared_ptr<monero_transfer> transfer : tx->get_transfers()) {
bool is_incoming = transfer->is_incoming().get();
uint64_t in_amount = transfer->m_amount.get();
int account_index = transfer->m_account_index.get();
}
monero_utils::free(txs);
// query incoming transfers to account 1
monero_transfer_query transfer_query;
transfer_query.m_is_incoming = true;
transfer_query.m_account_index = 1;
vector<shared_ptr<monero_transfer>> transfers = wallet_restored->get_transfers(transfer_query);
monero_utils::free(transfers);
// query unspent outputs
monero_output_query output_query;
output_query.m_is_spent = false;
vector<shared_ptr<monero_output_wallet>> outputs = wallet_restored->get_outputs(output_query);
monero_utils::free(outputs);
// create and sync a new wallet with a random seed phrase
wallet_config = monero_wallet_config();
wallet_config.m_path = "MyWalletRandom";
wallet_config.m_password = "supersecretpassword123";
wallet_config.m_network_type = monero_network_type::STAGENET;
wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123");
wallet_config.m_language = "English";
monero_wallet* wallet_random = monero_wallet_full::create_wallet(wallet_config);
wallet_random->sync();
// synchronize in the background every 5 seconds
wallet_random->start_syncing(5000);
// get wallet info
string random_seed = wallet_random->get_seed();
string random_primary = wallet_random->get_primary_address();
uint64_t random_height = wallet_random->get_height();
bool random_is_synced = wallet_random->is_synced();
// receive notifications when funds are received, confirmed, and unlocked
struct : monero_wallet_listener {
void on_output_received(const monero_output_wallet& output) {
cout << "Wallet received funds!" << endl;
uint64_t amount = output.m_amount.get();
string tx_hash = output.m_tx->m_hash.get();
bool is_confirmed = output.m_tx->m_is_confirmed.get();
bool is_locked = dynamic_pointer_cast<monero_tx_wallet>(output.m_tx)->m_is_locked.get();
int account_index = output.m_account_index.get();
int subaddress_index = output.m_subaddress_index.get();
FUNDS_RECEIVED = true;
}
} my_listener;
wallet_random->add_listener(my_listener);
// send funds from the restored wallet to the random wallet
monero_tx_config tx_config;
tx_config.m_account_index = 0;
tx_config.m_address = wallet_random->get_address(1, 0);
tx_config.m_amount = 50000;
tx_config.m_relay = true;
shared_ptr<monero_tx_wallet> sent_tx = wallet_restored->create_tx(tx_config);
bool in_pool = sent_tx->m_in_tx_pool.get(); // true
monero_utils::free(sent_tx);
// mine with 7 threads to push the network along
int num_threads = 7;
bool is_background = false;
bool ignore_battery = false;
wallet_restored->start_mining(num_threads, is_background, ignore_battery);
// wait for the next block to be added to the chain
uint64_t next_height = wallet_random->wait_for_next_block();
// stop mining
wallet_restored->stop_mining();
// create config to send funds to multiple destinations in the random wallet
tx_config = monero_tx_config();
tx_config.m_account_index = 1; // withdraw funds from this account
tx_config.m_subaddress_indices = vector<uint32_t>();
tx_config.m_subaddress_indices.push_back(0);
tx_config.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account
tx_config.m_priority = monero_tx_priority::UNIMPORTANT; // no rush
tx_config.m_relay = false; // create transaction and relay to the network if true
vector<shared_ptr<monero_destination>> destinations; // specify the recipients and their amounts
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(1, 0), 50000));
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(2, 0), 50000));
tx_config.m_destinations = destinations;
// create the transaction, confirm with the user, and relay to the network
shared_ptr<monero_tx_wallet> created_tx = wallet_restored->create_tx(tx_config);
uint64_t fee = created_tx->m_fee.get(); // "Are you sure you want to send ...?"
wallet_restored->relay_tx(*created_tx); // recipient receives notification within 5 seconds
monero_utils::free(created_tx);
// save and close the wallets
wallet_restored->close(true);
wallet_random->close(true);
delete wallet_restored;
delete wallet_random;
``` ```
## Documentation Then in your own project:
* [API documentation](https://woodser.github.io/monero-cpp/doxygen/annotated.html) ```cmake
* [API and model overview with visual diagrams](https://woodser.github.io/monero-java/monero-spec.pdf) find_package(wownero_cpp REQUIRED)
* [monero-ts documentation](https://github.com/woodser/monero-ts#documentation) provides additional documentation which translates to monero-cpp add_executable(test main.cpp)
target_link_libraries(test PUBLIC wownero_cpp)
```
## Using monero-cpp in your project ```cpp
#include <iostream>
This project may be compiled as part of another application or built as a shared or static library. #include "wallet/wownero_wallet_full.h"
#include "utils/wownero_utils.h"
For example, [monero-java](https://github.com/woodser/monero-java) compiles this project to a shared library to support Java JNI bindings, while [monero-ts](https://github.com/woodser/monero-ts) compiles this project to WebAssembly binaries. using namespace std;
wownero_wallet* wallet_restored = nullptr;
### Linux int main() {
// create a wallet from a seed phrase into /tmp/test.keys
wownero_wallet_config wallet_config;
wallet_config.m_seed = "afar industrial unafraid input ulcers innocent aggravate pulp insult sawmill ankle smash niece hydrogen mouth issued unusual pride fully identity fever hatchet knife knowledge issued";
wallet_config.m_path = "/tmp/test";
wallet_config.m_password = "";
wallet_config.m_network_type = wownero_network_type::MAINNET;
// configure your own remote node here
wallet_config.m_server = wownero_rpc_connection("http://10.1.0.10:34568", "", "");
wallet_config.m_restore_height = 610000;
wallet_config.m_seed_offset = "";
wallet_restored = wownero_wallet_full::create_wallet(wallet_config);
wallet_restored->save();
1. Clone the project repository if applicable: `git clone --recurse-submodules https://github.com/woodser/monero-cpp.git` // synchronize the wallet and receive progress notifications
2. Update submodules: `cd monero-cpp && ./bin/update_submodules.sh` struct : wownero_wallet_listener {
3. `sudo apt update && sudo apt install build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz nettle-dev libevent-dev` void on_sync_progress(uint64_t height, uint64_t start_height, uint64_t end_height, double percent_done, const string& message) {
4. Follow instructions to install [unbound](https://unbound.docs.nlnetlabs.nl/en/latest/getting-started/installation.html) for Linux to your home directory (e.g. `~/unbound-1.19.0`). // feed a progress bar?
printf("%f", percent_done);
wallet_restored->save();
}
} my_sync_listener;
For example, install expat: wallet_restored->sync(my_sync_listener);
```
cd ~
wget https://github.com/libexpat/libexpat/releases/download/R_2_4_8/expat-2.4.8.tar.bz2
tar -xf expat-2.4.8.tar.bz2
sudo rm expat-2.4.8.tar.bz2
cd expat-2.4.8
./configure --enable-static --disable-shared
make
sudo make install
cd ../
```
For example, install unbound: // start syncing the wallet continuously in the background
``` wallet_restored->start_syncing();
cd ~
wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.19.0.tar.gz
tar xzf unbound-1.19.0.tar.gz
sudo apt update
sudo apt install -y build-essential
sudo apt install -y libssl-dev
sudo apt install -y libexpat1-dev
sudo apt-get install -y bison
sudo apt-get install -y flex
cd unbound-1.19.0
./configure --with-libexpat=/usr --with-ssl=/usr
make
sudo make install
cd ../
```
5. Build monero-project, located as a submodule at ./external/monero-project. Install [dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system, then build with: `make release-static -j8`
6. Link to this library's source files in your application, or build monero-cpp to a shared library in ./build: `./bin/build_libmonero_cpp.sh`
### macOS return 0;
}
1. Clone the project repository if applicable: `git clone --recurse-submodules https://github.com/woodser/monero-cpp.git` ```
2. Update submodules: `cd monero-cpp && ./bin/update_submodules.sh`
3. Follow instructions to install [unbound](https://unbound.docs.nlnetlabs.nl/en/latest/getting-started/installation.html) for macOS to your home directory (e.g. `~/unbound-1.19.0`).
For example:
```
cd ~
wget https://nlnetlabs.nl/downloads/unbound/unbound-1.19.0.tar.gz
tar xzf unbound-1.19.0.tar.gz
cd ~/unbound-1.19.0
./configure --with-ssl=/opt/homebrew/Cellar/openssl@3/3.2.1/ --with-libexpat=/opt/homebrew/Cellar/expat/2.5.0
make
sudo make install
```
4. Build monero-project, located as a submodule at ./external/monero-project. Install [dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system, then build with: `make release-static -j8`
5. Link to this library's source files in your application, or build monero-cpp to a shared library in ./build: `./bin/build_libmonero_cpp.sh`
### Windows
1. Download and install [MSYS2](https://www.msys2.org/).
2. Press the Windows button and launch `MSYS2 MINGW64` for 64 bit systems or `MSYS2 MINGW32` for 32 bit.
3. Update packages: `pacman -Syu` and confirm at prompts.
4. Relaunch MSYS2 (if necessary) and install dependencies:
For 64 bit:
```
pacman -S mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-unbound mingw-w64-x86_64-protobuf git mingw-w64-x86_64-libusb gettext base-devel
```
For 32 bit:
```
pacman -S mingw-w64-i686-toolchain make mingw-w64-i686-cmake mingw-w64-i686-boost mingw-w64-i686-openssl mingw-w64-i686-zeromq mingw-w64-i686-libsodium mingw-w64-i686-hidapi mingw-w64-i686-unbound mingw-w64-i686-protobuf git mingw-w64-i686-libusb gettext base-devel
```
5. Clone repo if installing standalone (skip if building as part of another repo like monero-java or monero-ts): `git clone --recursive https://github.com/woodser/monero-cpp.git`
6. Update submodules: `cd monero-cpp && ./bin/update_submodules.sh`
7. Build monero-project, located as a submodule at ./external/monero-project. Install [dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system, then build with:
For 64 bit: `make release-static-win64`
For 32 bit: `make release-static-win32`
8. Link to this library's source files in your application, or build monero-cpp to a shared library (libmonero-cpp.dll) in ./build: `./bin/build_libmonero_cpp.sh`
## Running sample code and tests
1. In CMakeLists.txt, set the flags to build:
set(BUILD_LIBRARY ON)
set(BUILD_SAMPLE ON)
set(BUILD_SCRATCHPAD ON)
set(BUILD_TESTS ON)
2. `./bin/build_libmonero_cpp.sh`
3. Run the app, for example: `./build/sample_code`
## Related projects
* [monero-java](https://github.com/woodser/monero-java)
* [monero-ts](https://github.com/woodser/monero-ts)
## License
This project is licensed under MIT.
## Donations
If this library brings you value, please consider donating.
<p align="center">
<img src="donate.png" width="115" height="115"/><br>
<code>46FR1GKVqFNQnDiFkH7AuzbUBrGQwz2VdaXTDD4jcjRE8YkkoTYTmZ2Vohsz9gLSqkj5EM6ai9Q7sBoX4FPPYJdGKQQXPVz</code>
</p>
-28
View File
@@ -1,28 +0,0 @@
#!/bin/sh
# build monero-project dependencies
cd ./external/monero-project/ || exit 1
git submodule update --init --force || exit 1
HOST_NCORES=$(nproc 2>/dev/null || shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
if [[ "$OSTYPE" == "msys" ]]; then
bit=$(getconf LONG_BIT)
if [ "$bit" == "64" ]; then
make release-static-win64 -j$HOST_NCORES || exit 1
else
make release-static-win32 -j$HOST_NCORES || exit 1
fi
elif [[ "$OSTYPE" == "cygwin" ]]; then
echo "monero-project supports building on Windows only with MSYS"
exit 1
else
# OS is not windows
make release-static -j$HOST_NCORES || exit 1
fi
cd ../../
# build libmonero-cpp shared library
mkdir -p build &&
cd build &&
cmake .. &&
cmake --build . &&
make .
-10
View File
@@ -1,10 +0,0 @@
#!/usr/bin/env bash
# initialize submodules recursively
git submodule update --init --force --recursive
# update monero-project
cd ./external/monero-project
git checkout master
git pull --ff-only origin master
cd ../../
+8
View File
@@ -0,0 +1,8 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/wownero_cppTargets.cmake")
find_package(Wownero REQUIRED)
check_required_components(wownero_cpp)
check_required_components(Wownero)
+56
View File
@@ -0,0 +1,56 @@
# Copyright (c) 2014-2020, The Monero Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# - Try to find readline include dirs and libraries
#
# Automatically finds ccache build accelerator, if it's found in PATH.
#
# Usage of this module as follows:
#
# project(monero)
# include(FindCcache) # Include AFTER the project() macro to be able to reach the CMAKE_CXX_COMPILER variable
#
# Properties modified by this module:
#
# GLOBAL PROPERTY RULE_LAUNCH_COMPILE set to ccache, when ccache found
# GLOBAL PROPERTY RULE_LAUNCH_LINK set to ccache, when ccache found
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
set(TEMP_CPP_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test-program.cpp")
file(WRITE "${TEMP_CPP_FILE}" "int main() { return 0; }")
execute_process(COMMAND "${CCACHE_FOUND}" "${CMAKE_CXX_COMPILER}" "${TEMP_CPP_FILE}" RESULT_VARIABLE RET)
if (${RET} EQUAL 0)
message("found usable ccache: ${CCACHE_FOUND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_FOUND}")
else()
message("found ccache ${CCACHE_FOUND}, but is UNUSABLE! Return code: ${RET}")
endif()
else()
message("ccache NOT found!")
endif()
-60
View File
@@ -1,60 +0,0 @@
# - try to find HIDAPI library
# from http://www.signal11.us/oss/hidapi/
#
# Cache Variables: (probably not for direct use in your scripts)
# HIDAPI_INCLUDE_DIR
# HIDAPI_LIBRARY
#
# Non-cache variables you might use in your CMakeLists.txt:
# HIDAPI_FOUND
# HIDAPI_INCLUDE_DIRS
# HIDAPI_LIBRARIES
#
# Requires these CMake modules:
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
find_library(HIDAPI_LIBRARY
NAMES hidapi hidapi-libusb)
find_path(HIDAPI_INCLUDE_DIR
NAMES hidapi.h
PATH_SUFFIXES
hidapi)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HIDAPI
DEFAULT_MSG
HIDAPI_LIBRARY
HIDAPI_INCLUDE_DIR)
if(HIDAPI_FOUND)
set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}")
if((STATIC AND UNIX AND NOT APPLE) OR (DEPENDS AND CMAKE_SYSTEM_NAME STREQUAL "Linux"))
find_library(LIBUSB-1.0_LIBRARY usb-1.0)
find_library(LIBUDEV_LIBRARY udev)
if(LIBUSB-1.0_LIBRARY)
set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARIES};${LIBUSB-1.0_LIBRARY}")
if(LIBUDEV_LIBRARY)
set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARIES};${LIBUDEV_LIBRARY}")
else()
message(WARNING "libudev library not found, binaries may fail to link.")
endif()
else()
message(WARNING "libusb-1.0 library not found, binaries may fail to link.")
endif()
endif()
set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}")
endif()
mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBRARY)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

-23
View File
@@ -1,23 +0,0 @@
#ifndef crypto_verify_16_H
#define crypto_verify_16_H
#include <stddef.h>
#include "export.h"
#ifdef __cplusplus
extern "C" {
#endif
#define crypto_verify_16_BYTES 16U
SODIUM_EXPORT
size_t crypto_verify_16_bytes(void);
SODIUM_EXPORT
int crypto_verify_16(const unsigned char *x, const unsigned char *y)
__attribute__ ((warn_unused_result));
#ifdef __cplusplus
}
#endif
#endif
-23
View File
@@ -1,23 +0,0 @@
#ifndef crypto_verify_32_H
#define crypto_verify_32_H
#include <stddef.h>
#include "export.h"
#ifdef __cplusplus
extern "C" {
#endif
#define crypto_verify_32_BYTES 32U
SODIUM_EXPORT
size_t crypto_verify_32_bytes(void);
SODIUM_EXPORT
int crypto_verify_32(const unsigned char *x, const unsigned char *y)
__attribute__ ((warn_unused_result));
#ifdef __cplusplus
}
#endif
#endif
-23
View File
@@ -1,23 +0,0 @@
#ifndef crypto_verify_64_H
#define crypto_verify_64_H
#include <stddef.h>
#include "export.h"
#ifdef __cplusplus
extern "C" {
#endif
#define crypto_verify_64_BYTES 64U
SODIUM_EXPORT
size_t crypto_verify_64_bytes(void);
SODIUM_EXPORT
int crypto_verify_64(const unsigned char *x, const unsigned char *y)
__attribute__ ((warn_unused_result));
#ifdef __cplusplus
}
#endif
#endif
-57
View File
@@ -1,57 +0,0 @@
#ifndef sodium_export_H
#define sodium_export_H
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#if !defined(__clang__) && !defined(__GNUC__)
# ifdef __attribute__
# undef __attribute__
# endif
# define __attribute__(a)
#endif
#ifdef SODIUM_STATIC
# define SODIUM_EXPORT
# define SODIUM_EXPORT_WEAK
#else
# if defined(_MSC_VER)
# ifdef SODIUM_DLL_EXPORT
# define SODIUM_EXPORT __declspec(dllexport)
# else
# define SODIUM_EXPORT __declspec(dllimport)
# endif
# else
# if defined(__SUNPRO_C)
# ifndef __GNU_C__
# define SODIUM_EXPORT __attribute__ (visibility(__global))
# else
# define SODIUM_EXPORT __attribute__ __global
# endif
# elif defined(_MSG_VER)
# define SODIUM_EXPORT extern __declspec(dllexport)
# else
# define SODIUM_EXPORT __attribute__ ((visibility ("default")))
# endif
# endif
# if defined(__ELF__) && !defined(SODIUM_DISABLE_WEAK_FUNCTIONS)
# define SODIUM_EXPORT_WEAK SODIUM_EXPORT __attribute__((weak))
# else
# define SODIUM_EXPORT_WEAK SODIUM_EXPORT
# endif
#endif
#ifndef CRYPTO_ALIGN
# if defined(__INTEL_COMPILER) || defined(_MSC_VER)
# define CRYPTO_ALIGN(x) __declspec(align(x))
# else
# define CRYPTO_ALIGN(x) __attribute__ ((aligned(x)))
# endif
#endif
#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))
#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)
#endif
-98
View File
@@ -1,98 +0,0 @@
#include <stddef.h>
#include <stdint.h>
#include "crypto_verify_16.h"
#include "crypto_verify_32.h"
#include "crypto_verify_64.h"
size_t
crypto_verify_16_bytes(void)
{
return crypto_verify_16_BYTES;
}
size_t
crypto_verify_32_bytes(void)
{
return crypto_verify_32_BYTES;
}
size_t
crypto_verify_64_bytes(void)
{
return crypto_verify_64_BYTES;
}
#if defined(HAVE_EMMINTRIN_H) && defined(__SSE2__)
# ifdef __GNUC__
# pragma GCC target("sse2")
# endif
# include <emmintrin.h>
static inline int
crypto_verify_n(const unsigned char *x_, const unsigned char *y_,
const int n)
{
const __m128i zero = _mm_setzero_si128();
volatile __m128i v1, v2, z;
volatile int m;
int i;
const volatile __m128i *volatile x =
(const volatile __m128i *volatile) (const void *) x_;
const volatile __m128i *volatile y =
(const volatile __m128i *volatile) (const void *) y_;
v1 = _mm_loadu_si128((const __m128i *) &x[0]);
v2 = _mm_loadu_si128((const __m128i *) &y[0]);
z = _mm_xor_si128(v1, v2);
for (i = 1; i < n / 16; i++) {
v1 = _mm_loadu_si128((const __m128i *) &x[i]);
v2 = _mm_loadu_si128((const __m128i *) &y[i]);
z = _mm_or_si128(z, _mm_xor_si128(v1, v2));
}
m = _mm_movemask_epi8(_mm_cmpeq_epi32(z, zero));
v1 = zero; v2 = zero; z = zero;
return (int) (((uint32_t) m + 1U) >> 16) - 1;
}
#else
static inline int
crypto_verify_n(const unsigned char *x_, const unsigned char *y_,
const int n)
{
const volatile unsigned char *volatile x =
(const volatile unsigned char *volatile) x_;
const volatile unsigned char *volatile y =
(const volatile unsigned char *volatile) y_;
volatile uint_fast16_t d = 0U;
int i;
for (i = 0; i < n; i++) {
d |= x[i] ^ y[i];
}
return (1 & ((d - 1) >> 8)) - 1;
}
#endif
int
crypto_verify_16(const unsigned char *x, const unsigned char *y)
{
return crypto_verify_n(x, y, crypto_verify_16_BYTES);
}
int
crypto_verify_32(const unsigned char *x, const unsigned char *y)
{
return crypto_verify_n(x, y, crypto_verify_32_BYTES);
}
int
crypto_verify_64(const unsigned char *x, const unsigned char *y)
{
return crypto_verify_n(x, y, crypto_verify_64_BYTES);
}
+62
View File
@@ -0,0 +1,62 @@
add_subdirectory(daemon)
add_subdirectory(utils)
add_subdirectory(wallet)
file(GLOB SOURCES
"daemon/*.cpp"
"utils/*.cpp"
"wallet/*.cpp"
)
add_library(wownero_cpp ${SOURCES})
include(GNUInstallDirs)
target_link_libraries(wownero_cpp PUBLIC
wownero::epee
wownero::wallet_api
wownero::easylogging
Threads::Threads
${CMAKE_DL_LIBS}
)
target_include_directories(wownero_cpp
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/wownero_cpp/>
)
install(TARGETS wownero_cpp EXPORT wownero_cppTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wownero_cpp/)
# CMake targets file
install(EXPORT wownero_cppTargets
FILE wownero_cppTargets.cmake
NAMESPACE wownero_cpp::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/wownero_cpp")
# generate CMake config file
configure_package_config_file("${CMAKE_SOURCE_DIR}/cmake/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/wownero_cppConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/wownero_cpp")
# install CMake config file
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/wownero_cppConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/wownero_cpp")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/wownero_cppConfigVersion.cmake"
VERSION "${CMAKE_PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/wownero_cppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/wownero_cppConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wownero_cpp)
message(STATUS "==== wownero-cpp")
message(STATUS "CMake ${CMAKE_VERSION}")
message(STATUS "[+] VERSION: ${CMAKE_PROJECT_VERSION}")
message(STATUS "[+] STATIC: ${STATIC}")
+2
View File
@@ -0,0 +1,2 @@
file(GLOB HEADERS "*.h")
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wownero_cpp/daemon)
@@ -50,11 +50,11 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/ */
#include "monero_daemon.h" #include "wownero_daemon.h"
/** /**
* Public library intereface. * Public library intereface.
*/ */
namespace monero { namespace wownero {
} }
@@ -52,11 +52,11 @@
#pragma once #pragma once
#include "monero_daemon_model.h" #include "wownero_daemon_model.h"
/** /**
* Public library interface. * Public library interface.
*/ */
namespace monero { namespace wownero {
} }
@@ -50,22 +50,22 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/ */
#include "monero_daemon_model.h" #include "wownero_daemon_model.h"
#include "utils/gen_utils.h" #include "utils/gen_utils.h"
#include "utils/monero_utils.h" #include "utils/wownero_utils.h"
#include "include_base_utils.h" #include "include_base_utils.h"
#include "common/util.h" #include "common/util.h"
/** /**
* Public library interface. * Public library interface.
*/ */
namespace monero { namespace wownero {
// ----------------------- UNDECLARED PRIVATE HELPERS ----------------------- // ----------------------- UNDECLARED PRIVATE HELPERS -----------------------
void merge_tx(std::vector<std::shared_ptr<monero_tx>>& txs, const std::shared_ptr<monero_tx>& tx) { void merge_tx(std::vector<std::shared_ptr<wownero_tx>>& txs, const std::shared_ptr<wownero_tx>& tx) {
for (const std::shared_ptr<monero_tx>& aTx : txs) { for (const std::shared_ptr<wownero_tx>& aTx : txs) {
if (aTx->m_hash.get() == tx->m_hash.get()) { if (aTx->m_hash.get() == tx->m_hash.get()) {
aTx->merge(aTx, tx); aTx->merge(aTx, tx);
return; return;
@@ -76,7 +76,7 @@ namespace monero {
// ------------------------- INITIALIZE CONSTANTS --------------------------- // ------------------------- INITIALIZE CONSTANTS ---------------------------
const std::string monero_tx::DEFAULT_PAYMENT_ID = std::string("0000000000000000"); const std::string wownero_tx::DEFAULT_PAYMENT_ID = std::string("0000000000000000");
// ------------------------- SERIALIZABLE STRUCT ---------------------------- // ------------------------- SERIALIZABLE STRUCT ----------------------------
@@ -85,22 +85,22 @@ namespace monero {
doc.SetObject(); doc.SetObject();
rapidjson::Value val = to_rapidjson_val(doc.GetAllocator()); rapidjson::Value val = to_rapidjson_val(doc.GetAllocator());
val.Swap(doc); val.Swap(doc);
return monero_utils::serialize(doc); return wownero_utils::serialize(doc);
} }
// ----------------------------- MONERO VERSION ----------------------------- // ----------------------------- MONERO VERSION -----------------------------
rapidjson::Value monero_version::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_version::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// create root // create root
rapidjson::Value root(rapidjson::kObjectType); rapidjson::Value root(rapidjson::kObjectType);
// set num values // set num values
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
if (m_number != boost::none) monero_utils::add_json_member("number", m_number.get(), allocator, root, value_num); if (m_number != boost::none) wownero_utils::add_json_member("number", m_number.get(), allocator, root, value_num);
// set bool values // set bool values
if (m_is_release != boost::none) monero_utils::add_json_member("isRelease", m_is_release.get(), allocator, root); if (m_is_release != boost::none) wownero_utils::add_json_member("isRelease", m_is_release.get(), allocator, root);
// return root // return root
return root; return root;
@@ -108,23 +108,23 @@ namespace monero {
// --------------------------- MONERO RPC VERSION --------------------------- // --------------------------- MONERO RPC VERSION ---------------------------
rapidjson::Value monero_rpc_connection::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_rpc_connection::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// create root // create root
rapidjson::Value root(rapidjson::kObjectType); rapidjson::Value root(rapidjson::kObjectType);
// set string values // set string values
rapidjson::Value value_str(rapidjson::kStringType); rapidjson::Value value_str(rapidjson::kStringType);
if (m_uri != boost::none) monero_utils::add_json_member("uri", m_uri.get(), allocator, root, value_str); if (m_uri != boost::none) wownero_utils::add_json_member("uri", m_uri.get(), allocator, root, value_str);
if (m_username != boost::none) monero_utils::add_json_member("username", m_username.get(), allocator, root, value_str); if (m_username != boost::none) wownero_utils::add_json_member("username", m_username.get(), allocator, root, value_str);
if (m_password != boost::none) monero_utils::add_json_member("password", m_password.get(), allocator, root, value_str); if (m_password != boost::none) wownero_utils::add_json_member("password", m_password.get(), allocator, root, value_str);
// return root // return root
return root; return root;
} }
monero_rpc_connection monero_rpc_connection::from_property_tree(const boost::property_tree::ptree& node) { wownero_rpc_connection wownero_rpc_connection::from_property_tree(const boost::property_tree::ptree& node) {
monero_rpc_connection connection; wownero_rpc_connection connection;
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
std::string key = it->first; std::string key = it->first;
if (key == std::string("uri")) connection.m_uri = it->second.data(); if (key == std::string("uri")) connection.m_uri = it->second.data();
@@ -136,42 +136,42 @@ namespace monero {
// ------------------------- MONERO BLOCK HEADER ---------------------------- // ------------------------- MONERO BLOCK HEADER ----------------------------
rapidjson::Value monero_block_header::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_block_header::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// create root // create root
rapidjson::Value root(rapidjson::kObjectType); rapidjson::Value root(rapidjson::kObjectType);
// set num values // set num values
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
if (m_height != boost::none) monero_utils::add_json_member("height", m_height.get(), allocator, root, value_num); if (m_height != boost::none) wownero_utils::add_json_member("height", m_height.get(), allocator, root, value_num);
if (m_timestamp != boost::none) monero_utils::add_json_member("timestamp", m_timestamp.get(), allocator, root, value_num); if (m_timestamp != boost::none) wownero_utils::add_json_member("timestamp", m_timestamp.get(), allocator, root, value_num);
if (m_size != boost::none) monero_utils::add_json_member("size", m_size.get(), allocator, root, value_num); if (m_size != boost::none) wownero_utils::add_json_member("size", m_size.get(), allocator, root, value_num);
if (m_weight != boost::none) monero_utils::add_json_member("weight", m_weight.get(), allocator, root, value_num); if (m_weight != boost::none) wownero_utils::add_json_member("weight", m_weight.get(), allocator, root, value_num);
if (m_long_term_weight != boost::none) monero_utils::add_json_member("longTermWeight", m_long_term_weight.get(), allocator, root, value_num); if (m_long_term_weight != boost::none) wownero_utils::add_json_member("longTermWeight", m_long_term_weight.get(), allocator, root, value_num);
if (m_depth != boost::none) monero_utils::add_json_member("depth", m_depth.get(), allocator, root, value_num); if (m_depth != boost::none) wownero_utils::add_json_member("depth", m_depth.get(), allocator, root, value_num);
if (m_difficulty != boost::none) monero_utils::add_json_member("difficulty", m_difficulty.get(), allocator, root, value_num); if (m_difficulty != boost::none) wownero_utils::add_json_member("difficulty", m_difficulty.get(), allocator, root, value_num);
if (m_cumulative_difficulty != boost::none) monero_utils::add_json_member("cumulativeDifficulty", m_cumulative_difficulty.get(), allocator, root, value_num); if (m_cumulative_difficulty != boost::none) wownero_utils::add_json_member("cumulativeDifficulty", m_cumulative_difficulty.get(), allocator, root, value_num);
if (m_major_version != boost::none) monero_utils::add_json_member("majorVersion", m_major_version.get(), allocator, root, value_num); if (m_major_version != boost::none) wownero_utils::add_json_member("majorVersion", m_major_version.get(), allocator, root, value_num);
if (m_minor_version != boost::none) monero_utils::add_json_member("minorVersion", m_minor_version.get(), allocator, root, value_num); if (m_minor_version != boost::none) wownero_utils::add_json_member("minorVersion", m_minor_version.get(), allocator, root, value_num);
if (m_nonce != boost::none) monero_utils::add_json_member("nonce", m_nonce.get(), allocator, root, value_num); if (m_nonce != boost::none) wownero_utils::add_json_member("nonce", m_nonce.get(), allocator, root, value_num);
if (m_miner_tx_hash != boost::none) monero_utils::add_json_member("minerTxHash", m_miner_tx_hash.get(), allocator, root, value_num); if (m_miner_tx_hash != boost::none) wownero_utils::add_json_member("minerTxHash", m_miner_tx_hash.get(), allocator, root, value_num);
if (m_num_txs != boost::none) monero_utils::add_json_member("numTxs", m_num_txs.get(), allocator, root, value_num); if (m_num_txs != boost::none) wownero_utils::add_json_member("numTxs", m_num_txs.get(), allocator, root, value_num);
if (m_reward != boost::none) monero_utils::add_json_member("reward", m_reward.get(), allocator, root, value_num); if (m_reward != boost::none) wownero_utils::add_json_member("reward", m_reward.get(), allocator, root, value_num);
// set string values // set string values
rapidjson::Value value_str(rapidjson::kStringType); rapidjson::Value value_str(rapidjson::kStringType);
if (m_hash != boost::none) monero_utils::add_json_member("hash", m_hash.get(), allocator, root, value_str); if (m_hash != boost::none) wownero_utils::add_json_member("hash", m_hash.get(), allocator, root, value_str);
if (m_prev_hash != boost::none) monero_utils::add_json_member("prevHash", m_prev_hash.get(), allocator, root, value_str); if (m_prev_hash != boost::none) wownero_utils::add_json_member("prevHash", m_prev_hash.get(), allocator, root, value_str);
if (m_pow_hash != boost::none) monero_utils::add_json_member("powHash", m_pow_hash.get(), allocator, root, value_str); if (m_pow_hash != boost::none) wownero_utils::add_json_member("powHash", m_pow_hash.get(), allocator, root, value_str);
// set bool values // set bool values
if (m_orphan_status != boost::none) monero_utils::add_json_member("orphanStatus", m_orphan_status.get(), allocator, root); if (m_orphan_status != boost::none) wownero_utils::add_json_member("orphanStatus", m_orphan_status.get(), allocator, root);
// return root // return root
return root; return root;
} }
std::shared_ptr<monero_block_header> monero_block_header::copy(const std::shared_ptr<monero_block_header>& src, const std::shared_ptr<monero_block_header>& tgt) const { std::shared_ptr<wownero_block_header> wownero_block_header::copy(const std::shared_ptr<wownero_block_header>& src, const std::shared_ptr<wownero_block_header>& tgt) const {
if (this != src.get()) throw std::runtime_error("this block header != src"); if (this != src.get()) throw std::runtime_error("this block header != src");
tgt->m_hash = src->m_hash; tgt->m_hash = src->m_hash;
tgt->m_height = src->m_height; tgt->m_height = src->m_height;
@@ -195,7 +195,7 @@ namespace monero {
return tgt; return tgt;
} }
void monero_block_header::merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other) { void wownero_block_header::merge(const std::shared_ptr<wownero_block_header>& self, const std::shared_ptr<wownero_block_header>& other) {
if (this != self.get()) throw std::runtime_error("this != self"); if (this != self.get()) throw std::runtime_error("this != self");
if (self == other) return; if (self == other) return;
m_hash = gen_utils::reconcile(m_hash, other->m_hash, "block header m_hash"); m_hash = gen_utils::reconcile(m_hash, other->m_hash, "block header m_hash");
@@ -220,18 +220,18 @@ namespace monero {
// ----------------------------- MONERO BLOCK ------------------------------- // ----------------------------- MONERO BLOCK -------------------------------
rapidjson::Value monero_block::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_block::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// serialize root from superclass // serialize root from superclass
rapidjson::Value root = monero_block_header::to_rapidjson_val(allocator); rapidjson::Value root = wownero_block_header::to_rapidjson_val(allocator);
// set string values // set string values
rapidjson::Value value_str(rapidjson::kStringType); rapidjson::Value value_str(rapidjson::kStringType);
if (m_hex != boost::none) monero_utils::add_json_member("hex", m_hex.get(), allocator, root, value_str); if (m_hex != boost::none) wownero_utils::add_json_member("hex", m_hex.get(), allocator, root, value_str);
// set sub-arrays // set sub-arrays
if (!m_txs.empty()) root.AddMember("txs", monero_utils::to_rapidjson_val(allocator, m_txs), allocator); if (!m_txs.empty()) root.AddMember("txs", wownero_utils::to_rapidjson_val(allocator, m_txs), allocator);
if (!m_tx_hashes.empty()) root.AddMember("txHashes", monero_utils::to_rapidjson_val(allocator, m_tx_hashes), allocator); if (!m_tx_hashes.empty()) root.AddMember("txHashes", wownero_utils::to_rapidjson_val(allocator, m_tx_hashes), allocator);
// set sub-objects // set sub-objects
if (m_miner_tx != boost::none) root.AddMember("minerTx", m_miner_tx.get()->to_rapidjson_val(allocator), allocator); if (m_miner_tx != boost::none) root.AddMember("minerTx", m_miner_tx.get()->to_rapidjson_val(allocator), allocator);
@@ -240,25 +240,25 @@ namespace monero {
return root; return root;
} }
std::shared_ptr<monero_block> monero_block::copy(const std::shared_ptr<monero_block>& src, const std::shared_ptr<monero_block>& tgt) const { std::shared_ptr<wownero_block> wownero_block::copy(const std::shared_ptr<wownero_block>& src, const std::shared_ptr<wownero_block>& tgt) const {
if (this != src.get()) throw std::runtime_error("this block != src"); if (this != src.get()) throw std::runtime_error("this block != src");
monero_block_header::copy(std::static_pointer_cast<monero_block_header>(src), std::static_pointer_cast<monero_block_header>(tgt)); wownero_block_header::copy(std::static_pointer_cast<wownero_block_header>(src), std::static_pointer_cast<wownero_block_header>(tgt));
tgt->m_hex = src->m_hex; tgt->m_hex = src->m_hex;
if (src->m_miner_tx) { if (src->m_miner_tx) {
tgt->m_miner_tx = src->m_miner_tx.get()->copy(src->m_miner_tx.get(), std::make_shared<monero_tx>()); tgt->m_miner_tx = src->m_miner_tx.get()->copy(src->m_miner_tx.get(), std::make_shared<wownero_tx>());
tgt->m_miner_tx.get()->m_block = tgt; tgt->m_miner_tx.get()->m_block = tgt;
} }
if (!src->m_txs.empty()) { if (!src->m_txs.empty()) {
bool use_wallet_types = std::dynamic_pointer_cast<monero_tx_wallet>(src->m_txs[0]) != 0; bool use_wallet_types = std::dynamic_pointer_cast<wownero_tx_wallet>(src->m_txs[0]) != 0;
tgt->m_txs = std::vector<std::shared_ptr<monero_tx>>(); tgt->m_txs = std::vector<std::shared_ptr<wownero_tx>>();
for (const auto& tx : src->m_txs) { for (const auto& tx : src->m_txs) {
if (use_wallet_types) { if (use_wallet_types) {
std::shared_ptr<monero_tx_wallet> tx_wallet = std::static_pointer_cast<monero_tx_wallet>(tx); std::shared_ptr<wownero_tx_wallet> tx_wallet = std::static_pointer_cast<wownero_tx_wallet>(tx);
std::shared_ptr<monero_tx_wallet> tx_copy = tx_wallet->copy(tx_wallet, std::make_shared<monero_tx_wallet>()); std::shared_ptr<wownero_tx_wallet> tx_copy = tx_wallet->copy(tx_wallet, std::make_shared<wownero_tx_wallet>());
tx_copy->m_block = tgt; tx_copy->m_block = tgt;
tgt->m_txs.push_back(tx_copy); tgt->m_txs.push_back(tx_copy);
} else { } else {
std::shared_ptr<monero_tx> tx_copy = tx->copy(tx, std::make_shared<monero_tx>()); std::shared_ptr<wownero_tx> tx_copy = tx->copy(tx, std::make_shared<wownero_tx>());
tx_copy->m_block = tgt; tx_copy->m_block = tgt;
tgt->m_txs.push_back(tx_copy); tgt->m_txs.push_back(tx_copy);
} }
@@ -268,16 +268,16 @@ namespace monero {
return tgt; return tgt;
} }
void monero_block::merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other) { void wownero_block::merge(const std::shared_ptr<wownero_block_header>& self, const std::shared_ptr<wownero_block_header>& other) {
merge(std::static_pointer_cast<monero_block>(self), std::static_pointer_cast<monero_block>(other)); merge(std::static_pointer_cast<wownero_block>(self), std::static_pointer_cast<wownero_block>(other));
} }
void monero_block::merge(const std::shared_ptr<monero_block>& self, const std::shared_ptr<monero_block>& other) { void wownero_block::merge(const std::shared_ptr<wownero_block>& self, const std::shared_ptr<wownero_block>& other) {
if (this != self.get()) throw std::runtime_error("this != self"); if (this != self.get()) throw std::runtime_error("this != self");
if (self == other) return; if (self == other) return;
// merge header fields // merge header fields
monero_block_header::merge(self, other); wownero_block_header::merge(self, other);
// merge reconcilable block extensions // merge reconcilable block extensions
m_hex = gen_utils::reconcile(m_hex, other->m_hex, "block m_hex"); m_hex = gen_utils::reconcile(m_hex, other->m_hex, "block m_hex");
@@ -292,7 +292,7 @@ namespace monero {
// merge non-miner txs // merge non-miner txs
if (!other->m_txs.empty()) { if (!other->m_txs.empty()) {
for (const std::shared_ptr<monero_tx> otherTx : other->m_txs) { // NOTE: not using reference so std::shared_ptr is not deleted when block is dereferenced for (const std::shared_ptr<wownero_tx> otherTx : other->m_txs) { // NOTE: not using reference so std::shared_ptr is not deleted when block is dereferenced
otherTx->m_block = self; otherTx->m_block = self;
merge_tx(self->m_txs, otherTx); merge_tx(self->m_txs, otherTx);
} }
@@ -301,63 +301,63 @@ namespace monero {
// ------------------------------- MONERO TX -------------------------------- // ------------------------------- MONERO TX --------------------------------
rapidjson::Value monero_tx::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_tx::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// create root // create root
rapidjson::Value root(rapidjson::kObjectType); rapidjson::Value root(rapidjson::kObjectType);
// set num values // set num values
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
if (m_version != boost::none) monero_utils::add_json_member("version", m_version.get(), allocator, root, value_num); if (m_version != boost::none) wownero_utils::add_json_member("version", m_version.get(), allocator, root, value_num);
if (m_fee != boost::none) monero_utils::add_json_member("fee", m_fee.get(), allocator, root, value_num); if (m_fee != boost::none) wownero_utils::add_json_member("fee", m_fee.get(), allocator, root, value_num);
if (m_ring_size != boost::none) monero_utils::add_json_member("ringSize", m_ring_size.get(), allocator, root, value_num); if (m_ring_size != boost::none) wownero_utils::add_json_member("ringSize", m_ring_size.get(), allocator, root, value_num);
if (m_num_confirmations != boost::none) monero_utils::add_json_member("numConfirmations", m_num_confirmations.get(), allocator, root, value_num); if (m_num_confirmations != boost::none) wownero_utils::add_json_member("numConfirmations", m_num_confirmations.get(), allocator, root, value_num);
if (m_unlock_time != boost::none) monero_utils::add_json_member("unlockTime", m_unlock_time.get(), allocator, root, value_num); if (m_unlock_time != boost::none) wownero_utils::add_json_member("unlockTime", m_unlock_time.get(), allocator, root, value_num);
if (m_last_relayed_timestamp != boost::none) monero_utils::add_json_member("lastRelayedTimestamp", m_last_relayed_timestamp.get(), allocator, root, value_num); if (m_last_relayed_timestamp != boost::none) wownero_utils::add_json_member("lastRelayedTimestamp", m_last_relayed_timestamp.get(), allocator, root, value_num);
if (m_received_timestamp != boost::none) monero_utils::add_json_member("receivedTimestamp", m_received_timestamp.get(), allocator, root, value_num); if (m_received_timestamp != boost::none) wownero_utils::add_json_member("receivedTimestamp", m_received_timestamp.get(), allocator, root, value_num);
if (m_size != boost::none) monero_utils::add_json_member("size", m_size.get(), allocator, root, value_num); if (m_size != boost::none) wownero_utils::add_json_member("size", m_size.get(), allocator, root, value_num);
if (m_weight != boost::none) monero_utils::add_json_member("weight", m_weight.get(), allocator, root, value_num); if (m_weight != boost::none) wownero_utils::add_json_member("weight", m_weight.get(), allocator, root, value_num);
if (m_last_failed_height != boost::none) monero_utils::add_json_member("lastFailedHeight", m_last_failed_height.get(), allocator, root, value_num); if (m_last_failed_height != boost::none) wownero_utils::add_json_member("lastFailedHeight", m_last_failed_height.get(), allocator, root, value_num);
if (m_max_used_block_height != boost::none) monero_utils::add_json_member("maxUsedBlockHeight", m_max_used_block_height.get(), allocator, root, value_num); if (m_max_used_block_height != boost::none) wownero_utils::add_json_member("maxUsedBlockHeight", m_max_used_block_height.get(), allocator, root, value_num);
// set string values // set string values
rapidjson::Value value_str(rapidjson::kStringType); rapidjson::Value value_str(rapidjson::kStringType);
if (m_hash != boost::none) monero_utils::add_json_member("hash", m_hash.get(), allocator, root, value_str); if (m_hash != boost::none) wownero_utils::add_json_member("hash", m_hash.get(), allocator, root, value_str);
if (m_payment_id != boost::none) monero_utils::add_json_member("paymentId", m_payment_id.get(), allocator, root, value_str); if (m_payment_id != boost::none) wownero_utils::add_json_member("paymentId", m_payment_id.get(), allocator, root, value_str);
if (m_key != boost::none) monero_utils::add_json_member("key", m_key.get(), allocator, root, value_str); if (m_key != boost::none) wownero_utils::add_json_member("key", m_key.get(), allocator, root, value_str);
if (m_full_hex != boost::none) monero_utils::add_json_member("fullHex", m_full_hex.get(), allocator, root, value_str); if (m_full_hex != boost::none) wownero_utils::add_json_member("fullHex", m_full_hex.get(), allocator, root, value_str);
if (m_pruned_hex != boost::none) monero_utils::add_json_member("prunedHex", m_pruned_hex.get(), allocator, root, value_str); if (m_pruned_hex != boost::none) wownero_utils::add_json_member("prunedHex", m_pruned_hex.get(), allocator, root, value_str);
if (m_prunable_hex != boost::none) monero_utils::add_json_member("prunableHex", m_prunable_hex.get(), allocator, root, value_str); if (m_prunable_hex != boost::none) wownero_utils::add_json_member("prunableHex", m_prunable_hex.get(), allocator, root, value_str);
if (m_prunable_hash != boost::none) monero_utils::add_json_member("prunableHash", m_prunable_hash.get(), allocator, root, value_str); if (m_prunable_hash != boost::none) wownero_utils::add_json_member("prunableHash", m_prunable_hash.get(), allocator, root, value_str);
if (m_metadata != boost::none) monero_utils::add_json_member("metadata", m_metadata.get(), allocator, root, value_str); if (m_metadata != boost::none) wownero_utils::add_json_member("metadata", m_metadata.get(), allocator, root, value_str);
if (m_common_tx_sets != boost::none) monero_utils::add_json_member("commonTxSets", m_common_tx_sets.get(), allocator, root, value_str); if (m_common_tx_sets != boost::none) wownero_utils::add_json_member("commonTxSets", m_common_tx_sets.get(), allocator, root, value_str);
if (m_rct_signatures != boost::none) monero_utils::add_json_member("rctSignatures", m_rct_signatures.get(), allocator, root, value_str); if (m_rct_signatures != boost::none) wownero_utils::add_json_member("rctSignatures", m_rct_signatures.get(), allocator, root, value_str);
if (m_rct_sig_prunable != boost::none) monero_utils::add_json_member("rctSigPrunable", m_rct_sig_prunable.get(), allocator, root, value_str); if (m_rct_sig_prunable != boost::none) wownero_utils::add_json_member("rctSigPrunable", m_rct_sig_prunable.get(), allocator, root, value_str);
if (m_last_failed_hash != boost::none) monero_utils::add_json_member("lastFailedHash", m_last_failed_hash.get(), allocator, root, value_str); if (m_last_failed_hash != boost::none) wownero_utils::add_json_member("lastFailedHash", m_last_failed_hash.get(), allocator, root, value_str);
if (m_max_used_block_hash != boost::none) monero_utils::add_json_member("maxUsedBlockHash", m_max_used_block_hash.get(), allocator, root, value_str); if (m_max_used_block_hash != boost::none) wownero_utils::add_json_member("maxUsedBlockHash", m_max_used_block_hash.get(), allocator, root, value_str);
// set bool values // set bool values
if (m_is_miner_tx != boost::none) monero_utils::add_json_member("isMinerTx", m_is_miner_tx.get(), allocator, root); if (m_is_miner_tx != boost::none) wownero_utils::add_json_member("isMinerTx", m_is_miner_tx.get(), allocator, root);
if (m_relay != boost::none) monero_utils::add_json_member("relay", m_relay.get(), allocator, root); if (m_relay != boost::none) wownero_utils::add_json_member("relay", m_relay.get(), allocator, root);
if (m_is_relayed != boost::none) monero_utils::add_json_member("isRelayed", m_is_relayed.get(), allocator, root); if (m_is_relayed != boost::none) wownero_utils::add_json_member("isRelayed", m_is_relayed.get(), allocator, root);
if (m_is_confirmed != boost::none) monero_utils::add_json_member("isConfirmed", m_is_confirmed.get(), allocator, root); if (m_is_confirmed != boost::none) wownero_utils::add_json_member("isConfirmed", m_is_confirmed.get(), allocator, root);
if (m_in_tx_pool != boost::none) monero_utils::add_json_member("inTxPool", m_in_tx_pool.get(), allocator, root); if (m_in_tx_pool != boost::none) wownero_utils::add_json_member("inTxPool", m_in_tx_pool.get(), allocator, root);
if (m_is_double_spend_seen != boost::none) monero_utils::add_json_member("isDoubleSpendSeen", m_is_double_spend_seen.get(), allocator, root); if (m_is_double_spend_seen != boost::none) wownero_utils::add_json_member("isDoubleSpendSeen", m_is_double_spend_seen.get(), allocator, root);
if (m_is_kept_by_block != boost::none) monero_utils::add_json_member("isKeptByBlock", m_is_kept_by_block.get(), allocator, root); if (m_is_kept_by_block != boost::none) wownero_utils::add_json_member("isKeptByBlock", m_is_kept_by_block.get(), allocator, root);
if (m_is_failed != boost::none) monero_utils::add_json_member("isFailed", m_is_failed.get(), allocator, root); if (m_is_failed != boost::none) wownero_utils::add_json_member("isFailed", m_is_failed.get(), allocator, root);
// set sub-arrays // set sub-arrays
if (!m_inputs.empty()) root.AddMember("inputs", monero_utils::to_rapidjson_val(allocator, m_inputs), allocator); if (!m_inputs.empty()) root.AddMember("inputs", wownero_utils::to_rapidjson_val(allocator, m_inputs), allocator);
if (!m_outputs.empty()) root.AddMember("outputs", monero_utils::to_rapidjson_val(allocator, m_outputs), allocator); if (!m_outputs.empty()) root.AddMember("outputs", wownero_utils::to_rapidjson_val(allocator, m_outputs), allocator);
if (!m_output_indices.empty()) root.AddMember("outputIndices", monero_utils::to_rapidjson_val(allocator, m_output_indices), allocator); if (!m_output_indices.empty()) root.AddMember("outputIndices", wownero_utils::to_rapidjson_val(allocator, m_output_indices), allocator);
if (!m_extra.empty()) root.AddMember("extra", monero_utils::to_rapidjson_val(allocator, m_extra), allocator); if (!m_extra.empty()) root.AddMember("extra", wownero_utils::to_rapidjson_val(allocator, m_extra), allocator);
if (!m_signatures.empty()) root.AddMember("signatures", monero_utils::to_rapidjson_val(allocator, m_signatures), allocator); if (!m_signatures.empty()) root.AddMember("signatures", wownero_utils::to_rapidjson_val(allocator, m_signatures), allocator);
// return root // return root
return root; return root;
} }
void monero_tx::from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr<monero_tx> tx) { void wownero_tx::from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr<wownero_tx> tx) {
// initialize tx from node // initialize tx from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
@@ -402,8 +402,8 @@ namespace monero {
} }
} }
std::shared_ptr<monero_tx> monero_tx::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const { std::shared_ptr<wownero_tx> wownero_tx::copy(const std::shared_ptr<wownero_tx>& src, const std::shared_ptr<wownero_tx>& tgt) const {
MTRACE("monero_tx::copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt)"); MTRACE("wownero_tx::copy(const std::shared_ptr<wownero_tx>& src, const std::shared_ptr<wownero_tx>& tgt)");
tgt->m_hash = src->m_hash; tgt->m_hash = src->m_hash;
tgt->m_version = src->m_version; tgt->m_version = src->m_version;
tgt->m_is_miner_tx = src->m_is_miner_tx; tgt->m_is_miner_tx = src->m_is_miner_tx;
@@ -427,17 +427,17 @@ namespace monero {
tgt->m_size = src->m_size; tgt->m_size = src->m_size;
tgt->m_weight = src->m_weight; tgt->m_weight = src->m_weight;
if (!src->m_inputs.empty()) { if (!src->m_inputs.empty()) {
tgt->m_inputs = std::vector<std::shared_ptr<monero_output>>(); tgt->m_inputs = std::vector<std::shared_ptr<wownero_output>>();
for (const std::shared_ptr<monero_output>& input : src->m_inputs) { for (const std::shared_ptr<wownero_output>& input : src->m_inputs) {
std::shared_ptr<monero_output> input_copy = input->copy(input, std::make_shared<monero_output>()); std::shared_ptr<wownero_output> input_copy = input->copy(input, std::make_shared<wownero_output>());
input_copy->m_tx = tgt; input_copy->m_tx = tgt;
tgt->m_inputs.push_back(input_copy); tgt->m_inputs.push_back(input_copy);
} }
} }
if (!src->m_outputs.empty()) { if (!src->m_outputs.empty()) {
tgt->m_outputs = std::vector<std::shared_ptr<monero_output>>(); tgt->m_outputs = std::vector<std::shared_ptr<wownero_output>>();
for (const std::shared_ptr<monero_output>& output : src->m_outputs) { for (const std::shared_ptr<wownero_output>& output : src->m_outputs) {
std::shared_ptr<monero_output> output_copy = output->copy(output, std::make_shared<monero_output>()); std::shared_ptr<wownero_output> output_copy = output->copy(output, std::make_shared<wownero_output>());
output_copy->m_tx = tgt; output_copy->m_tx = tgt;
tgt->m_outputs.push_back(output_copy); tgt->m_outputs.push_back(output_copy);
} }
@@ -458,12 +458,12 @@ namespace monero {
return tgt; return tgt;
} }
boost::optional<uint64_t> monero_tx::get_height() const { boost::optional<uint64_t> wownero_tx::get_height() const {
if (m_block == boost::none) return boost::none; if (m_block == boost::none) return boost::none;
return *((*m_block)->m_height); return *((*m_block)->m_height);
} }
void monero_tx::merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other) { void wownero_tx::merge(const std::shared_ptr<wownero_tx>& self, const std::shared_ptr<wownero_tx>& other) {
if (this != self.get()) throw std::runtime_error("this != self"); if (this != self.get()) throw std::runtime_error("this != self");
if (self == other) return; if (self == other) return;
@@ -514,10 +514,10 @@ namespace monero {
// merge inputs // merge inputs
if (!other->m_inputs.empty()) { if (!other->m_inputs.empty()) {
for (const std::shared_ptr<monero_output>& merger : other->m_inputs) { for (const std::shared_ptr<wownero_output>& merger : other->m_inputs) {
bool merged = false; bool merged = false;
merger->m_tx = self; merger->m_tx = self;
for (const std::shared_ptr<monero_output>& mergee : m_inputs) { for (const std::shared_ptr<wownero_output>& mergee : m_inputs) {
if ((*mergee->m_key_image)->m_hex == (*merger->m_key_image)->m_hex) { if ((*mergee->m_key_image)->m_hex == (*merger->m_key_image)->m_hex) {
mergee->merge(mergee, merger); mergee->merge(mergee, merger);
merged = true; merged = true;
@@ -530,15 +530,15 @@ namespace monero {
// merge outputs // merge outputs
if (!other->m_outputs.empty()) { if (!other->m_outputs.empty()) {
for (const std::shared_ptr<monero_output>& output : other->m_outputs) output->m_tx = self; for (const std::shared_ptr<wownero_output>& output : other->m_outputs) output->m_tx = self;
if (m_outputs.empty()) m_outputs = other->m_outputs; if (m_outputs.empty()) m_outputs = other->m_outputs;
else { else {
// merge outputs if key image or stealth public key present, otherwise append // merge outputs if key image or stealth public key present, otherwise append
for (const std::shared_ptr<monero_output>& merger : other->m_outputs) { for (const std::shared_ptr<wownero_output>& merger : other->m_outputs) {
bool merged = false; bool merged = false;
merger->m_tx = self; merger->m_tx = self;
for (const std::shared_ptr<monero_output>& mergee : m_outputs) { for (const std::shared_ptr<wownero_output>& mergee : m_outputs) {
if ((merger->m_key_image != boost::none && (*mergee->m_key_image)->m_hex == (*merger->m_key_image)->m_hex) || if ((merger->m_key_image != boost::none && (*mergee->m_key_image)->m_hex == (*merger->m_key_image)->m_hex) ||
(merger->m_stealth_public_key != boost::none && *mergee->m_stealth_public_key == *merger->m_stealth_public_key)) { (merger->m_stealth_public_key != boost::none && *mergee->m_stealth_public_key == *merger->m_stealth_public_key)) {
mergee->merge(mergee, merger); mergee->merge(mergee, merger);
@@ -565,21 +565,21 @@ namespace monero {
// --------------------------- MONERO KEY IMAGE ----------------------------- // --------------------------- MONERO KEY IMAGE -----------------------------
rapidjson::Value monero_key_image::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_key_image::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// create root // create root
rapidjson::Value root(rapidjson::kObjectType); rapidjson::Value root(rapidjson::kObjectType);
// set string values // set string values
rapidjson::Value value_str(rapidjson::kStringType); rapidjson::Value value_str(rapidjson::kStringType);
if (m_hex != boost::none) monero_utils::add_json_member("hex", m_hex.get(), allocator, root, value_str); if (m_hex != boost::none) wownero_utils::add_json_member("hex", m_hex.get(), allocator, root, value_str);
if (m_signature != boost::none) monero_utils::add_json_member("signature", m_signature.get(), allocator, root, value_str); if (m_signature != boost::none) wownero_utils::add_json_member("signature", m_signature.get(), allocator, root, value_str);
// return root // return root
return root; return root;
} }
void monero_key_image::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_key_image>& key_image) { void wownero_key_image::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_key_image>& key_image) {
// initialize key image from node // initialize key image from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
@@ -589,7 +589,7 @@ namespace monero {
} }
} }
std::vector<std::shared_ptr<monero_key_image>> monero_key_image::deserialize_key_images(const std::string& key_images_json) { std::vector<std::shared_ptr<wownero_key_image>> wownero_key_image::deserialize_key_images(const std::string& key_images_json) {
// deserialize json to property node // deserialize json to property node
std::istringstream iss = key_images_json.empty() ? std::istringstream() : std::istringstream(key_images_json); std::istringstream iss = key_images_json.empty() ? std::istringstream() : std::istringstream(key_images_json);
@@ -597,13 +597,13 @@ namespace monero {
boost::property_tree::read_json(iss, node); boost::property_tree::read_json(iss, node);
// convert property tree to key images // convert property tree to key images
std::vector<std::shared_ptr<monero_key_image>> key_images; std::vector<std::shared_ptr<wownero_key_image>> key_images;
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
std::string key = it->first; std::string key = it->first;
if (key == std::string("keyImages")) { if (key == std::string("keyImages")) {
for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { for (boost::property_tree::ptree::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
std::shared_ptr<monero_key_image> key_image = std::make_shared<monero_key_image>(); std::shared_ptr<wownero_key_image> key_image = std::make_shared<wownero_key_image>();
monero_key_image::from_property_tree(it2->second, key_image); wownero_key_image::from_property_tree(it2->second, key_image);
key_images.push_back(key_image); key_images.push_back(key_image);
} }
} }
@@ -612,15 +612,15 @@ namespace monero {
return key_images; return key_images;
} }
std::shared_ptr<monero_key_image> monero_key_image::copy(const std::shared_ptr<monero_key_image>& src, const std::shared_ptr<monero_key_image>& tgt) const { std::shared_ptr<wownero_key_image> wownero_key_image::copy(const std::shared_ptr<wownero_key_image>& src, const std::shared_ptr<wownero_key_image>& tgt) const {
if (this != src.get()) throw std::runtime_error("this != src"); if (this != src.get()) throw std::runtime_error("this != src");
tgt->m_hex = src->m_hex; tgt->m_hex = src->m_hex;
tgt->m_signature = src->m_signature; tgt->m_signature = src->m_signature;
return tgt; return tgt;
} }
void monero_key_image::merge(const std::shared_ptr<monero_key_image>& self, const std::shared_ptr<monero_key_image>& other) { void wownero_key_image::merge(const std::shared_ptr<wownero_key_image>& self, const std::shared_ptr<wownero_key_image>& other) {
MTRACE("monero_key_image::merge(self, other)"); MTRACE("wownero_key_image::merge(self, other)");
if (this != self.get()) throw std::runtime_error("this != self"); if (this != self.get()) throw std::runtime_error("this != self");
if (self == other) return; if (self == other) return;
m_hex = gen_utils::reconcile(m_hex, other->m_hex, "key image m_hex"); m_hex = gen_utils::reconcile(m_hex, other->m_hex, "key image m_hex");
@@ -629,19 +629,19 @@ namespace monero {
// ------------------------------ MONERO OUTPUT ----------------------------- // ------------------------------ MONERO OUTPUT -----------------------------
rapidjson::Value monero_output::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const { rapidjson::Value wownero_output::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const {
// create root // create root
rapidjson::Value root(rapidjson::kObjectType); rapidjson::Value root(rapidjson::kObjectType);
// set num values // set num values
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
if (m_amount != boost::none) monero_utils::add_json_member("amount", m_amount.get(), allocator, root, value_num); if (m_amount != boost::none) wownero_utils::add_json_member("amount", m_amount.get(), allocator, root, value_num);
if (m_index != boost::none) monero_utils::add_json_member("index", m_index.get(), allocator, root, value_num); if (m_index != boost::none) wownero_utils::add_json_member("index", m_index.get(), allocator, root, value_num);
if (m_stealth_public_key != boost::none) monero_utils::add_json_member("stealthPublicKey", m_stealth_public_key.get(), allocator, root, value_num); if (m_stealth_public_key != boost::none) wownero_utils::add_json_member("stealthPublicKey", m_stealth_public_key.get(), allocator, root, value_num);
// set sub-arrays // set sub-arrays
if (!m_ring_output_indices.empty()) root.AddMember("ringOutputIndices", monero_utils::to_rapidjson_val(allocator, m_ring_output_indices), allocator); if (!m_ring_output_indices.empty()) root.AddMember("ringOutputIndices", wownero_utils::to_rapidjson_val(allocator, m_ring_output_indices), allocator);
// set sub-objects // set sub-objects
if (m_key_image != boost::none) root.AddMember("keyImage", m_key_image.get()->to_rapidjson_val(allocator), allocator); if (m_key_image != boost::none) root.AddMember("keyImage", m_key_image.get()->to_rapidjson_val(allocator), allocator);
@@ -650,14 +650,14 @@ namespace monero {
return root; return root;
} }
void monero_output::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output>& output) { void wownero_output::from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_output>& output) {
// initialize output from node // initialize output from node
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
std::string key = it->first; std::string key = it->first;
if (key == std::string("keyImage")) { if (key == std::string("keyImage")) {
output->m_key_image = std::make_shared<monero_key_image>(); output->m_key_image = std::make_shared<wownero_key_image>();
monero_key_image::from_property_tree(it->second, output->m_key_image.get()); wownero_key_image::from_property_tree(it->second, output->m_key_image.get());
} }
else if (key == std::string("amount")) output->m_amount = it->second.get_value<uint64_t>(); else if (key == std::string("amount")) output->m_amount = it->second.get_value<uint64_t>();
else if (key == std::string("index")) output->m_index = it->second.get_value<uint32_t>(); else if (key == std::string("index")) output->m_index = it->second.get_value<uint32_t>();
@@ -666,10 +666,10 @@ namespace monero {
} }
} }
std::shared_ptr<monero_output> monero_output::copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const { std::shared_ptr<wownero_output> wownero_output::copy(const std::shared_ptr<wownero_output>& src, const std::shared_ptr<wownero_output>& tgt) const {
if (this != src.get()) throw std::runtime_error("this != src"); if (this != src.get()) throw std::runtime_error("this != src");
tgt->m_tx = src->m_tx; // reference same parent tx by default tgt->m_tx = src->m_tx; // reference same parent tx by default
if (src->m_key_image != boost::none) tgt->m_key_image = src->m_key_image.get()->copy(src->m_key_image.get(), std::make_shared<monero_key_image>()); if (src->m_key_image != boost::none) tgt->m_key_image = src->m_key_image.get()->copy(src->m_key_image.get(), std::make_shared<wownero_key_image>());
tgt->m_amount = src->m_amount; tgt->m_amount = src->m_amount;
tgt->m_index = src->m_index; tgt->m_index = src->m_index;
if (!src->m_ring_output_indices.empty()) tgt->m_ring_output_indices = std::vector<uint64_t>(src->m_ring_output_indices); if (!src->m_ring_output_indices.empty()) tgt->m_ring_output_indices = std::vector<uint64_t>(src->m_ring_output_indices);
@@ -677,7 +677,7 @@ namespace monero {
return tgt; return tgt;
} }
void monero_output::merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other) { void wownero_output::merge(const std::shared_ptr<wownero_output>& self, const std::shared_ptr<wownero_output>& other) {
if (this != self.get()) throw std::runtime_error("this != self"); if (this != self.get()) throw std::runtime_error("this != self");
if (self == other) return; if (self == other) return;
@@ -61,7 +61,7 @@
/** /**
* Public interface for libmonero-cpp library. * Public interface for libmonero-cpp library.
*/ */
namespace monero { namespace wownero {
/** /**
* Base struct which can be serialized. * Base struct which can be serialized.
@@ -87,7 +87,7 @@ namespace monero {
/** /**
* Enumerates Monero network types. * Enumerates Monero network types.
*/ */
enum monero_network_type : uint8_t { enum wownero_network_type : uint8_t {
MAINNET = 0, MAINNET = 0,
TESTNET, TESTNET,
STAGENET STAGENET
@@ -96,7 +96,7 @@ namespace monero {
/** /**
* Models a Monero version. * Models a Monero version.
*/ */
struct monero_version : public serializable_struct { struct wownero_version : public serializable_struct {
boost::optional<uint32_t> m_number; boost::optional<uint32_t> m_number;
boost::optional<bool> m_is_release; boost::optional<bool> m_is_release;
@@ -106,26 +106,26 @@ namespace monero {
/** /**
* Models a connection to a daemon. * Models a connection to a daemon.
*/ */
struct monero_rpc_connection : public serializable_struct { struct wownero_rpc_connection : public serializable_struct {
boost::optional<std::string> m_uri; boost::optional<std::string> m_uri;
boost::optional<std::string> m_username; boost::optional<std::string> m_username;
boost::optional<std::string> m_password; boost::optional<std::string> m_password;
monero_rpc_connection(const std::string& uri = "", const std::string& username = "", const std::string& password = "") : m_uri(uri), m_username(username), m_password(password) {} wownero_rpc_connection(const std::string& uri = "", const std::string& username = "", const std::string& password = "") : m_uri(uri), m_username(username), m_password(password) {}
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static monero_rpc_connection from_property_tree(const boost::property_tree::ptree& node); static wownero_rpc_connection from_property_tree(const boost::property_tree::ptree& node);
}; };
// forward declarations // forward declarations
struct monero_tx; struct wownero_tx;
struct monero_output; struct wownero_output;
/** /**
* Models a Monero block header which contains information about the block. * Models a Monero block header which contains information about the block.
* *
* TODO: a header that is transmitted may have fewer fields like cryptonote::block_header; separate? * TODO: a header that is transmitted may have fewer fields like cryptonote::block_header; separate?
*/ */
struct monero_block_header : public serializable_struct { struct wownero_block_header : public serializable_struct {
boost::optional<std::string> m_hash; boost::optional<std::string> m_hash;
boost::optional<uint64_t> m_height; boost::optional<uint64_t> m_height;
boost::optional<uint64_t> m_timestamp; boost::optional<uint64_t> m_timestamp;
@@ -146,31 +146,31 @@ namespace monero {
boost::optional<std::string> m_pow_hash; boost::optional<std::string> m_pow_hash;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
std::shared_ptr<monero_block_header> copy(const std::shared_ptr<monero_block_header>& src, const std::shared_ptr<monero_block_header>& tgt) const; std::shared_ptr<wownero_block_header> copy(const std::shared_ptr<wownero_block_header>& src, const std::shared_ptr<wownero_block_header>& tgt) const;
virtual void merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other); virtual void merge(const std::shared_ptr<wownero_block_header>& self, const std::shared_ptr<wownero_block_header>& other);
}; };
/** /**
* Models a Monero block in the blockchain. * Models a Monero block in the blockchain.
*/ */
struct monero_block : public monero_block_header { struct wownero_block : public wownero_block_header {
boost::optional<std::string> m_hex; boost::optional<std::string> m_hex;
boost::optional<std::shared_ptr<monero_tx>> m_miner_tx; boost::optional<std::shared_ptr<wownero_tx>> m_miner_tx;
std::vector<std::shared_ptr<monero_tx>> m_txs; std::vector<std::shared_ptr<wownero_tx>> m_txs;
std::vector<std::string> m_tx_hashes; std::vector<std::string> m_tx_hashes;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
std::shared_ptr<monero_block> copy(const std::shared_ptr<monero_block>& src, const std::shared_ptr<monero_block>& tgt) const; std::shared_ptr<wownero_block> copy(const std::shared_ptr<wownero_block>& src, const std::shared_ptr<wownero_block>& tgt) const;
void merge(const std::shared_ptr<monero_block_header>& self, const std::shared_ptr<monero_block_header>& other); void merge(const std::shared_ptr<wownero_block_header>& self, const std::shared_ptr<wownero_block_header>& other);
void merge(const std::shared_ptr<monero_block>& self, const std::shared_ptr<monero_block>& other); void merge(const std::shared_ptr<wownero_block>& self, const std::shared_ptr<wownero_block>& other);
}; };
/** /**
* Models a Monero transaction on the blockchain. * Models a Monero transaction on the blockchain.
*/ */
struct monero_tx : public serializable_struct { struct wownero_tx : public serializable_struct {
static const std::string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000" static const std::string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000"
boost::optional<std::shared_ptr<monero_block>> m_block; boost::optional<std::shared_ptr<wownero_block>> m_block;
boost::optional<std::string> m_hash; boost::optional<std::string> m_hash;
boost::optional<uint32_t> m_version; boost::optional<uint32_t> m_version;
boost::optional<bool> m_is_miner_tx; boost::optional<bool> m_is_miner_tx;
@@ -193,8 +193,8 @@ namespace monero {
boost::optional<std::string> m_prunable_hash; boost::optional<std::string> m_prunable_hash;
boost::optional<uint64_t> m_size; boost::optional<uint64_t> m_size;
boost::optional<uint64_t> m_weight; boost::optional<uint64_t> m_weight;
std::vector<std::shared_ptr<monero_output>> m_inputs; std::vector<std::shared_ptr<wownero_output>> m_inputs;
std::vector<std::shared_ptr<monero_output>> m_outputs; std::vector<std::shared_ptr<wownero_output>> m_outputs;
std::vector<uint64_t> m_output_indices; std::vector<uint64_t> m_output_indices;
boost::optional<std::string> m_metadata; boost::optional<std::string> m_metadata;
boost::optional<std::string> m_common_tx_sets; boost::optional<std::string> m_common_tx_sets;
@@ -210,40 +210,40 @@ namespace monero {
std::vector<std::string> m_signatures; std::vector<std::string> m_signatures;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr<monero_tx> tx); static void from_property_tree(const boost::property_tree::ptree& node, std::shared_ptr<wownero_tx> tx);
std::shared_ptr<monero_tx> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const; std::shared_ptr<wownero_tx> copy(const std::shared_ptr<wownero_tx>& src, const std::shared_ptr<wownero_tx>& tgt) const;
virtual void merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other); virtual void merge(const std::shared_ptr<wownero_tx>& self, const std::shared_ptr<wownero_tx>& other);
boost::optional<uint64_t> get_height() const; boost::optional<uint64_t> get_height() const;
}; };
/** /**
* Models a Monero key image. * Models a Monero key image.
*/ */
struct monero_key_image : public serializable_struct { struct wownero_key_image : public serializable_struct {
boost::optional<std::string> m_hex; boost::optional<std::string> m_hex;
boost::optional<std::string> m_signature; boost::optional<std::string> m_signature;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_key_image>& key_image); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_key_image>& key_image);
static std::vector<std::shared_ptr<monero_key_image>> deserialize_key_images(const std::string& key_images_json); // TODO: remove this specialty util used once static std::vector<std::shared_ptr<wownero_key_image>> deserialize_key_images(const std::string& key_images_json); // TODO: remove this specialty util used once
std::shared_ptr<monero_key_image> copy(const std::shared_ptr<monero_key_image>& src, const std::shared_ptr<monero_key_image>& tgt) const; std::shared_ptr<wownero_key_image> copy(const std::shared_ptr<wownero_key_image>& src, const std::shared_ptr<wownero_key_image>& tgt) const;
void merge(const std::shared_ptr<monero_key_image>& self, const std::shared_ptr<monero_key_image>& other); void merge(const std::shared_ptr<wownero_key_image>& self, const std::shared_ptr<wownero_key_image>& other);
}; };
/** /**
* Models a Monero transaction output. * Models a Monero transaction output.
*/ */
struct monero_output : public serializable_struct { struct wownero_output : public serializable_struct {
std::shared_ptr<monero_tx> m_tx; std::shared_ptr<wownero_tx> m_tx;
boost::optional<std::shared_ptr<monero_key_image>> m_key_image; boost::optional<std::shared_ptr<wownero_key_image>> m_key_image;
boost::optional<uint64_t> m_amount; boost::optional<uint64_t> m_amount;
boost::optional<uint64_t> m_index; boost::optional<uint64_t> m_index;
std::vector<uint64_t> m_ring_output_indices; std::vector<uint64_t> m_ring_output_indices;
boost::optional<std::string> m_stealth_public_key; boost::optional<std::string> m_stealth_public_key;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output>& output); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_output>& output);
std::shared_ptr<monero_output> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const; std::shared_ptr<wownero_output> copy(const std::shared_ptr<wownero_output>& src, const std::shared_ptr<wownero_output>& tgt) const;
virtual void merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other); virtual void merge(const std::shared_ptr<wownero_output>& self, const std::shared_ptr<wownero_output>& other);
}; };
} }
+2
View File
@@ -0,0 +1,2 @@
file(GLOB HEADERS "*.h")
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wownero_cpp/utils)
@@ -50,7 +50,7 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/ */
#include "monero_utils.h" #include "wownero_utils.h"
#include "rpc/core_rpc_server_commands_defs.h" #include "rpc/core_rpc_server_commands_defs.h"
#include "storages/portable_storage_template_helper.h" #include "storages/portable_storage_template_helper.h"
#include "cryptonote_basic/cryptonote_format_utils.h" #include "cryptonote_basic/cryptonote_format_utils.h"
@@ -60,19 +60,19 @@
#include "byte_stream.h" #include "byte_stream.h"
using namespace cryptonote; using namespace cryptonote;
using namespace monero_utils; using namespace wownero_utils;
void monero_utils::set_log_level(int level) { void wownero_utils::set_log_level(int level) {
mlog_set_log_level(level); mlog_set_log_level(level);
} }
void monero_utils::configure_logging(const std::string& path, bool console) { void wownero_utils::configure_logging(const std::string& path, bool console) {
mlog_configure(path, console); mlog_configure(path, console);
} }
// --------------------------- VALIDATION UTILS ------------------------------- // --------------------------- VALIDATION UTILS -------------------------------
monero_integrated_address monero_utils::get_integrated_address(monero_network_type network_type, const std::string& standard_address, const std::string& payment_id) { wownero_integrated_address wownero_utils::get_integrated_address(wownero_network_type network_type, const std::string& standard_address, const std::string& payment_id) {
// parse and validate address // parse and validate address
cryptonote::address_parse_info address_info; cryptonote::address_parse_info address_info;
@@ -90,14 +90,14 @@ monero_integrated_address monero_utils::get_integrated_address(monero_network_ty
} }
// build integrated address // build integrated address
monero_integrated_address integrated_address; wownero_integrated_address integrated_address;
integrated_address.m_integrated_address = cryptonote::get_account_integrated_address_as_str(static_cast<cryptonote::network_type>(network_type), address_info.address, payment_id_h8); integrated_address.m_integrated_address = cryptonote::get_account_integrated_address_as_str(static_cast<cryptonote::network_type>(network_type), address_info.address, payment_id_h8);
integrated_address.m_standard_address = standard_address; integrated_address.m_standard_address = standard_address;
integrated_address.m_payment_id = epee::string_tools::pod_to_hex(payment_id_h8); integrated_address.m_payment_id = epee::string_tools::pod_to_hex(payment_id_h8);
return integrated_address; return integrated_address;
} }
bool monero_utils::is_valid_address(const std::string& address, monero_network_type network_type) { bool wownero_utils::is_valid_address(const std::string& address, wownero_network_type network_type) {
try { try {
validate_address(address, network_type); validate_address(address, network_type);
return true; return true;
@@ -106,7 +106,7 @@ bool monero_utils::is_valid_address(const std::string& address, monero_network_t
} }
} }
bool monero_utils::is_valid_private_view_key(const std::string& private_view_key) { bool wownero_utils::is_valid_private_view_key(const std::string& private_view_key) {
try { try {
validate_private_view_key(private_view_key); validate_private_view_key(private_view_key);
return true; return true;
@@ -115,7 +115,7 @@ bool monero_utils::is_valid_private_view_key(const std::string& private_view_key
} }
} }
bool monero_utils::is_valid_private_spend_key(const std::string& private_spend_key) { bool wownero_utils::is_valid_private_spend_key(const std::string& private_spend_key) {
try { try {
validate_private_spend_key(private_spend_key); validate_private_spend_key(private_spend_key);
return true; return true;
@@ -124,12 +124,12 @@ bool monero_utils::is_valid_private_spend_key(const std::string& private_spend_k
} }
} }
void monero_utils::validate_address(const std::string& address, monero_network_type network_type) { void wownero_utils::validate_address(const std::string& address, wownero_network_type network_type) {
cryptonote::address_parse_info info; cryptonote::address_parse_info info;
if (!get_account_address_from_str(info, static_cast<cryptonote::network_type>(network_type), address)) throw std::runtime_error("Invalid address"); if (!get_account_address_from_str(info, static_cast<cryptonote::network_type>(network_type), address)) throw std::runtime_error("Invalid address");
} }
void monero_utils::validate_private_view_key(const std::string& private_view_key) { void wownero_utils::validate_private_view_key(const std::string& private_view_key) {
if (private_view_key.length() != 64) throw std::runtime_error("private view key expected to be 64 hex characters"); if (private_view_key.length() != 64) throw std::runtime_error("private view key expected to be 64 hex characters");
cryptonote::blobdata private_view_key_data; cryptonote::blobdata private_view_key_data;
if (!epee::string_tools::parse_hexstr_to_binbuff(private_view_key, private_view_key_data) || private_view_key_data.size() != sizeof(crypto::secret_key)) { if (!epee::string_tools::parse_hexstr_to_binbuff(private_view_key, private_view_key_data) || private_view_key_data.size() != sizeof(crypto::secret_key)) {
@@ -137,7 +137,7 @@ void monero_utils::validate_private_view_key(const std::string& private_view_key
} }
} }
void monero_utils::validate_private_spend_key(const std::string& private_spend_key) { void wownero_utils::validate_private_spend_key(const std::string& private_spend_key) {
if (private_spend_key.length() != 64) throw std::runtime_error("private spend key expected to be 64 hex characters"); if (private_spend_key.length() != 64) throw std::runtime_error("private spend key expected to be 64 hex characters");
cryptonote::blobdata private_spend_key_data; cryptonote::blobdata private_spend_key_data;
if (!epee::string_tools::parse_hexstr_to_binbuff(private_spend_key, private_spend_key_data) || private_spend_key_data.size() != sizeof(crypto::secret_key)) { if (!epee::string_tools::parse_hexstr_to_binbuff(private_spend_key, private_spend_key_data) || private_spend_key_data.size() != sizeof(crypto::secret_key)) {
@@ -147,7 +147,7 @@ void monero_utils::validate_private_spend_key(const std::string& private_spend_k
// -------------------------- BINARY SERIALIZATION ---------------------------- // -------------------------- BINARY SERIALIZATION ----------------------------
void monero_utils::json_to_binary(const std::string &json, std::string &bin) { void wownero_utils::json_to_binary(const std::string &json, std::string &bin) {
epee::serialization::portable_storage ps; epee::serialization::portable_storage ps;
ps.load_from_json(json); ps.load_from_json(json);
epee::byte_stream bs; epee::byte_stream bs;
@@ -155,13 +155,13 @@ void monero_utils::json_to_binary(const std::string &json, std::string &bin) {
bin = std::string((char*) bs.data(), bs.size()); bin = std::string((char*) bs.data(), bs.size());
} }
void monero_utils::binary_to_json(const std::string &bin, std::string &json) { void wownero_utils::binary_to_json(const std::string &bin, std::string &json) {
epee::serialization::portable_storage ps; epee::serialization::portable_storage ps;
ps.load_from_binary(bin); ps.load_from_binary(bin);
ps.dump_as_json(json); ps.dump_as_json(json);
} }
void monero_utils::binary_blocks_to_json(const std::string &bin, std::string &json) { void wownero_utils::binary_blocks_to_json(const std::string &bin, std::string &json) {
// load binary rpc response to struct // load binary rpc response to struct
cryptonote::COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response resp_struct; cryptonote::COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response resp_struct;
@@ -193,8 +193,8 @@ void monero_utils::binary_blocks_to_json(const std::string &bin, std::string &js
// add tx node to txs node // add tx node to txs node
boost::property_tree::ptree txNode; boost::property_tree::ptree txNode;
//MTRACE("PRUNED:\n" << monero_utils::get_pruned_tx_json(tx)); //MTRACE("PRUNED:\n" << wownero_utils::get_pruned_tx_json(tx));
txNode.put("", monero_utils::get_pruned_tx_json(tx)); // TODO: no pretty print txNode.put("", wownero_utils::get_pruned_tx_json(tx)); // TODO: no pretty print
txs_node.push_back(std::make_pair("", txNode)); txs_node.push_back(std::make_pair("", txNode));
} else { } else {
throw std::runtime_error("failed to parse tx blob at index " + std::to_string(txIdx)); throw std::runtime_error("failed to parse tx blob at index " + std::to_string(txIdx));
@@ -215,20 +215,20 @@ void monero_utils::binary_blocks_to_json(const std::string &bin, std::string &js
// ------------------------------- RAPIDJSON ---------------------------------- // ------------------------------- RAPIDJSON ----------------------------------
std::string monero_utils::serialize(const rapidjson::Document& doc) { std::string wownero_utils::serialize(const rapidjson::Document& doc) {
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
doc.Accept(writer); doc.Accept(writer);
return buffer.GetString(); return buffer.GetString();
} }
void monero_utils::add_json_member(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) { void wownero_utils::add_json_member(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field) {
rapidjson::Value field_key(key.c_str(), key.size(), allocator); rapidjson::Value field_key(key.c_str(), key.size(), allocator);
field.SetString(val.c_str(), val.size(), allocator); field.SetString(val.c_str(), val.size(), allocator);
root.AddMember(field_key, field, allocator); root.AddMember(field_key, field, allocator);
} }
void monero_utils::add_json_member(std::string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root) { void wownero_utils::add_json_member(std::string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root) {
rapidjson::Value field_key(key.c_str(), key.size(), allocator); rapidjson::Value field_key(key.c_str(), key.size(), allocator);
if (val) { if (val) {
rapidjson::Value field_val(rapidjson::kTrueType); rapidjson::Value field_val(rapidjson::kTrueType);
@@ -239,7 +239,7 @@ void monero_utils::add_json_member(std::string key, bool val, rapidjson::Documen
} }
} }
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::string>& strs) { rapidjson::Value wownero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::string>& strs) {
rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_str(rapidjson::kStringType); rapidjson::Value value_str(rapidjson::kStringType);
for (const std::string& str : strs) { for (const std::string& str : strs) {
@@ -249,7 +249,7 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy
return value_arr; return value_arr;
} }
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint8_t>& nums) { rapidjson::Value wownero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint8_t>& nums) {
rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
for (const auto& num : nums) { for (const auto& num : nums) {
@@ -260,7 +260,7 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy
} }
// TODO: remove these redundant implementations for different sizes? // TODO: remove these redundant implementations for different sizes?
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint32_t>& nums) { rapidjson::Value wownero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint32_t>& nums) {
rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
for (const auto& num : nums) { for (const auto& num : nums) {
@@ -270,7 +270,7 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy
return value_arr; return value_arr;
} }
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint64_t>& nums) { rapidjson::Value wownero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<uint64_t>& nums) {
rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_num(rapidjson::kNumberType); rapidjson::Value value_num(rapidjson::kNumberType);
for (const auto& num : nums) { for (const auto& num : nums) {
@@ -282,14 +282,14 @@ rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorTy
// ------------------------ PROPERTY TREES --------------------------- // ------------------------ PROPERTY TREES ---------------------------
std::string monero_utils::serialize(const boost::property_tree::ptree& node) { std::string wownero_utils::serialize(const boost::property_tree::ptree& node) {
std::stringstream ss; std::stringstream ss;
boost::property_tree::write_json(ss, node, false); boost::property_tree::write_json(ss, node, false);
std::string str = ss.str(); std::string str = ss.str();
return str.substr(0, str.size() - 1); // strip newline return str.substr(0, str.size() - 1); // strip newline
} }
void monero_utils::deserialize(const std::string& json, boost::property_tree::ptree& root) { void wownero_utils::deserialize(const std::string& json, boost::property_tree::ptree& root) {
std::istringstream iss = json.empty() ? std::istringstream() : std::istringstream(json); std::istringstream iss = json.empty() ? std::istringstream() : std::istringstream(json);
try { try {
boost::property_tree::read_json(iss, root); boost::property_tree::read_json(iss, root);
@@ -300,7 +300,7 @@ void monero_utils::deserialize(const std::string& json, boost::property_tree::pt
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool monero_utils::is_valid_language(const std::string& language) { bool wownero_utils::is_valid_language(const std::string& language) {
std::vector<std::string> languages; std::vector<std::string> languages;
crypto::ElectrumWords::get_language_list(languages, false); crypto::ElectrumWords::get_language_list(languages, false);
std::vector<std::string>::iterator it = std::find(languages.begin(), languages.end(), language); std::vector<std::string>::iterator it = std::find(languages.begin(), languages.end(), language);
@@ -313,24 +313,24 @@ bool monero_utils::is_valid_language(const std::string& language) {
} }
// TODO: this is unused // TODO: this is unused
std::shared_ptr<monero_block> monero_utils::cn_block_to_block(const cryptonote::block& cn_block) { std::shared_ptr<wownero_block> wownero_utils::cn_block_to_block(const cryptonote::block& cn_block) {
cryptonote::block temp = cn_block; cryptonote::block temp = cn_block;
std::cout << cryptonote::obj_to_json_str(temp) << std::endl; std::cout << cryptonote::obj_to_json_str(temp) << std::endl;
std::shared_ptr<monero_block> block = std::make_shared<monero_block>(); std::shared_ptr<wownero_block> block = std::make_shared<wownero_block>();
block->m_major_version = cn_block.major_version; block->m_major_version = cn_block.major_version;
block->m_minor_version = cn_block.minor_version; block->m_minor_version = cn_block.minor_version;
block->m_timestamp = cn_block.timestamp; block->m_timestamp = cn_block.timestamp;
block->m_prev_hash = epee::string_tools::pod_to_hex(cn_block.prev_id); block->m_prev_hash = epee::string_tools::pod_to_hex(cn_block.prev_id);
block->m_nonce = cn_block.nonce; block->m_nonce = cn_block.nonce;
block->m_miner_tx = monero_utils::cn_tx_to_tx(cn_block.miner_tx); block->m_miner_tx = wownero_utils::cn_tx_to_tx(cn_block.miner_tx);
for (const crypto::hash& tx_hash : cn_block.tx_hashes) { for (const crypto::hash& tx_hash : cn_block.tx_hashes) {
block->m_tx_hashes.push_back(epee::string_tools::pod_to_hex(tx_hash)); block->m_tx_hashes.push_back(epee::string_tools::pod_to_hex(tx_hash));
} }
return block; return block;
} }
std::shared_ptr<monero_tx> monero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) { std::shared_ptr<wownero_tx> wownero_utils::cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet) {
std::shared_ptr<monero_tx> tx = init_as_tx_wallet ? std::make_shared<monero_tx_wallet>() : std::make_shared<monero_tx>(); std::shared_ptr<wownero_tx> tx = init_as_tx_wallet ? std::make_shared<wownero_tx_wallet>() : std::make_shared<wownero_tx>();
tx->m_version = cn_tx.version; tx->m_version = cn_tx.version;
tx->m_unlock_time = cn_tx.unlock_time; tx->m_unlock_time = cn_tx.unlock_time;
tx->m_hash = epee::string_tools::pod_to_hex(cn_tx.hash); tx->m_hash = epee::string_tools::pod_to_hex(cn_tx.hash);
@@ -341,20 +341,20 @@ std::shared_ptr<monero_tx> monero_utils::cn_tx_to_tx(const cryptonote::transacti
if (cnVin.which() != 0 && cnVin.which() != 3) throw std::runtime_error("Unsupported variant type"); if (cnVin.which() != 0 && cnVin.which() != 3) throw std::runtime_error("Unsupported variant type");
if (tx->m_is_miner_tx == boost::none) tx->m_is_miner_tx = cnVin.which() == 0; if (tx->m_is_miner_tx == boost::none) tx->m_is_miner_tx = cnVin.which() == 0;
if (cnVin.which() != 3) continue; // only process txin_to_key of variant TODO: support other types, like 0 "gen" which is miner tx? if (cnVin.which() != 3) continue; // only process txin_to_key of variant TODO: support other types, like 0 "gen" which is miner tx?
std::shared_ptr<monero_output> input = init_as_tx_wallet ? std::make_shared<monero_output_wallet>() : std::make_shared<monero_output>(); std::shared_ptr<wownero_output> input = init_as_tx_wallet ? std::make_shared<wownero_output_wallet>() : std::make_shared<wownero_output>();
input->m_tx = tx; input->m_tx = tx;
tx->m_inputs.push_back(input); tx->m_inputs.push_back(input);
const txin_to_key& txin = boost::get<txin_to_key>(cnVin); const txin_to_key& txin = boost::get<txin_to_key>(cnVin);
input->m_amount = txin.amount; input->m_amount = txin.amount;
input->m_ring_output_indices = txin.key_offsets; input->m_ring_output_indices = txin.key_offsets;
crypto::key_image cnKeyImage = txin.k_image; crypto::key_image cnKeyImage = txin.k_image;
input->m_key_image = std::make_shared<monero_key_image>(); input->m_key_image = std::make_shared<wownero_key_image>();
input->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(cnKeyImage); input->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(cnKeyImage);
} }
// init outputs // init outputs
for (const tx_out& cnVout : cn_tx.vout) { for (const tx_out& cnVout : cn_tx.vout) {
std::shared_ptr<monero_output> output = init_as_tx_wallet ? std::make_shared<monero_output_wallet>() : std::make_shared<monero_output>(); std::shared_ptr<wownero_output> output = init_as_tx_wallet ? std::make_shared<wownero_output_wallet>() : std::make_shared<wownero_output>();
output->m_tx = tx; output->m_tx = tx;
tx->m_outputs.push_back(output); tx->m_outputs.push_back(output);
output->m_amount = cnVout.amount; output->m_amount = cnVout.amount;
@@ -52,10 +52,10 @@
#pragma once #pragma once
#ifndef monero_utils_h #ifndef wownero_utils_h
#define monero_utils_h #define wownero_utils_h
#include "wallet/monero_wallet_model.h" #include "wallet/wownero_wallet_model.h"
#include "cryptonote_basic/cryptonote_basic.h" #include "cryptonote_basic/cryptonote_basic.h"
#include "serialization/keyvalue_serialization.h" // TODO: consolidate with other binary deps? #include "serialization/keyvalue_serialization.h" // TODO: consolidate with other binary deps?
#include "storages/portable_storage.h" #include "storages/portable_storage.h"
@@ -63,7 +63,7 @@
/** /**
* Collection of utilities for the Monero library. * Collection of utilities for the Monero library.
*/ */
namespace monero_utils namespace wownero_utils
{ {
using namespace cryptonote; using namespace cryptonote;
@@ -75,11 +75,11 @@ namespace monero_utils
void set_log_level(int level); void set_log_level(int level);
void configure_logging(const std::string& path, bool console); void configure_logging(const std::string& path, bool console);
monero_integrated_address get_integrated_address(monero_network_type network_type, const std::string& standard_address, const std::string& payment_id); wownero_integrated_address get_integrated_address(wownero_network_type network_type, const std::string& standard_address, const std::string& payment_id);
bool is_valid_address(const std::string& address, monero_network_type network_type); bool is_valid_address(const std::string& address, wownero_network_type network_type);
bool is_valid_private_view_key(const std::string& private_view_key); bool is_valid_private_view_key(const std::string& private_view_key);
bool is_valid_private_spend_key(const std::string& private_spend_key); bool is_valid_private_spend_key(const std::string& private_spend_key);
void validate_address(const std::string& address, monero_network_type network_type); void validate_address(const std::string& address, wownero_network_type network_type);
void validate_private_view_key(const std::string& private_view_key); void validate_private_view_key(const std::string& private_view_key);
void validate_private_spend_key(const std::string& private_spend_key); void validate_private_spend_key(const std::string& private_spend_key);
void json_to_binary(const std::string &json, std::string &bin); void json_to_binary(const std::string &json, std::string &bin);
@@ -104,7 +104,7 @@ namespace monero_utils
void add_json_member(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field); void add_json_member(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field);
void add_json_member(std::string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root); void add_json_member(std::string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root);
// TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation // TODO: template implementation here, could move to wownero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::shared_ptr<T>>& vals) { template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<std::shared_ptr<T>>& vals) {
rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_arr(rapidjson::kArrayType);
for (const auto& val : vals) { for (const auto& val : vals) {
@@ -113,7 +113,7 @@ namespace monero_utils
return value_arr; return value_arr;
} }
// TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation // TODO: template implementation here, could move to wownero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<T>& vals) { template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const std::vector<T>& vals) {
rapidjson::Value value_arr(rapidjson::kArrayType); rapidjson::Value value_arr(rapidjson::kArrayType);
for (const auto& val : vals) { for (const auto& val : vals) {
@@ -150,16 +150,16 @@ namespace monero_utils
* @param cn_block is the block to convert * @param cn_block is the block to convert
* @return a block in this library's native model * @return a block in this library's native model
*/ */
std::shared_ptr<monero_block> cn_block_to_block(const cryptonote::block& cn_block); std::shared_ptr<wownero_block> cn_block_to_block(const cryptonote::block& cn_block);
/** /**
* Convert a cryptonote::transaction to a transaction in this library's * Convert a cryptonote::transaction to a transaction in this library's
* native model. * native model.
* *
* @param cn_tx is the transaction to convert * @param cn_tx is the transaction to convert
* @param init_as_tx_wallet specifies if a monero_tx xor monero_tx_wallet should be initialized * @param init_as_tx_wallet specifies if a wownero_tx xor wownero_tx_wallet should be initialized
*/ */
std::shared_ptr<monero_tx> cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet = false); std::shared_ptr<wownero_tx> cn_tx_to_tx(const cryptonote::transaction& cn_tx, bool init_as_tx_wallet = false);
/** /**
* Modified from core_rpc_server.cpp to return a std::string. * Modified from core_rpc_server.cpp to return a std::string.
@@ -177,17 +177,17 @@ namespace monero_utils
// ----------------------------- GATHER BLOCKS ------------------------------ // ----------------------------- GATHER BLOCKS ------------------------------
static std::vector<std::shared_ptr<monero_block>> get_blocks_from_txs(std::vector<std::shared_ptr<monero_tx_wallet>> txs) { static std::vector<std::shared_ptr<wownero_block>> get_blocks_from_txs(std::vector<std::shared_ptr<wownero_tx_wallet>> txs) {
std::shared_ptr<monero_block> unconfirmed_block = nullptr; // placeholder for unconfirmed txs std::shared_ptr<wownero_block> unconfirmed_block = nullptr; // placeholder for unconfirmed txs
std::vector<std::shared_ptr<monero_block>> blocks; std::vector<std::shared_ptr<wownero_block>> blocks;
std::unordered_set<std::shared_ptr<monero_block>> seen_block_ptrs; std::unordered_set<std::shared_ptr<wownero_block>> seen_block_ptrs;
for (const std::shared_ptr<monero_tx_wallet>& tx : txs) { for (const std::shared_ptr<wownero_tx_wallet>& tx : txs) {
if (tx->m_block == boost::none) { if (tx->m_block == boost::none) {
if (unconfirmed_block == nullptr) unconfirmed_block = std::make_shared<monero_block>(); if (unconfirmed_block == nullptr) unconfirmed_block = std::make_shared<wownero_block>();
tx->m_block = unconfirmed_block; tx->m_block = unconfirmed_block;
unconfirmed_block->m_txs.push_back(tx); unconfirmed_block->m_txs.push_back(tx);
} }
std::unordered_set<std::shared_ptr<monero_block>>::const_iterator got = seen_block_ptrs.find(tx->m_block.get()); std::unordered_set<std::shared_ptr<wownero_block>>::const_iterator got = seen_block_ptrs.find(tx->m_block.get());
if (got == seen_block_ptrs.end()) { if (got == seen_block_ptrs.end()) {
seen_block_ptrs.insert(tx->m_block.get()); seen_block_ptrs.insert(tx->m_block.get());
blocks.push_back(tx->m_block.get()); blocks.push_back(tx->m_block.get());
@@ -196,18 +196,18 @@ namespace monero_utils
return blocks; return blocks;
} }
static std::vector<std::shared_ptr<monero_block>> get_blocks_from_transfers(std::vector<std::shared_ptr<monero_transfer>> transfers) { static std::vector<std::shared_ptr<wownero_block>> get_blocks_from_transfers(std::vector<std::shared_ptr<wownero_transfer>> transfers) {
std::shared_ptr<monero_block> unconfirmed_block = nullptr; // placeholder for unconfirmed txs in return json std::shared_ptr<wownero_block> unconfirmed_block = nullptr; // placeholder for unconfirmed txs in return json
std::vector<std::shared_ptr<monero_block>> blocks; std::vector<std::shared_ptr<wownero_block>> blocks;
std::unordered_set<std::shared_ptr<monero_block>> seen_block_ptrs; std::unordered_set<std::shared_ptr<wownero_block>> seen_block_ptrs;
for (auto const& transfer : transfers) { for (auto const& transfer : transfers) {
std::shared_ptr<monero_tx_wallet> tx = transfer->m_tx; std::shared_ptr<wownero_tx_wallet> tx = transfer->m_tx;
if (tx->m_block == boost::none) { if (tx->m_block == boost::none) {
if (unconfirmed_block == nullptr) unconfirmed_block = std::make_shared<monero_block>(); if (unconfirmed_block == nullptr) unconfirmed_block = std::make_shared<wownero_block>();
tx->m_block = unconfirmed_block; tx->m_block = unconfirmed_block;
unconfirmed_block->m_txs.push_back(tx); unconfirmed_block->m_txs.push_back(tx);
} }
std::unordered_set<std::shared_ptr<monero_block>>::const_iterator got = seen_block_ptrs.find(tx->m_block.get()); std::unordered_set<std::shared_ptr<wownero_block>>::const_iterator got = seen_block_ptrs.find(tx->m_block.get());
if (got == seen_block_ptrs.end()) { if (got == seen_block_ptrs.end()) {
seen_block_ptrs.insert(tx->m_block.get()); seen_block_ptrs.insert(tx->m_block.get());
blocks.push_back(tx->m_block.get()); blocks.push_back(tx->m_block.get());
@@ -216,13 +216,13 @@ namespace monero_utils
return blocks; return blocks;
} }
static std::vector<std::shared_ptr<monero_block>> get_blocks_from_outputs(std::vector<std::shared_ptr<monero_output_wallet>> outputs) { static std::vector<std::shared_ptr<wownero_block>> get_blocks_from_outputs(std::vector<std::shared_ptr<wownero_output_wallet>> outputs) {
std::vector<std::shared_ptr<monero_block>> blocks; std::vector<std::shared_ptr<wownero_block>> blocks;
std::unordered_set<std::shared_ptr<monero_block>> seen_block_ptrs; std::unordered_set<std::shared_ptr<wownero_block>> seen_block_ptrs;
for (auto const& output : outputs) { for (auto const& output : outputs) {
std::shared_ptr<monero_tx_wallet> tx = std::static_pointer_cast<monero_tx_wallet>(output->m_tx); std::shared_ptr<wownero_tx_wallet> tx = std::static_pointer_cast<wownero_tx_wallet>(output->m_tx);
if (tx->m_block == boost::none) throw std::runtime_error("Need to handle unconfirmed output"); if (tx->m_block == boost::none) throw std::runtime_error("Need to handle unconfirmed output");
std::unordered_set<std::shared_ptr<monero_block>>::const_iterator got = seen_block_ptrs.find(*tx->m_block); std::unordered_set<std::shared_ptr<wownero_block>>::const_iterator got = seen_block_ptrs.find(*tx->m_block);
if (got == seen_block_ptrs.end()) { if (got == seen_block_ptrs.end()) {
seen_block_ptrs.insert(*tx->m_block); seen_block_ptrs.insert(*tx->m_block);
blocks.push_back(*tx->m_block); blocks.push_back(*tx->m_block);
@@ -233,21 +233,21 @@ namespace monero_utils
// ------------------------------ FREE MEMORY ------------------------------- // ------------------------------ FREE MEMORY -------------------------------
static void free(std::shared_ptr<monero_block> block) { static void free(std::shared_ptr<wownero_block> block) {
for (std::shared_ptr<monero_tx>& tx : block->m_txs) { for (std::shared_ptr<wownero_tx>& tx : block->m_txs) {
tx->m_block->reset(); tx->m_block->reset();
monero_tx_wallet* tx_wallet = dynamic_cast<monero_tx_wallet*>(tx.get()); wownero_tx_wallet* tx_wallet = dynamic_cast<wownero_tx_wallet*>(tx.get());
if (tx_wallet != nullptr) { if (tx_wallet != nullptr) {
if (tx_wallet->m_tx_set != boost::none) tx_wallet->m_tx_set->reset(); if (tx_wallet->m_tx_set != boost::none) tx_wallet->m_tx_set->reset();
if (tx_wallet->m_outgoing_transfer != boost::none) tx_wallet->m_outgoing_transfer.get()->m_tx.reset(); if (tx_wallet->m_outgoing_transfer != boost::none) tx_wallet->m_outgoing_transfer.get()->m_tx.reset();
for (std::shared_ptr<monero_transfer> transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset(); for (std::shared_ptr<wownero_transfer> transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset();
for (std::shared_ptr<monero_output> output : tx_wallet->m_outputs) output->m_tx.reset(); for (std::shared_ptr<wownero_output> output : tx_wallet->m_outputs) output->m_tx.reset();
for (std::shared_ptr<monero_output> input : tx_wallet->m_inputs) { for (std::shared_ptr<wownero_output> input : tx_wallet->m_inputs) {
input->m_key_image.reset(); input->m_key_image.reset();
input->m_tx.reset(); input->m_tx.reset();
} }
} }
monero_tx_query* tx_query = dynamic_cast<monero_tx_query*>(tx.get()); wownero_tx_query* tx_query = dynamic_cast<wownero_tx_query*>(tx.get());
if (tx_query != nullptr) { if (tx_query != nullptr) {
if (tx_query->m_transfer_query != boost::none) { if (tx_query->m_transfer_query != boost::none) {
tx_query->m_transfer_query.get()->m_tx_query->reset(); tx_query->m_transfer_query.get()->m_tx_query->reset();
@@ -262,29 +262,29 @@ namespace monero_utils
block.reset(); block.reset();
} }
static void free(std::vector<std::shared_ptr<monero_block>> blocks) { static void free(std::vector<std::shared_ptr<wownero_block>> blocks) {
for (std::shared_ptr<monero_block>& block : blocks) monero_utils::free(block); for (std::shared_ptr<wownero_block>& block : blocks) wownero_utils::free(block);
} }
static void free(std::shared_ptr<monero_tx> tx) { static void free(std::shared_ptr<wownero_tx> tx) {
if (tx->m_block == boost::none) { if (tx->m_block == boost::none) {
std::shared_ptr<monero_block> block = std::make_shared<monero_block>(); std::shared_ptr<wownero_block> block = std::make_shared<wownero_block>();
tx->m_block = block; tx->m_block = block;
block->m_txs.push_back(tx); block->m_txs.push_back(tx);
} }
monero_utils::free(tx->m_block.get()); wownero_utils::free(tx->m_block.get());
} }
static void free(std::vector<std::shared_ptr<monero_tx_wallet>> txs) { static void free(std::vector<std::shared_ptr<wownero_tx_wallet>> txs) {
return monero_utils::free(monero_utils::get_blocks_from_txs(txs)); return wownero_utils::free(wownero_utils::get_blocks_from_txs(txs));
} }
static void free(std::vector<std::shared_ptr<monero_transfer>> transfers) { static void free(std::vector<std::shared_ptr<wownero_transfer>> transfers) {
return monero_utils::free(monero_utils::get_blocks_from_transfers(transfers)); return wownero_utils::free(wownero_utils::get_blocks_from_transfers(transfers));
} }
static void free(std::vector<std::shared_ptr<monero_output_wallet>> outputs) { static void free(std::vector<std::shared_ptr<wownero_output_wallet>> outputs) {
return monero_utils::free(monero_utils::get_blocks_from_outputs(outputs)); return wownero_utils::free(wownero_utils::get_blocks_from_outputs(outputs));
} }
} }
#endif /* monero_utils_h */ #endif /* wownero_utils_h */
+2
View File
@@ -0,0 +1,2 @@
file(GLOB HEADERS "*.h")
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wownero_cpp/wallet)
@@ -52,23 +52,23 @@
#pragma once #pragma once
#include "monero_wallet_model.h" #include "wownero_wallet_model.h"
#include <vector> #include <vector>
#include <set> #include <set>
using namespace monero; using namespace wownero;
/** /**
* Public library interface. * Public library interface.
*/ */
namespace monero { namespace wownero {
// --------------------------------- LISTENERS ------------------------------ // --------------------------------- LISTENERS ------------------------------
/** /**
* Interface to receive wallet notifications. * Interface to receive wallet notifications.
*/ */
class monero_wallet_listener { class wownero_wallet_listener {
public: public:
/** /**
@@ -102,14 +102,14 @@ namespace monero {
* *
* @param output - the received output * @param output - the received output
*/ */
virtual void on_output_received(const monero_output_wallet& output) {}; virtual void on_output_received(const wownero_output_wallet& output) {};
/** /**
* Invoked when the wallet spends an output. * Invoked when the wallet spends an output.
* *
* @param output - the spent output * @param output - the spent output
*/ */
virtual void on_output_spent(const monero_output_wallet& output) {}; virtual void on_output_spent(const wownero_output_wallet& output) {};
}; };
// forward declaration of internal wallet2 listener // forward declaration of internal wallet2 listener
@@ -120,14 +120,14 @@ namespace monero {
/** /**
* Base wallet with default implementations. * Base wallet with default implementations.
*/ */
class monero_wallet { class wownero_wallet {
public: public:
/** /**
* Virtual destructor. * Virtual destructor.
*/ */
virtual ~monero_wallet() {} virtual ~wownero_wallet() {}
/** /**
* Indicates if the wallet is view-only, meaning it does have the private * Indicates if the wallet is view-only, meaning it does have the private
@@ -155,7 +155,7 @@ namespace monero {
* *
* @param connection is the connection to set * @param connection is the connection to set
*/ */
virtual void set_daemon_connection(const boost::optional<monero_rpc_connection>& connection) { virtual void set_daemon_connection(const boost::optional<wownero_rpc_connection>& connection) {
throw std::runtime_error("set_daemon_connection() not supported"); throw std::runtime_error("set_daemon_connection() not supported");
} }
@@ -171,7 +171,7 @@ namespace monero {
* *
* @return the wallet's daemon connection * @return the wallet's daemon connection
*/ */
virtual boost::optional<monero_rpc_connection> get_daemon_connection() const { virtual boost::optional<wownero_rpc_connection> get_daemon_connection() const {
throw std::runtime_error("get_daemon_connection() not supported"); throw std::runtime_error("get_daemon_connection() not supported");
} }
@@ -216,7 +216,7 @@ namespace monero {
* *
* @return the wallet's version * @return the wallet's version
*/ */
virtual monero_version get_version() const { virtual wownero_version get_version() const {
throw std::runtime_error("get_version() not supported"); throw std::runtime_error("get_version() not supported");
} }
@@ -234,7 +234,7 @@ namespace monero {
* *
* @return the wallet's network type * @return the wallet's network type
*/ */
virtual monero_network_type get_network_type() const { virtual wownero_network_type get_network_type() const {
throw std::runtime_error("get_network_type() not supported"); throw std::runtime_error("get_network_type() not supported");
} }
@@ -319,7 +319,7 @@ namespace monero {
* @return the account and subaddress indices * @return the account and subaddress indices
* @throws exception if address is not a wallet address * @throws exception if address is not a wallet address
*/ */
virtual monero_subaddress get_address_index(const std::string& address) const { virtual wownero_subaddress get_address_index(const std::string& address) const {
throw std::runtime_error("get_address_index() not supported"); throw std::runtime_error("get_address_index() not supported");
} }
@@ -330,7 +330,7 @@ namespace monero {
* @param payment_id is the integrated addresse's payment id (defaults to randomly generating new payment id) * @param payment_id is the integrated addresse's payment id (defaults to randomly generating new payment id)
* @return the integrated address * @return the integrated address
*/ */
virtual monero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const { virtual wownero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const {
throw std::runtime_error("get_integrated_address() not supported"); throw std::runtime_error("get_integrated_address() not supported");
} }
@@ -340,7 +340,7 @@ namespace monero {
* @param integrated_address is an integrated address to decode * @param integrated_address is an integrated address to decode
* @return the decoded integrated address including standard address and payment id * @return the decoded integrated address including standard address and payment id
*/ */
virtual monero_integrated_address decode_integrated_address(const std::string& integrated_address) const { virtual wownero_integrated_address decode_integrated_address(const std::string& integrated_address) const {
throw std::runtime_error("decode_integrated_address() not supported"); throw std::runtime_error("decode_integrated_address() not supported");
} }
@@ -406,7 +406,7 @@ namespace monero {
* *
* @param listener is the listener to receive wallet notifications * @param listener is the listener to receive wallet notifications
*/ */
virtual void add_listener(monero_wallet_listener& listener) { virtual void add_listener(wownero_wallet_listener& listener) {
throw std::runtime_error("add_listener() not supported"); throw std::runtime_error("add_listener() not supported");
} }
@@ -415,14 +415,14 @@ namespace monero {
* *
* @param listener is the listener to unregister * @param listener is the listener to unregister
*/ */
virtual void remove_listener(monero_wallet_listener& listener) { virtual void remove_listener(wownero_wallet_listener& listener) {
throw std::runtime_error("remove_listener() not supported"); throw std::runtime_error("remove_listener() not supported");
} }
/** /**
* Get the listeners registered with the wallet. * Get the listeners registered with the wallet.
*/ */
virtual std::set<monero_wallet_listener*> get_listeners() { virtual std::set<wownero_wallet_listener*> get_listeners() {
throw std::runtime_error("get_listeners() not supported"); throw std::runtime_error("get_listeners() not supported");
} }
@@ -431,7 +431,7 @@ namespace monero {
* *
* @return the sync result * @return the sync result
*/ */
virtual monero_sync_result sync() { virtual wownero_sync_result sync() {
throw std::runtime_error("sync() not supported"); throw std::runtime_error("sync() not supported");
} }
@@ -441,7 +441,7 @@ namespace monero {
* @param listener - listener to receive notifications during synchronization * @param listener - listener to receive notifications during synchronization
* @return the sync result * @return the sync result
*/ */
virtual monero_sync_result sync(monero_wallet_listener& listener) { virtual wownero_sync_result sync(wownero_wallet_listener& listener) {
throw std::runtime_error("sync() not supported"); throw std::runtime_error("sync() not supported");
} }
@@ -451,7 +451,7 @@ namespace monero {
* @param start_height is the start height to sync from (ignored if less than last processed block) * @param start_height is the start height to sync from (ignored if less than last processed block)
* @return the sync result * @return the sync result
*/ */
virtual monero_sync_result sync(uint64_t start_height) { virtual wownero_sync_result sync(uint64_t start_height) {
throw std::runtime_error("sync() not supported"); throw std::runtime_error("sync() not supported");
} }
@@ -462,7 +462,7 @@ namespace monero {
* @param listener - listener to receive notifications during synchronization * @param listener - listener to receive notifications during synchronization
* @return the sync result * @return the sync result
*/ */
virtual monero_sync_result sync(uint64_t start_height, monero_wallet_listener& listener) { virtual wownero_sync_result sync(uint64_t start_height, wownero_wallet_listener& listener) {
throw std::runtime_error("sync() not supported"); throw std::runtime_error("sync() not supported");
} }
@@ -578,9 +578,9 @@ namespace monero {
/** /**
* Get all accounts. * Get all accounts.
* *
* @return List<monero_account> are all accounts within the wallet * @return List<wownero_account> are all accounts within the wallet
*/ */
virtual std::vector<monero_account> get_accounts() const { virtual std::vector<wownero_account> get_accounts() const {
return get_accounts(false, std::string("")); return get_accounts(false, std::string(""));
} }
@@ -588,9 +588,9 @@ namespace monero {
* Get all accounts. * Get all accounts.
* *
* @param include_subaddresses specifies if subaddresses should be included * @param include_subaddresses specifies if subaddresses should be included
* @return List<monero_account> are all accounts * @return List<wownero_account> are all accounts
*/ */
virtual std::vector<monero_account> get_accounts(bool include_subaddresses) const { virtual std::vector<wownero_account> get_accounts(bool include_subaddresses) const {
return get_accounts(include_subaddresses, ""); return get_accounts(include_subaddresses, "");
} }
@@ -598,9 +598,9 @@ namespace monero {
* Get accounts with a given tag. * Get accounts with a given tag.
* *
* @param tag is the tag for filtering accounts, all accounts if null * @param tag is the tag for filtering accounts, all accounts if null
* @return List<monero_account> are all accounts for the wallet with the given tag * @return List<wownero_account> are all accounts for the wallet with the given tag
*/ */
virtual std::vector<monero_account> get_accounts(const std::string& tag) const { virtual std::vector<wownero_account> get_accounts(const std::string& tag) const {
return get_accounts(false, tag); return get_accounts(false, tag);
} }
@@ -609,9 +609,9 @@ namespace monero {
* *
* @param include_subaddresses specifies if subaddresses should be included * @param include_subaddresses specifies if subaddresses should be included
* @param tag is the tag for filtering accounts, all accounts if null * @param tag is the tag for filtering accounts, all accounts if null
* @return List<monero_account> are all accounts for the wallet with the given tag * @return List<wownero_account> are all accounts for the wallet with the given tag
*/ */
virtual std::vector<monero_account> get_accounts(bool include_subaddresses, const std::string& tag) const { virtual std::vector<wownero_account> get_accounts(bool include_subaddresses, const std::string& tag) const {
throw std::runtime_error("get_accounts() not supported"); throw std::runtime_error("get_accounts() not supported");
} }
@@ -621,7 +621,7 @@ namespace monero {
* @param account_idx specifies the account to get * @param account_idx specifies the account to get
* @return the retrieved account * @return the retrieved account
*/ */
virtual monero_account get_account(uint32_t account_idx) const { virtual wownero_account get_account(uint32_t account_idx) const {
return get_account(account_idx, false); return get_account(account_idx, false);
} }
@@ -632,7 +632,7 @@ namespace monero {
* @param include_subaddresses specifies if subaddresses should be included * @param include_subaddresses specifies if subaddresses should be included
* @return the retrieved account * @return the retrieved account
*/ */
virtual monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const { virtual wownero_account get_account(const uint32_t account_idx, bool include_subaddresses) const {
throw std::runtime_error("get_account() not supported"); throw std::runtime_error("get_account() not supported");
} }
@@ -642,7 +642,7 @@ namespace monero {
* @param label specifies the label for the account's first subaddress (optional) * @param label specifies the label for the account's first subaddress (optional)
* @return the created account * @return the created account
*/ */
virtual monero_account create_account(const std::string& label = "") { virtual wownero_account create_account(const std::string& label = "") {
throw std::runtime_error("create_account() not supported"); throw std::runtime_error("create_account() not supported");
} }
@@ -650,9 +650,9 @@ namespace monero {
* Get all subaddresses in an account. * Get all subaddresses in an account.
* *
* @param account_idx specifies the account to get subaddresses within * @param account_idx specifies the account to get subaddresses within
* @return List<monero_subaddress> are the retrieved subaddresses * @return List<wownero_subaddress> are the retrieved subaddresses
*/ */
virtual std::vector<monero_subaddress> get_subaddresses(const uint32_t account_idx) const { virtual std::vector<wownero_subaddress> get_subaddresses(const uint32_t account_idx) const {
return get_subaddresses(account_idx, std::vector<uint32_t>()); return get_subaddresses(account_idx, std::vector<uint32_t>());
} }
@@ -663,7 +663,7 @@ namespace monero {
* @param subaddress_indices are specific subaddresses to get (optional) * @param subaddress_indices are specific subaddresses to get (optional)
* @return the retrieved subaddresses * @return the retrieved subaddresses
*/ */
virtual std::vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const { virtual std::vector<wownero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const {
throw std::runtime_error("get_subaddresses() not supported"); throw std::runtime_error("get_subaddresses() not supported");
} }
@@ -674,7 +674,7 @@ namespace monero {
* @param subaddress_idx specifies index of the subaddress within the account * @param subaddress_idx specifies index of the subaddress within the account
* @return the retrieved subaddress * @return the retrieved subaddress
*/ */
virtual monero_subaddress get_subaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const { virtual wownero_subaddress get_subaddress(const uint32_t account_idx, const uint32_t subaddress_idx) const {
throw std::runtime_error("get_subaddress() not supported"); throw std::runtime_error("get_subaddress() not supported");
} }
@@ -685,7 +685,7 @@ namespace monero {
* @param label specifies the the label for the subaddress (defaults to empty std::string) * @param label specifies the the label for the subaddress (defaults to empty std::string)
* @return the created subaddress * @return the created subaddress
*/ */
virtual monero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") { virtual wownero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") {
throw std::runtime_error("create_subaddress() not supported"); throw std::runtime_error("create_subaddress() not supported");
} }
@@ -704,9 +704,9 @@ namespace monero {
* Get all wallet transactions. Wallet transactions contain one or more * Get all wallet transactions. Wallet transactions contain one or more
* transfers that are either incoming or outgoing to the wallet. * transfers that are either incoming or outgoing to the wallet.
* *
* @return all wallet transactions (free memory using monero_utils::free) * @return all wallet transactions (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_tx_wallet>> get_txs() const { virtual std::vector<std::shared_ptr<wownero_tx_wallet>> get_txs() const {
throw std::runtime_error("get_txs() not supported"); throw std::runtime_error("get_txs() not supported");
} }
@@ -720,9 +720,9 @@ namespace monero {
* not defined. * not defined.
* *
* @param query filters query results (optional) * @param query filters query results (optional)
* @return wallet transactions per the query (free memory using monero_utils::free) * @return wallet transactions per the query (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query) const { virtual std::vector<std::shared_ptr<wownero_tx_wallet>> get_txs(const wownero_tx_query& query) const {
throw std::runtime_error("get_txs(query) not supported"); throw std::runtime_error("get_txs(query) not supported");
} }
@@ -734,15 +734,15 @@ namespace monero {
* a subaddress within an account. Transfers belong to transactions which * a subaddress within an account. Transfers belong to transactions which
* are stored on the blockchain. * are stored on the blockchain.
* *
* Query results can be filtered by passing in a monero_transfer_query. * Query results can be filtered by passing in a wownero_transfer_query.
* Transfers must meet every criteria defined in the query in order to be * Transfers must meet every criteria defined in the query in order to be
* returned. All filtering is optional and no filtering is applied when not * returned. All filtering is optional and no filtering is applied when not
* defined. * defined.
* *
* @param query filters query results (optional) * @param query filters query results (optional)
* @return wallet transfers per the query (free memory using monero_utils::free) * @return wallet transfers per the query (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const { virtual std::vector<std::shared_ptr<wownero_transfer>> get_transfers(const wownero_transfer_query& query) const {
throw std::runtime_error("get_transfers() not supported"); throw std::runtime_error("get_transfers() not supported");
} }
@@ -751,14 +751,14 @@ namespace monero {
* (i.e. that the wallet can spend one time). Outputs are part of * (i.e. that the wallet can spend one time). Outputs are part of
* transactions which are stored in blocks on the blockchain. * transactions which are stored in blocks on the blockchain.
* *
* Results can be configured by passing a monero_output_query. Outputs must * Results can be configured by passing a wownero_output_query. Outputs must
* meet every criteria defined in the query in order to be returned. All * meet every criteria defined in the query in order to be returned. All
* filtering is optional and no filtering is applied when not defined. * filtering is optional and no filtering is applied when not defined.
* *
* @param query specifies query options (optional) * @param query specifies query options (optional)
* @return wallet outputs per the query (free memory using monero_utils::free) * @return wallet outputs per the query (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_output_wallet>> get_outputs(const monero_output_query& query) const { virtual std::vector<std::shared_ptr<wownero_output_wallet>> get_outputs(const wownero_output_query& query) const {
throw std::runtime_error("get_outputs() not supported"); throw std::runtime_error("get_outputs() not supported");
} }
@@ -788,7 +788,7 @@ namespace monero {
* @param all - export all key images if true, else export key images since the last export * @param all - export all key images if true, else export key images since the last export
* @return the wallet's signed key images * @return the wallet's signed key images
*/ */
virtual std::vector<std::shared_ptr<monero_key_image>> export_key_images(bool all = false) const { virtual std::vector<std::shared_ptr<wownero_key_image>> export_key_images(bool all = false) const {
throw std::runtime_error("export_key_images() not supported"); throw std::runtime_error("export_key_images() not supported");
} }
@@ -798,7 +798,7 @@ namespace monero {
* @param key_images are key images to import and verify (requires hex and signature) * @param key_images are key images to import and verify (requires hex and signature)
* @return results of the import * @return results of the import
*/ */
virtual std::shared_ptr<monero_key_image_import_result> import_key_images(const std::vector<std::shared_ptr<monero_key_image>>& key_images) { virtual std::shared_ptr<wownero_key_image_import_result> import_key_images(const std::vector<std::shared_ptr<wownero_key_image>>& key_images) {
throw std::runtime_error("import_key_images() not supported"); throw std::runtime_error("import_key_images() not supported");
} }
@@ -834,11 +834,11 @@ namespace monero {
* Create a transaction to transfer funds from this wallet. * Create a transaction to transfer funds from this wallet.
* *
* @param config configures the transaction to create * @param config configures the transaction to create
* @return the created transaction (free memory using monero_utils::free) * @return the created transaction (free memory using wownero_utils::free)
*/ */
virtual std::shared_ptr<monero_tx_wallet> create_tx(const monero_tx_config& config) { virtual std::shared_ptr<wownero_tx_wallet> create_tx(const wownero_tx_config& config) {
if (config.m_can_split != boost::none && config.m_can_split.get()) throw std::runtime_error("Cannot split transactions with create_tx(); use create_txs() instead"); if (config.m_can_split != boost::none && config.m_can_split.get()) throw std::runtime_error("Cannot split transactions with create_tx(); use create_txs() instead");
monero_tx_config config_copy = monero_tx_config(config); wownero_tx_config config_copy = wownero_tx_config(config);
config_copy.m_can_split = false; config_copy.m_can_split = false;
return create_txs(config_copy)[0]; return create_txs(config_copy)[0];
} }
@@ -847,9 +847,9 @@ namespace monero {
* Create one or more transactions to transfer funds from this wallet. * Create one or more transactions to transfer funds from this wallet.
* *
* @param config configures the transactions to create * @param config configures the transactions to create
* @return the created transactions (free memory using monero_utils::free) * @return the created transactions (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) { virtual std::vector<std::shared_ptr<wownero_tx_wallet>> create_txs(const wownero_tx_config& config) {
throw std::runtime_error("create_txs() not supported"); throw std::runtime_error("create_txs() not supported");
} }
@@ -857,9 +857,9 @@ namespace monero {
* Sweep unlocked funds according to the given config. * Sweep unlocked funds according to the given config.
* *
* @param config is the sweep configuration * @param config is the sweep configuration
* @return the created transactions (free memory using monero_utils::free) * @return the created transactions (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) { virtual std::vector<std::shared_ptr<wownero_tx_wallet>> sweep_unlocked(const wownero_tx_config& config) {
throw std::runtime_error("sweep_unlocked() not supported"); throw std::runtime_error("sweep_unlocked() not supported");
} }
@@ -867,9 +867,9 @@ namespace monero {
* Sweep an output with a given key image. * Sweep an output with a given key image.
* *
* @param config configures the sweep transaction * @param config configures the sweep transaction
* @return the created transaction (free memory using monero_utils::free) * @return the created transaction (free memory using wownero_utils::free)
*/ */
virtual std::shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) { virtual std::shared_ptr<wownero_tx_wallet> sweep_output(const wownero_tx_config& config) {
throw std::runtime_error("sweep_output() not supported"); throw std::runtime_error("sweep_output() not supported");
} }
@@ -877,9 +877,9 @@ namespace monero {
* Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix. * Sweep all unmixable dust outputs back to the wallet to make them easier to spend and mix.
* *
* @param relay specifies if the resulting transaction should be relayed (default false) * @param relay specifies if the resulting transaction should be relayed (default false)
* @return the created transactions (free memory using monero_utils::free) * @return the created transactions (free memory using wownero_utils::free)
*/ */
virtual std::vector<std::shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) { virtual std::vector<std::shared_ptr<wownero_tx_wallet>> sweep_dust(bool relay = false) {
throw std::runtime_error("sweep_dust() not supported"); throw std::runtime_error("sweep_dust() not supported");
} }
@@ -901,7 +901,7 @@ namespace monero {
* @param tx is the transaction to relay * @param tx is the transaction to relay
* @return the hash of the relayed tx * @return the hash of the relayed tx
*/ */
virtual std::string relay_tx(const monero_tx_wallet& tx) { virtual std::string relay_tx(const wownero_tx_wallet& tx) {
return relay_tx(tx.m_metadata.get()); return relay_tx(tx.m_metadata.get());
} }
@@ -911,9 +911,9 @@ namespace monero {
* @param txs are the transactions to relay * @param txs are the transactions to relay
* @return the hashes of the relayed txs * @return the hashes of the relayed txs
*/ */
virtual std::vector<std::string> relay_txs(const std::vector<std::shared_ptr<monero_tx_wallet>>& txs) { virtual std::vector<std::string> relay_txs(const std::vector<std::shared_ptr<wownero_tx_wallet>>& txs) {
std::vector<std::string> tx_hexes; std::vector<std::string> tx_hexes;
for (const std::shared_ptr<monero_tx_wallet>& tx : txs) tx_hexes.push_back(tx->m_metadata.get()); for (const std::shared_ptr<wownero_tx_wallet>& tx : txs) tx_hexes.push_back(tx->m_metadata.get());
return relay_txs(tx_hexes); return relay_txs(tx_hexes);
} }
@@ -933,7 +933,7 @@ namespace monero {
* @param tx_set is a tx set containing unsigned or multisig tx hex * @param tx_set is a tx set containing unsigned or multisig tx hex
* @return the tx set containing structured transactions * @return the tx set containing structured transactions
*/ */
virtual monero_tx_set describe_tx_set(const monero_tx_set& tx_set) { virtual wownero_tx_set describe_tx_set(const wownero_tx_set& tx_set) {
throw std::runtime_error("describe_tx_set() not supported"); throw std::runtime_error("describe_tx_set() not supported");
} }
@@ -943,7 +943,7 @@ namespace monero {
* @param unsigned_tx_hex is unsigned transaction hex from when the transactions were created * @param unsigned_tx_hex is unsigned transaction hex from when the transactions were created
* @return the signed transaction set * @return the signed transaction set
*/ */
virtual monero_tx_set sign_txs(const std::string& unsigned_tx_hex) { virtual wownero_tx_set sign_txs(const std::string& unsigned_tx_hex) {
throw std::runtime_error("sign_txs() not supported"); throw std::runtime_error("sign_txs() not supported");
} }
@@ -966,7 +966,7 @@ namespace monero {
* @param subaddress_idx - the subaddress index of the message signature (default 0) * @param subaddress_idx - the subaddress index of the message signature (default 0)
* @return the message signature * @return the message signature
*/ */
virtual std::string sign_message(const std::string& msg, monero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const { virtual std::string sign_message(const std::string& msg, wownero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const {
throw std::runtime_error("sign_message() not supported"); throw std::runtime_error("sign_message() not supported");
} }
@@ -978,7 +978,7 @@ namespace monero {
* @param signature - signature * @param signature - signature
* @return the message signature result * @return the message signature result
*/ */
virtual monero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const { virtual wownero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const {
throw std::runtime_error("verify_message() not supported"); throw std::runtime_error("verify_message() not supported");
} }
@@ -1000,7 +1000,7 @@ namespace monero {
* @param address is the destination public address of the transaction * @param address is the destination public address of the transaction
* @return the result of the check * @return the result of the check
*/ */
virtual std::shared_ptr<monero_check_tx> check_tx_key(const std::string& tx_hash, const std::string& tx_key, const std::string& address) const { virtual std::shared_ptr<wownero_check_tx> check_tx_key(const std::string& tx_hash, const std::string& tx_key, const std::string& address) const {
throw std::runtime_error("check_tx_key() not supported"); throw std::runtime_error("check_tx_key() not supported");
} }
@@ -1025,7 +1025,7 @@ namespace monero {
* @param signature is the transaction signature to confirm * @param signature is the transaction signature to confirm
* @return the result of the check * @return the result of the check
*/ */
virtual std::shared_ptr<monero_check_tx> check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const { virtual std::shared_ptr<wownero_check_tx> check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const {
throw std::runtime_error("check_tx_proof() not supported"); throw std::runtime_error("check_tx_proof() not supported");
} }
@@ -1082,7 +1082,7 @@ namespace monero {
* @param signature is the reserve proof signature to check * @param signature is the reserve proof signature to check
* @return the result of checking the signature proof * @return the result of checking the signature proof
*/ */
virtual std::shared_ptr<monero_check_reserve> check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const { virtual std::shared_ptr<wownero_check_reserve> check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const {
throw std::runtime_error("check_reserve_proof() not supported"); throw std::runtime_error("check_reserve_proof() not supported");
} }
@@ -1132,7 +1132,7 @@ namespace monero {
* @param indices are indices of the entries to get * @param indices are indices of the entries to get
* @return the address book entries * @return the address book entries
*/ */
virtual std::vector<monero_address_book_entry> get_address_book_entries(const std::vector<uint64_t>& indices) const { virtual std::vector<wownero_address_book_entry> get_address_book_entries(const std::vector<uint64_t>& indices) const {
throw std::runtime_error("get_address_book_entries() not supported"); throw std::runtime_error("get_address_book_entries() not supported");
} }
@@ -1175,7 +1175,7 @@ namespace monero {
* @param config specifies configuration for a potential tx * @param config specifies configuration for a potential tx
* @return is the payment uri * @return is the payment uri
*/ */
virtual std::string get_payment_uri(const monero_tx_config& config) const { virtual std::string get_payment_uri(const wownero_tx_config& config) const {
throw std::runtime_error("get_payment_uri() not supported"); throw std::runtime_error("get_payment_uri() not supported");
} }
@@ -1185,7 +1185,7 @@ namespace monero {
* @param uri is the payment uri to parse * @param uri is the payment uri to parse
* @return the tx configuration parsed from the uri * @return the tx configuration parsed from the uri
*/ */
virtual std::shared_ptr<monero_tx_config> parse_payment_uri(const std::string& uri) const { virtual std::shared_ptr<wownero_tx_config> parse_payment_uri(const std::string& uri) const {
throw std::runtime_error("parse_payment_uri() not supported"); throw std::runtime_error("parse_payment_uri() not supported");
} }
@@ -1260,7 +1260,7 @@ namespace monero {
* *
* @return multisig info about this wallet * @return multisig info about this wallet
*/ */
virtual monero_multisig_info get_multisig_info() const { virtual wownero_multisig_info get_multisig_info() const {
throw std::runtime_error("get_multisig_info() not supported"); throw std::runtime_error("get_multisig_info() not supported");
} }
@@ -1295,7 +1295,7 @@ namespace monero {
* @param password is the wallet's password // TODO monero-project: redundant? wallet is created with password * @param password is the wallet's password // TODO monero-project: redundant? wallet is created with password
* @return the result which has the multisig's address xor this wallet's multisig hex to share with participants iff not done * @return the result which has the multisig's address xor this wallet's multisig hex to share with participants iff not done
*/ */
virtual monero_multisig_init_result exchange_multisig_keys(const std::vector<std::string>& mutisig_hexes, const std::string& password) { virtual wownero_multisig_init_result exchange_multisig_keys(const std::vector<std::string>& mutisig_hexes, const std::string& password) {
throw std::runtime_error("exchange_multisig_keys() not supported"); throw std::runtime_error("exchange_multisig_keys() not supported");
} }
@@ -1328,8 +1328,8 @@ namespace monero {
* @param multisig_tx_hex is the hex shared among the multisig transactions when they were created * @param multisig_tx_hex is the hex shared among the multisig transactions when they were created
* @return the result of signing the multisig transactions * @return the result of signing the multisig transactions
*/ */
virtual monero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) { virtual wownero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) {
throw std::runtime_error("monero_multisig_sign_result() not supported"); throw std::runtime_error("wownero_multisig_sign_result() not supported");
} }
/** /**
File diff suppressed because it is too large Load Diff
@@ -52,7 +52,7 @@
#pragma once #pragma once
#include "monero_wallet.h" #include "wownero_wallet.h"
#include "wallet/wallet2.h" #include "wallet/wallet2.h"
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
@@ -60,9 +60,9 @@
#include <boost/thread/condition_variable.hpp> #include <boost/thread/condition_variable.hpp>
/** /**
* Implements a monero_wallet.h by wrapping monero-project's wallet2. * Implements a wownero_wallet.h by wrapping monero-project's wallet2.
*/ */
namespace monero { namespace wownero {
// -------------------------------- LISTENERS ------------------------------- // -------------------------------- LISTENERS -------------------------------
@@ -74,7 +74,7 @@ namespace monero {
/** /**
* Monero wallet implementation which uses monero-project's wallet2. * Monero wallet implementation which uses monero-project's wallet2.
*/ */
class monero_wallet_full : public monero_wallet { class wownero_wallet_full : public wownero_wallet {
public: public:
@@ -94,7 +94,7 @@ namespace monero {
* @param network_type is the wallet's network type * @param network_type is the wallet's network type
* @return a pointer to the wallet instance * @return a pointer to the wallet instance
*/ */
static monero_wallet_full* open_wallet(const std::string& path, const std::string& password, const monero_network_type network_type); static wownero_wallet_full* open_wallet(const std::string& path, const std::string& password, const wownero_network_type network_type);
/** /**
* Open an in-memory wallet from existing data buffers. * Open an in-memory wallet from existing data buffers.
@@ -107,7 +107,7 @@ namespace monero {
* @param http_client_factory allows use of custom http clients * @param http_client_factory allows use of custom http clients
* @return a pointer to the wallet instance * @return a pointer to the wallet instance
*/ */
static monero_wallet_full* open_wallet_data(const std::string& password, const monero_network_type, const std::string& keys_data, const std::string& cache_data, const monero_rpc_connection& daemon_connection = monero_rpc_connection(), std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr); static wownero_wallet_full* open_wallet_data(const std::string& password, const wownero_network_type, const std::string& keys_data, const std::string& cache_data, const wownero_rpc_connection& daemon_connection = wownero_rpc_connection(), std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr);
/** /**
* Create a new wallet with the given configuration. * Create a new wallet with the given configuration.
@@ -116,7 +116,7 @@ namespace monero {
* @param http_client_factory allows use of custom http clients * @param http_client_factory allows use of custom http clients
* @return a pointer to the wallet instance * @return a pointer to the wallet instance
*/ */
static monero_wallet_full* create_wallet(const monero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr); static wownero_wallet_full* create_wallet(const wownero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr);
/** /**
* Get a list of available languages for the wallet's seed. * Get a list of available languages for the wallet's seed.
@@ -130,23 +130,23 @@ namespace monero {
/** /**
* Destruct the wallet. * Destruct the wallet.
*/ */
~monero_wallet_full(); ~wownero_wallet_full();
/** /**
* Supported wallet methods. * Supported wallet methods.
*/ */
bool is_view_only() const override { return m_w2->watch_only(); } bool is_view_only() const override { return m_w2->watch_only(); }
void set_daemon_connection(const std::string& uri, const std::string& username = "", const std::string& password = "") override; void set_daemon_connection(const std::string& uri, const std::string& username = "", const std::string& password = "") override;
void set_daemon_connection(const boost::optional<monero_rpc_connection>& connection) override; void set_daemon_connection(const boost::optional<wownero_rpc_connection>& connection) override;
void set_daemon_proxy(const std::string& uri = "") override; void set_daemon_proxy(const std::string& uri = "") override;
boost::optional<monero_rpc_connection> get_daemon_connection() const override; boost::optional<wownero_rpc_connection> get_daemon_connection() const override;
bool is_connected_to_daemon() const override; bool is_connected_to_daemon() const override;
bool is_daemon_synced() const override; bool is_daemon_synced() const override;
bool is_daemon_trusted() const override; bool is_daemon_trusted() const override;
bool is_synced() const override; bool is_synced() const override;
monero_version get_version() const override; wownero_version get_version() const override;
std::string get_path() const override; std::string get_path() const override;
monero_network_type get_network_type() const override; wownero_network_type get_network_type() const override;
std::string get_seed() const override; std::string get_seed() const override;
std::string get_seed_language() const override; std::string get_seed_language() const override;
std::string get_public_view_key() const override; std::string get_public_view_key() const override;
@@ -154,22 +154,22 @@ namespace monero {
std::string get_public_spend_key() const override; std::string get_public_spend_key() const override;
std::string get_private_spend_key() const override; std::string get_private_spend_key() const override;
std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override; std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override;
monero_subaddress get_address_index(const std::string& address) const override; wownero_subaddress get_address_index(const std::string& address) const override;
monero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const override; wownero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const override;
monero_integrated_address decode_integrated_address(const std::string& integrated_address) const override; wownero_integrated_address decode_integrated_address(const std::string& integrated_address) const override;
uint64_t get_height() const override; uint64_t get_height() const override;
uint64_t get_restore_height() const override; uint64_t get_restore_height() const override;
void set_restore_height(uint64_t restore_height) override; void set_restore_height(uint64_t restore_height) override;
uint64_t get_daemon_height() const override; uint64_t get_daemon_height() const override;
uint64_t get_daemon_max_peer_height() const override; uint64_t get_daemon_max_peer_height() const override;
uint64_t get_height_by_date(uint16_t year, uint8_t month, uint8_t day) const override; uint64_t get_height_by_date(uint16_t year, uint8_t month, uint8_t day) const override;
void add_listener(monero_wallet_listener& listener) override; void add_listener(wownero_wallet_listener& listener) override;
void remove_listener(monero_wallet_listener& listener) override; void remove_listener(wownero_wallet_listener& listener) override;
std::set<monero_wallet_listener*> get_listeners() override; std::set<wownero_wallet_listener*> get_listeners() override;
monero_sync_result sync() override; wownero_sync_result sync() override;
monero_sync_result sync(monero_wallet_listener& listener) override; wownero_sync_result sync(wownero_wallet_listener& listener) override;
monero_sync_result sync(uint64_t start_height) override; wownero_sync_result sync(uint64_t start_height) override;
monero_sync_result sync(uint64_t start_height, monero_wallet_listener& listener) override; wownero_sync_result sync(uint64_t start_height, wownero_wallet_listener& listener) override;
void start_syncing(uint64_t sync_period_in_ms) override; void start_syncing(uint64_t sync_period_in_ms) override;
void stop_syncing() override; void stop_syncing() override;
void scan_txs(const std::vector<std::string>& tx_hashes) override; void scan_txs(const std::vector<std::string>& tx_hashes) override;
@@ -181,65 +181,65 @@ namespace monero {
uint64_t get_unlocked_balance() const override; uint64_t get_unlocked_balance() const override;
uint64_t get_unlocked_balance(uint32_t account_idx) const override; uint64_t get_unlocked_balance(uint32_t account_idx) const override;
uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const override; uint64_t get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const override;
std::vector<monero_account> get_accounts(bool include_subaddresses, const std::string& tag) const override; std::vector<wownero_account> get_accounts(bool include_subaddresses, const std::string& tag) const override;
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override; wownero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override;
monero_account create_account(const std::string& label = "") override; wownero_account create_account(const std::string& label = "") override;
std::vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const override; std::vector<wownero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const override;
monero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") override; wownero_subaddress create_subaddress(uint32_t account_idx, const std::string& label = "") override;
void set_subaddress_label(uint32_t account_idx, uint32_t subaddress_idx, const std::string& label = "") override; void set_subaddress_label(uint32_t account_idx, uint32_t subaddress_idx, const std::string& label = "") override;
std::vector<std::shared_ptr<monero_tx_wallet>> get_txs() const override; std::vector<std::shared_ptr<wownero_tx_wallet>> get_txs() const override;
std::vector<std::shared_ptr<monero_tx_wallet>> get_txs(const monero_tx_query& query) const override; std::vector<std::shared_ptr<wownero_tx_wallet>> get_txs(const wownero_tx_query& query) const override;
std::vector<std::shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const override; std::vector<std::shared_ptr<wownero_transfer>> get_transfers(const wownero_transfer_query& query) const override;
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs(const monero_output_query& query) const override; std::vector<std::shared_ptr<wownero_output_wallet>> get_outputs(const wownero_output_query& query) const override;
std::string export_outputs(bool all = false) const override; std::string export_outputs(bool all = false) const override;
int import_outputs(const std::string& outputs_hex) override; int import_outputs(const std::string& outputs_hex) override;
std::vector<std::shared_ptr<monero_key_image>> export_key_images(bool all = false) const override; std::vector<std::shared_ptr<wownero_key_image>> export_key_images(bool all = false) const override;
std::shared_ptr<monero_key_image_import_result> import_key_images(const std::vector<std::shared_ptr<monero_key_image>>& key_images) override; std::shared_ptr<wownero_key_image_import_result> import_key_images(const std::vector<std::shared_ptr<wownero_key_image>>& key_images) override;
void freeze_output(const std::string& key_image) override; void freeze_output(const std::string& key_image) override;
void thaw_output(const std::string& key_image) override; void thaw_output(const std::string& key_image) override;
bool is_output_frozen(const std::string& key_image) override; bool is_output_frozen(const std::string& key_image) override;
std::vector<std::shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) override; std::vector<std::shared_ptr<wownero_tx_wallet>> create_txs(const wownero_tx_config& config) override;
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) override; std::vector<std::shared_ptr<wownero_tx_wallet>> sweep_unlocked(const wownero_tx_config& config) override;
std::shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) override; std::shared_ptr<wownero_tx_wallet> sweep_output(const wownero_tx_config& config) override;
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) override; std::vector<std::shared_ptr<wownero_tx_wallet>> sweep_dust(bool relay = false) override;
std::vector<std::string> relay_txs(const std::vector<std::string>& tx_metadatas) override; std::vector<std::string> relay_txs(const std::vector<std::string>& tx_metadatas) override;
monero_tx_set describe_tx_set(const monero_tx_set& tx_set) override; wownero_tx_set describe_tx_set(const wownero_tx_set& tx_set) override;
monero_tx_set sign_txs(const std::string& unsigned_tx_hex) override; wownero_tx_set sign_txs(const std::string& unsigned_tx_hex) override;
std::vector<std::string> submit_txs(const std::string& signed_tx_hex) override; std::vector<std::string> submit_txs(const std::string& signed_tx_hex) override;
std::string sign_message(const std::string& msg, monero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const override; std::string sign_message(const std::string& msg, wownero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const override;
monero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override; wownero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override;
std::string get_tx_key(const std::string& tx_hash) const override; std::string get_tx_key(const std::string& tx_hash) const override;
std::shared_ptr<monero_check_tx> check_tx_key(const std::string& tx_hash, const std::string& txKey, const std::string& address) const override; std::shared_ptr<wownero_check_tx> check_tx_key(const std::string& tx_hash, const std::string& txKey, const std::string& address) const override;
std::string get_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message) const override; std::string get_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message) const override;
std::shared_ptr<monero_check_tx> check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const override; std::shared_ptr<wownero_check_tx> check_tx_proof(const std::string& tx_hash, const std::string& address, const std::string& message, const std::string& signature) const override;
std::string get_spend_proof(const std::string& tx_hash, const std::string& message) const override; std::string get_spend_proof(const std::string& tx_hash, const std::string& message) const override;
bool check_spend_proof(const std::string& tx_hash, const std::string& message, const std::string& signature) const override; bool check_spend_proof(const std::string& tx_hash, const std::string& message, const std::string& signature) const override;
std::string get_reserve_proof_wallet(const std::string& message) const override; std::string get_reserve_proof_wallet(const std::string& message) const override;
std::string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const std::string& message) const override; std::string get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const std::string& message) const override;
std::shared_ptr<monero_check_reserve> check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const override; std::shared_ptr<wownero_check_reserve> check_reserve_proof(const std::string& address, const std::string& message, const std::string& signature) const override;
std::string get_tx_note(const std::string& tx_hash) const override; std::string get_tx_note(const std::string& tx_hash) const override;
std::vector<std::string> get_tx_notes(const std::vector<std::string>& tx_hashes) const override; std::vector<std::string> get_tx_notes(const std::vector<std::string>& tx_hashes) const override;
void set_tx_note(const std::string& tx_hash, const std::string& note) override; void set_tx_note(const std::string& tx_hash, const std::string& note) override;
void set_tx_notes(const std::vector<std::string>& tx_hashes, const std::vector<std::string>& notes) override; void set_tx_notes(const std::vector<std::string>& tx_hashes, const std::vector<std::string>& notes) override;
std::vector<monero_address_book_entry> get_address_book_entries(const std::vector<uint64_t>& indices) const override; std::vector<wownero_address_book_entry> get_address_book_entries(const std::vector<uint64_t>& indices) const override;
uint64_t add_address_book_entry(const std::string& address, const std::string& description) override; uint64_t add_address_book_entry(const std::string& address, const std::string& description) override;
void edit_address_book_entry(uint64_t index, bool set_address, const std::string& address, bool set_description, const std::string& description) override; void edit_address_book_entry(uint64_t index, bool set_address, const std::string& address, bool set_description, const std::string& description) override;
void delete_address_book_entry(uint64_t index) override; void delete_address_book_entry(uint64_t index) override;
std::string get_payment_uri(const monero_tx_config& config) const override; std::string get_payment_uri(const wownero_tx_config& config) const override;
std::shared_ptr<monero_tx_config> parse_payment_uri(const std::string& uri) const override; std::shared_ptr<wownero_tx_config> parse_payment_uri(const std::string& uri) const override;
bool get_attribute(const std::string& key, std::string& value) const override; bool get_attribute(const std::string& key, std::string& value) const override;
void set_attribute(const std::string& key, const std::string& val) override; void set_attribute(const std::string& key, const std::string& val) override;
void start_mining(boost::optional<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> ignore_battery) override; void start_mining(boost::optional<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> ignore_battery) override;
void stop_mining() override; void stop_mining() override;
uint64_t wait_for_next_block() override; uint64_t wait_for_next_block() override;
bool is_multisig_import_needed() const override; bool is_multisig_import_needed() const override;
monero_multisig_info get_multisig_info() const override; wownero_multisig_info get_multisig_info() const override;
std::string prepare_multisig() override; std::string prepare_multisig() override;
std::string make_multisig(const std::vector<std::string>& multisig_hexes, int threshold, const std::string& password) override; std::string make_multisig(const std::vector<std::string>& multisig_hexes, int threshold, const std::string& password) override;
monero_multisig_init_result exchange_multisig_keys(const std::vector<std::string>& mutisig_hexes, const std::string& password) override; wownero_multisig_init_result exchange_multisig_keys(const std::vector<std::string>& mutisig_hexes, const std::string& password) override;
std::string export_multisig_hex() override; std::string export_multisig_hex() override;
int import_multisig_hex(const std::vector<std::string>& multisig_hexes) override; int import_multisig_hex(const std::vector<std::string>& multisig_hexes) override;
monero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) override; wownero_multisig_sign_result sign_multisig_tx_hex(const std::string& multisig_tx_hex) override;
std::vector<std::string> submit_multisig_tx_hex(const std::string& signed_multisig_tx_hex) override; std::vector<std::string> submit_multisig_tx_hex(const std::string& signed_multisig_tx_hex) override;
void change_password(const std::string& old_password, const std::string& new_password) override; void change_password(const std::string& old_password, const std::string& new_password) override;
void move_to(const std::string& path, const std::string& password) override; void move_to(const std::string& path, const std::string& password) override;
@@ -264,16 +264,16 @@ namespace monero {
private: private:
friend struct wallet2_listener; friend struct wallet2_listener;
std::unique_ptr<wallet2_listener> m_w2_listener; // internal wallet implementation listener std::unique_ptr<wallet2_listener> m_w2_listener; // internal wallet implementation listener
std::set<monero_wallet_listener*> m_listeners; // external wallet listeners std::set<wownero_wallet_listener*> m_listeners; // external wallet listeners
static monero_wallet_full* create_wallet_from_seed(monero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory); static wownero_wallet_full* create_wallet_from_seed(wownero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory);
static monero_wallet_full* create_wallet_from_keys(monero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory); static wownero_wallet_full* create_wallet_from_keys(wownero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory);
static monero_wallet_full* create_wallet_random(monero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory); static wownero_wallet_full* create_wallet_random(wownero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory);
std::vector<monero_subaddress> get_subaddresses_aux(uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices, const std::vector<tools::wallet2::transfer_details>& transfers) const; std::vector<wownero_subaddress> get_subaddresses_aux(uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices, const std::vector<tools::wallet2::transfer_details>& transfers) const;
std::vector<std::shared_ptr<monero_transfer>> get_transfers_aux(const monero_transfer_query& query) const; std::vector<std::shared_ptr<wownero_transfer>> get_transfers_aux(const wownero_transfer_query& query) const;
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_aux(const monero_output_query& query) const; std::vector<std::shared_ptr<wownero_output_wallet>> get_outputs_aux(const wownero_output_query& query) const;
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_account(const monero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked() std::vector<std::shared_ptr<wownero_tx_wallet>> sweep_account(const wownero_tx_config& config); // sweeps unlocked funds within an account; private helper to sweep_unlocked()
// blockchain sync management // blockchain sync management
mutable std::atomic<bool> m_is_synced; // whether or not wallet is synced mutable std::atomic<bool> m_is_synced; // whether or not wallet is synced
@@ -287,7 +287,7 @@ namespace monero {
boost::thread m_syncing_thread; // thread for auto sync loop boost::thread m_syncing_thread; // thread for auto sync loop
boost::mutex m_syncing_mutex; // synchronize auto sync loop boost::mutex m_syncing_mutex; // synchronize auto sync loop
void run_sync_loop(); // run the sync loop in a thread void run_sync_loop(); // run the sync loop in a thread
monero_sync_result lock_and_sync(boost::optional<uint64_t> start_height = boost::none); // internal function to synchronize request to sync and rescan wownero_sync_result lock_and_sync(boost::optional<uint64_t> start_height = boost::none); // internal function to synchronize request to sync and rescan
monero_sync_result sync_aux(boost::optional<uint64_t> start_height = boost::none); // internal function to immediately block, sync, and report progress wownero_sync_result sync_aux(boost::optional<uint64_t> start_height = boost::none); // internal function to immediately block, sync, and report progress
}; };
} }
@@ -50,9 +50,9 @@
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/ */
#include "monero_wallet_keys.h" #include "wownero_wallet_keys.h"
#include "utils/monero_utils.h" #include "utils/wownero_utils.h"
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include "mnemonics/electrum-words.h" #include "mnemonics/electrum-words.h"
@@ -69,20 +69,20 @@ using namespace crypto;
/** /**
* Public library interface. * Public library interface.
*/ */
namespace monero { namespace wownero {
// ---------------------------- WALLET MANAGEMENT --------------------------- // ---------------------------- WALLET MANAGEMENT ---------------------------
monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_wallet_config& config) { wownero_wallet_keys* wownero_wallet_keys::create_wallet_random(const wownero_wallet_config& config) {
// validate and normalize config // validate and normalize config
monero_wallet_config config_normalized = config.copy(); wownero_wallet_config config_normalized = config.copy();
if (config_normalized.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type"); if (config_normalized.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type");
if (config_normalized.m_language == boost::none || config_normalized.m_language.get().empty()) config_normalized.m_language = "English"; if (config_normalized.m_language == boost::none || config_normalized.m_language.get().empty()) config_normalized.m_language = "English";
if (!monero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get()); if (!wownero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get());
// initialize random wallet account // initialize random wallet account
monero_wallet_keys* wallet = new monero_wallet_keys(); wownero_wallet_keys* wallet = new wownero_wallet_keys();
crypto::secret_key spend_key_sk = wallet->m_account.generate(); crypto::secret_key spend_key_sk = wallet->m_account.generate();
// initialize remaining wallet // initialize remaining wallet
@@ -98,7 +98,7 @@ namespace monero {
return wallet; return wallet;
} }
monero_wallet_keys* monero_wallet_keys::create_wallet_from_seed(const monero_wallet_config& config) { wownero_wallet_keys* wownero_wallet_keys::create_wallet_from_seed(const wownero_wallet_config& config) {
// validate config // validate config
if (config.m_is_multisig != boost::none && config.m_is_multisig.get()) throw std::runtime_error("Restoring from multisig seed not supported"); if (config.m_is_multisig != boost::none && config.m_is_multisig.get()) throw std::runtime_error("Restoring from multisig seed not supported");
@@ -116,7 +116,7 @@ namespace monero {
if (config.m_seed_offset != boost::none && !config.m_seed_offset.get().empty()) spend_key_sk = cryptonote::decrypt_key(spend_key_sk, config.m_seed_offset.get()); if (config.m_seed_offset != boost::none && !config.m_seed_offset.get().empty()) spend_key_sk = cryptonote::decrypt_key(spend_key_sk, config.m_seed_offset.get());
// initialize wallet account // initialize wallet account
monero_wallet_keys* wallet = new monero_wallet_keys(); wownero_wallet_keys* wallet = new wownero_wallet_keys();
wallet->m_account = cryptonote::account_base{}; wallet->m_account = cryptonote::account_base{};
wallet->m_account.generate(spend_key_sk, true, false); wallet->m_account.generate(spend_key_sk, true, false);
@@ -133,15 +133,15 @@ namespace monero {
return wallet; return wallet;
} }
monero_wallet_keys* monero_wallet_keys::create_wallet_from_keys(const monero_wallet_config& config) { wownero_wallet_keys* wownero_wallet_keys::create_wallet_from_keys(const wownero_wallet_config& config) {
// validate and normalize config // validate and normalize config
monero_wallet_config config_normalized = config.copy(); wownero_wallet_config config_normalized = config.copy();
if (config.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type"); if (config.m_network_type == boost::none) throw std::runtime_error("Must provide wallet network type");
if (config.m_language == boost::none || config_normalized.m_language.get().empty()) config_normalized.m_language = "English"; if (config.m_language == boost::none || config_normalized.m_language.get().empty()) config_normalized.m_language = "English";
if (config.m_private_spend_key == boost::none) config_normalized.m_private_spend_key = std::string(""); if (config.m_private_spend_key == boost::none) config_normalized.m_private_spend_key = std::string("");
if (config.m_private_view_key == boost::none) config_normalized.m_private_view_key = std::string(""); if (config.m_private_view_key == boost::none) config_normalized.m_private_view_key = std::string("");
if (!monero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get()); if (!wownero_utils::is_valid_language(config_normalized.m_language.get())) throw std::runtime_error("Unknown language: " + config_normalized.m_language.get());
// parse and validate private spend key // parse and validate private spend key
crypto::secret_key spend_key_sk; crypto::secret_key spend_key_sk;
@@ -190,7 +190,7 @@ namespace monero {
} }
// initialize wallet account // initialize wallet account
monero_wallet_keys* wallet = new monero_wallet_keys(); wownero_wallet_keys* wallet = new wownero_wallet_keys();
if (has_spend_key && has_view_key) { if (has_spend_key && has_view_key) {
wallet->m_account.create_from_keys(address_info.address, spend_key_sk, view_key_sk); wallet->m_account.create_from_keys(address_info.address, spend_key_sk, view_key_sk);
} else if (has_spend_key) { } else if (has_spend_key) {
@@ -215,7 +215,7 @@ namespace monero {
return wallet; return wallet;
} }
std::vector<std::string> monero_wallet_keys::get_seed_languages() { std::vector<std::string> wownero_wallet_keys::get_seed_languages() {
std::vector<std::string> languages; std::vector<std::string> languages;
crypto::ElectrumWords::get_language_list(languages, true); // TODO: support getting names in language crypto::ElectrumWords::get_language_list(languages, true); // TODO: support getting names in language
return languages; return languages;
@@ -223,52 +223,52 @@ namespace monero {
// ----------------------------- WALLET METHODS ----------------------------- // ----------------------------- WALLET METHODS -----------------------------
monero_wallet_keys::~monero_wallet_keys() { wownero_wallet_keys::~wownero_wallet_keys() {
MTRACE("~monero_wallet_keys()"); MTRACE("~wownero_wallet_keys()");
close(); close();
} }
monero_version monero_wallet_keys::get_version() const { wownero_version wownero_wallet_keys::get_version() const {
monero_version version; wownero_version version;
version.m_number = 65552; // same as monero-wallet-rpc v0.15.0.1 release version.m_number = 65552; // same as monero-wallet-rpc v0.15.0.1 release
version.m_is_release = false; // TODO: could pull from MONERO_VERSION_IS_RELEASE in version.cpp version.m_is_release = false; // TODO: could pull from wownero_VERSION_IS_RELEASE in version.cpp
return version; return version;
} }
std::string monero_wallet_keys::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { std::string wownero_wallet_keys::get_address(uint32_t account_idx, uint32_t subaddress_idx) const {
hw::device &hwdev = m_account.get_device(); hw::device &hwdev = m_account.get_device();
cryptonote::subaddress_index index{account_idx, subaddress_idx}; cryptonote::subaddress_index index{account_idx, subaddress_idx};
cryptonote::account_public_address address = hwdev.get_subaddress(m_account.get_keys(), index); cryptonote::account_public_address address = hwdev.get_subaddress(m_account.get_keys(), index);
return cryptonote::get_account_address_as_str(static_cast<cryptonote::network_type>(m_network_type), !index.is_zero(), address); return cryptonote::get_account_address_as_str(static_cast<cryptonote::network_type>(m_network_type), !index.is_zero(), address);
} }
monero_integrated_address monero_wallet_keys::get_integrated_address(const std::string& standard_address, const std::string& payment_id) const { wownero_integrated_address wownero_wallet_keys::get_integrated_address(const std::string& standard_address, const std::string& payment_id) const {
std::cout << "monero_wallet_keys::get_integrated_address()" << std::endl; std::cout << "wownero_wallet_keys::get_integrated_address()" << std::endl;
throw std::runtime_error("monero_wallet_keys::get_integrated_address() not implemented"); throw std::runtime_error("wownero_wallet_keys::get_integrated_address() not implemented");
} }
monero_integrated_address monero_wallet_keys::decode_integrated_address(const std::string& integrated_address) const { wownero_integrated_address wownero_wallet_keys::decode_integrated_address(const std::string& integrated_address) const {
std::cout << "monero_wallet_keys::decode_integrated_address()" << std::endl; std::cout << "wownero_wallet_keys::decode_integrated_address()" << std::endl;
throw std::runtime_error("monero_wallet_keys::decode_integrated_address() not implemented"); throw std::runtime_error("wownero_wallet_keys::decode_integrated_address() not implemented");
} }
monero_account monero_wallet_keys::get_account(uint32_t account_idx, bool include_subaddresses) const { wownero_account wownero_wallet_keys::get_account(uint32_t account_idx, bool include_subaddresses) const {
std::cout << "monero_wallet_keys::get_account()" << std::endl; std::cout << "wownero_wallet_keys::get_account()" << std::endl;
if (include_subaddresses) { if (include_subaddresses) {
std::string err = "monero_wallet_keys::get_account(account_idx, include_subaddresses) include_subaddresses must be false"; std::string err = "wownero_wallet_keys::get_account(account_idx, include_subaddresses) include_subaddresses must be false";
std::cout << err << std::endl; std::cout << err << std::endl;
throw std::runtime_error(err); throw std::runtime_error(err);
} }
// build and return account // build and return account
monero_account account; wownero_account account;
account.m_index = account_idx; account.m_index = account_idx;
account.m_primary_address = get_address(account_idx, 0); account.m_primary_address = get_address(account_idx, 0);
return account; return account;
} }
std::vector<monero_subaddress> monero_wallet_keys::get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const { std::vector<wownero_subaddress> wownero_wallet_keys::get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const {
// must provide subaddress indices // must provide subaddress indices
if (subaddress_indices.empty()) { if (subaddress_indices.empty()) {
@@ -278,9 +278,9 @@ namespace monero {
} }
// initialize subaddresses at indices // initialize subaddresses at indices
std::vector<monero_subaddress> subaddresses; std::vector<wownero_subaddress> subaddresses;
for (uint32_t subaddressIndicesIdx = 0; subaddressIndicesIdx < subaddress_indices.size(); subaddressIndicesIdx++) { for (uint32_t subaddressIndicesIdx = 0; subaddressIndicesIdx < subaddress_indices.size(); subaddressIndicesIdx++) {
monero_subaddress subaddress; wownero_subaddress subaddress;
subaddress.m_account_index = account_idx; subaddress.m_account_index = account_idx;
uint32_t subaddress_idx = subaddress_indices.at(subaddressIndicesIdx); uint32_t subaddress_idx = subaddress_indices.at(subaddressIndicesIdx);
subaddress.m_index = subaddress_idx; subaddress.m_index = subaddress_idx;
@@ -291,24 +291,24 @@ namespace monero {
return subaddresses; return subaddresses;
} }
std::string monero_wallet_keys::sign_message(const std::string& msg, monero_message_signature_type signature_type, uint32_t account_idx, uint32_t subaddress_idx) const { std::string wownero_wallet_keys::sign_message(const std::string& msg, wownero_message_signature_type signature_type, uint32_t account_idx, uint32_t subaddress_idx) const {
std::cout << "monero_wallet_keys::sign_message()" << std::endl; std::cout << "wownero_wallet_keys::sign_message()" << std::endl;
throw std::runtime_error("monero_wallet_keys::sign_message() not implemented"); throw std::runtime_error("wownero_wallet_keys::sign_message() not implemented");
} }
monero_message_signature_result monero_wallet_keys::verify_message(const std::string& msg, const std::string& address, const std::string& signature) const { wownero_message_signature_result wownero_wallet_keys::verify_message(const std::string& msg, const std::string& address, const std::string& signature) const {
std::cout << "monero_wallet_keys::verify_message()" << std::endl; std::cout << "wownero_wallet_keys::verify_message()" << std::endl;
throw std::runtime_error("monero_wallet_keys::verify_message() not implemented"); throw std::runtime_error("wownero_wallet_keys::verify_message() not implemented");
} }
void monero_wallet_keys::close(bool save) { void wownero_wallet_keys::close(bool save) {
if (save) throw std::runtime_error("MoneroWalletKeys does not support saving"); if (save) throw std::runtime_error("MoneroWalletKeys does not support saving");
// no pointers to destroy // no pointers to destroy
} }
// ------------------------------- PRIVATE HELPERS ---------------------------- // ------------------------------- PRIVATE HELPERS ----------------------------
void monero_wallet_keys::init_common() { void wownero_wallet_keys::init_common() {
m_primary_address = m_account.get_public_address_str(static_cast<cryptonote::network_type>(m_network_type)); m_primary_address = m_account.get_public_address_str(static_cast<cryptonote::network_type>(m_network_type));
const cryptonote::account_keys& keys = m_account.get_keys(); const cryptonote::account_keys& keys = m_account.get_keys();
m_pub_view_key = epee::string_tools::pod_to_hex(keys.m_account_address.m_view_public_key); m_pub_view_key = epee::string_tools::pod_to_hex(keys.m_account_address.m_view_public_key);
@@ -52,20 +52,20 @@
#pragma once #pragma once
#include "monero_wallet.h" #include "wownero_wallet.h"
#include "cryptonote_basic/account.h" #include "cryptonote_basic/account.h"
using namespace monero; using namespace wownero;
/** /**
* Public library interface. * Public library interface.
*/ */
namespace monero { namespace wownero {
/** /**
* Implements a Monero wallet to provide basic key management. * Implements a Monero wallet to provide basic key management.
*/ */
class monero_wallet_keys : public monero_wallet { class wownero_wallet_keys : public wownero_wallet {
public: public:
@@ -76,21 +76,21 @@ namespace monero {
* *
* @param config is the wallet configuration (network type and language) * @param config is the wallet configuration (network type and language)
*/ */
static monero_wallet_keys* create_wallet_random(const monero_wallet_config& config); static wownero_wallet_keys* create_wallet_random(const wownero_wallet_config& config);
/** /**
* Create a wallet from an existing mnemonic phrase or seed. * Create a wallet from an existing mnemonic phrase or seed.
* *
* @param config is the wallet configuration (network type, seed, seed offset, isMultisig) * @param config is the wallet configuration (network type, seed, seed offset, isMultisig)
*/ */
static monero_wallet_keys* create_wallet_from_seed(const monero_wallet_config& config); static wownero_wallet_keys* create_wallet_from_seed(const wownero_wallet_config& config);
/** /**
* Create a wallet from an address, view key, and spend key. * Create a wallet from an address, view key, and spend key.
* *
* @param config is the wallet configuration (network type, address, view key, spend key, language) * @param config is the wallet configuration (network type, address, view key, spend key, language)
*/ */
static monero_wallet_keys* create_wallet_from_keys(const monero_wallet_config& config); static wownero_wallet_keys* create_wallet_from_keys(const wownero_wallet_config& config);
/** /**
* Get a list of available languages for the wallet's seed. * Get a list of available languages for the wallet's seed.
@@ -104,14 +104,14 @@ namespace monero {
/** /**
* Destruct the wallet. * Destruct the wallet.
*/ */
~monero_wallet_keys(); ~wownero_wallet_keys();
/** /**
* Supported wallet methods. * Supported wallet methods.
*/ */
bool is_view_only() const override { return m_is_view_only; } bool is_view_only() const override { return m_is_view_only; }
monero_version get_version() const override; wownero_version get_version() const override;
monero_network_type get_network_type() const override { return m_network_type; } wownero_network_type get_network_type() const override { return m_network_type; }
std::string get_seed() const override { return m_seed; } std::string get_seed() const override { return m_seed; }
std::string get_seed_language() const override { return m_language; } std::string get_seed_language() const override { return m_language; }
std::string get_private_view_key() const override { return m_prv_view_key; } std::string get_private_view_key() const override { return m_prv_view_key; }
@@ -120,19 +120,19 @@ namespace monero {
std::string get_public_spend_key() const override { return m_pub_spend_key; } std::string get_public_spend_key() const override { return m_pub_spend_key; }
std::string get_primary_address() const override { return m_primary_address; } std::string get_primary_address() const override { return m_primary_address; }
std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override; std::string get_address(const uint32_t account_idx, const uint32_t subaddress_idx) const override;
monero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const override; wownero_integrated_address get_integrated_address(const std::string& standard_address = "", const std::string& payment_id = "") const override;
monero_integrated_address decode_integrated_address(const std::string& integrated_address) const override; wownero_integrated_address decode_integrated_address(const std::string& integrated_address) const override;
monero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override; wownero_account get_account(const uint32_t account_idx, bool include_subaddresses) const override;
std::vector<monero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const override; std::vector<wownero_subaddress> get_subaddresses(const uint32_t account_idx, const std::vector<uint32_t>& subaddress_indices) const override;
std::string sign_message(const std::string& msg, monero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const override; std::string sign_message(const std::string& msg, wownero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const override;
monero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override; wownero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override;
void close(bool save = false) override; void close(bool save = false) override;
// --------------------------------- PRIVATE -------------------------------- // --------------------------------- PRIVATE --------------------------------
private: private:
bool m_is_view_only; bool m_is_view_only;
monero_network_type m_network_type; wownero_network_type m_network_type;
cryptonote::account_base m_account; cryptonote::account_base m_account;
std::string m_seed; std::string m_seed;
std::string m_language; std::string m_language;
File diff suppressed because it is too large Load Diff
@@ -52,23 +52,23 @@
#pragma once #pragma once
#include "daemon/monero_daemon_model.h" #include "daemon/wownero_daemon_model.h"
using namespace monero; using namespace wownero;
/** /**
* Public library interface. * Public library interface.
*/ */
namespace monero { namespace wownero {
/** /**
* Configures a wallet to create. * Configures a wallet to create.
*/ */
struct monero_wallet_config : public serializable_struct { struct wownero_wallet_config : public serializable_struct {
boost::optional<std::string> m_path; boost::optional<std::string> m_path;
boost::optional<std::string> m_password; boost::optional<std::string> m_password;
boost::optional<monero_network_type> m_network_type; boost::optional<wownero_network_type> m_network_type;
boost::optional<monero_rpc_connection> m_server; boost::optional<wownero_rpc_connection> m_server;
boost::optional<std::string> m_seed; boost::optional<std::string> m_seed;
boost::optional<std::string> m_seed_offset; boost::optional<std::string> m_seed_offset;
boost::optional<std::string> m_primary_address; boost::optional<std::string> m_primary_address;
@@ -81,21 +81,21 @@ namespace monero {
boost::optional<uint64_t> m_subaddress_lookahead; boost::optional<uint64_t> m_subaddress_lookahead;
boost::optional<bool> m_is_multisig; boost::optional<bool> m_is_multisig;
monero_wallet_config() {} wownero_wallet_config() {}
monero_wallet_config(const monero_wallet_config& config); wownero_wallet_config(const wownero_wallet_config& config);
monero_wallet_config copy() const; wownero_wallet_config copy() const;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static std::shared_ptr<monero_wallet_config> deserialize(const std::string& config_json); static std::shared_ptr<wownero_wallet_config> deserialize(const std::string& config_json);
}; };
/** /**
* Models a result of syncing a wallet. * Models a result of syncing a wallet.
*/ */
struct monero_sync_result : public serializable_struct { struct wownero_sync_result : public serializable_struct {
uint64_t m_num_blocks_fetched; uint64_t m_num_blocks_fetched;
bool m_received_money; bool m_received_money;
monero_sync_result() {} wownero_sync_result() {}
monero_sync_result(const uint64_t num_blocks_fetched, const bool received_money) : m_num_blocks_fetched(num_blocks_fetched), m_received_money(received_money) {} wownero_sync_result(const uint64_t num_blocks_fetched, const bool received_money) : m_num_blocks_fetched(num_blocks_fetched), m_received_money(received_money) {}
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
}; };
@@ -103,7 +103,7 @@ namespace monero {
/** /**
* Models a Monero subaddress. * Models a Monero subaddress.
*/ */
struct monero_subaddress : public serializable_struct { struct wownero_subaddress : public serializable_struct {
boost::optional<uint32_t> m_account_index; boost::optional<uint32_t> m_account_index;
boost::optional<uint32_t> m_index; boost::optional<uint32_t> m_index;
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
@@ -120,13 +120,13 @@ namespace monero {
/** /**
* Models a Monero account. * Models a Monero account.
*/ */
struct monero_account : public serializable_struct { struct wownero_account : public serializable_struct {
boost::optional<uint32_t> m_index; boost::optional<uint32_t> m_index;
boost::optional<std::string> m_primary_address; boost::optional<std::string> m_primary_address;
boost::optional<uint64_t> m_balance; boost::optional<uint64_t> m_balance;
boost::optional<uint64_t> m_unlocked_balance; boost::optional<uint64_t> m_unlocked_balance;
boost::optional<std::string> m_tag; boost::optional<std::string> m_tag;
std::vector<monero_subaddress> m_subaddresses; std::vector<wownero_subaddress> m_subaddresses;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
}; };
@@ -134,72 +134,72 @@ namespace monero {
/** /**
* Models an outgoing transfer destination. * Models an outgoing transfer destination.
*/ */
struct monero_destination { struct wownero_destination {
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
boost::optional<uint64_t> m_amount; boost::optional<uint64_t> m_amount;
monero_destination(boost::optional<std::string> address = boost::none, boost::optional<uint64_t> amount = boost::none) : m_address(address), m_amount(amount) {} wownero_destination(boost::optional<std::string> address = boost::none, boost::optional<uint64_t> amount = boost::none) : m_address(address), m_amount(amount) {}
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_destination>& destination); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_destination>& destination);
std::shared_ptr<monero_destination> copy(const std::shared_ptr<monero_destination>& src, const std::shared_ptr<monero_destination>& tgt) const; std::shared_ptr<wownero_destination> copy(const std::shared_ptr<wownero_destination>& src, const std::shared_ptr<wownero_destination>& tgt) const;
}; };
// forward declarations // forward declarations
struct monero_tx_wallet; struct wownero_tx_wallet;
struct monero_tx_query; struct wownero_tx_query;
struct monero_tx_set; struct wownero_tx_set;
/** /**
* Models a base transfer of funds to or from the wallet. * Models a base transfer of funds to or from the wallet.
* *
* TODO: m_is_incoming for api consistency * TODO: m_is_incoming for api consistency
*/ */
struct monero_transfer : serializable_struct { struct wownero_transfer : serializable_struct {
std::shared_ptr<monero_tx_wallet> m_tx; std::shared_ptr<wownero_tx_wallet> m_tx;
boost::optional<uint64_t> m_amount; boost::optional<uint64_t> m_amount;
boost::optional<uint32_t> m_account_index; boost::optional<uint32_t> m_account_index;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer>& transfer); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_transfer>& transfer);
virtual boost::optional<bool> is_incoming() const = 0; // derived class must implement virtual boost::optional<bool> is_incoming() const = 0; // derived class must implement
std::shared_ptr<monero_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const; std::shared_ptr<wownero_transfer> copy(const std::shared_ptr<wownero_transfer>& src, const std::shared_ptr<wownero_transfer>& tgt) const;
boost::optional<bool> is_outgoing() const { boost::optional<bool> is_outgoing() const {
if (is_incoming() == boost::none) return boost::none; if (is_incoming() == boost::none) return boost::none;
return !(*is_incoming()); return !(*is_incoming());
} }
void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other); void merge(const std::shared_ptr<wownero_transfer>& self, const std::shared_ptr<wownero_transfer>& other);
}; };
/** /**
* Models an incoming transfer of funds to the wallet. * Models an incoming transfer of funds to the wallet.
*/ */
struct monero_incoming_transfer : public monero_transfer { struct wownero_incoming_transfer : public wownero_transfer {
boost::optional<uint32_t> m_subaddress_index; boost::optional<uint32_t> m_subaddress_index;
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
boost::optional<uint64_t> m_num_suggested_confirmations; boost::optional<uint64_t> m_num_suggested_confirmations;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
std::shared_ptr<monero_incoming_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const; std::shared_ptr<wownero_incoming_transfer> copy(const std::shared_ptr<wownero_transfer>& src, const std::shared_ptr<wownero_transfer>& tgt) const;
std::shared_ptr<monero_incoming_transfer> copy(const std::shared_ptr<monero_incoming_transfer>& src, const std::shared_ptr<monero_incoming_transfer>& tgt) const; std::shared_ptr<wownero_incoming_transfer> copy(const std::shared_ptr<wownero_incoming_transfer>& src, const std::shared_ptr<wownero_incoming_transfer>& tgt) const;
boost::optional<bool> is_incoming() const; boost::optional<bool> is_incoming() const;
void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other); void merge(const std::shared_ptr<wownero_transfer>& self, const std::shared_ptr<wownero_transfer>& other);
void merge(const std::shared_ptr<monero_incoming_transfer>& self, const std::shared_ptr<monero_incoming_transfer>& other); void merge(const std::shared_ptr<wownero_incoming_transfer>& self, const std::shared_ptr<wownero_incoming_transfer>& other);
}; };
/** /**
* Models an outgoing transfer of funds from the wallet. * Models an outgoing transfer of funds from the wallet.
*/ */
struct monero_outgoing_transfer : public monero_transfer { struct wownero_outgoing_transfer : public wownero_transfer {
std::vector<uint32_t> m_subaddress_indices; std::vector<uint32_t> m_subaddress_indices;
std::vector<std::string> m_addresses; std::vector<std::string> m_addresses;
std::vector<std::shared_ptr<monero_destination>> m_destinations; std::vector<std::shared_ptr<wownero_destination>> m_destinations;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
std::shared_ptr<monero_outgoing_transfer> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const; std::shared_ptr<wownero_outgoing_transfer> copy(const std::shared_ptr<wownero_transfer>& src, const std::shared_ptr<wownero_transfer>& tgt) const;
std::shared_ptr<monero_outgoing_transfer> copy(const std::shared_ptr<monero_outgoing_transfer>& src, const std::shared_ptr<monero_outgoing_transfer>& tgt) const; std::shared_ptr<wownero_outgoing_transfer> copy(const std::shared_ptr<wownero_outgoing_transfer>& src, const std::shared_ptr<wownero_outgoing_transfer>& tgt) const;
boost::optional<bool> is_incoming() const; boost::optional<bool> is_incoming() const;
void merge(const std::shared_ptr<monero_transfer>& self, const std::shared_ptr<monero_transfer>& other); void merge(const std::shared_ptr<wownero_transfer>& self, const std::shared_ptr<wownero_transfer>& other);
void merge(const std::shared_ptr<monero_outgoing_transfer>& self, const std::shared_ptr<monero_outgoing_transfer>& other); void merge(const std::shared_ptr<wownero_outgoing_transfer>& self, const std::shared_ptr<wownero_outgoing_transfer>& other);
}; };
/** /**
@@ -207,40 +207,40 @@ namespace monero {
* *
* All transfers are returned except those that do not meet the criteria defined in this query. * All transfers are returned except those that do not meet the criteria defined in this query.
*/ */
struct monero_transfer_query : public monero_transfer { struct wownero_transfer_query : public wownero_transfer {
boost::optional<bool> m_is_incoming; boost::optional<bool> m_is_incoming;
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
std::vector<std::string> m_addresses; std::vector<std::string> m_addresses;
boost::optional<uint32_t> m_subaddress_index; boost::optional<uint32_t> m_subaddress_index;
std::vector<uint32_t> m_subaddress_indices; std::vector<uint32_t> m_subaddress_indices;
std::vector<std::shared_ptr<monero_destination>> m_destinations; std::vector<std::shared_ptr<wownero_destination>> m_destinations;
boost::optional<bool> m_has_destinations; boost::optional<bool> m_has_destinations;
boost::optional<std::shared_ptr<monero_tx_query>> m_tx_query; boost::optional<std::shared_ptr<wownero_tx_query>> m_tx_query;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_transfer_query>& transfer_query); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_transfer_query>& transfer_query);
static std::shared_ptr<monero_transfer_query> deserialize_from_block(const std::string& transfer_query_json); static std::shared_ptr<wownero_transfer_query> deserialize_from_block(const std::string& transfer_query_json);
std::shared_ptr<monero_transfer_query> copy(const std::shared_ptr<monero_transfer>& src, const std::shared_ptr<monero_transfer>& tgt) const; std::shared_ptr<wownero_transfer_query> copy(const std::shared_ptr<wownero_transfer>& src, const std::shared_ptr<wownero_transfer>& tgt) const;
std::shared_ptr<monero_transfer_query> copy(const std::shared_ptr<monero_transfer_query>& src, const std::shared_ptr<monero_transfer_query>& tgt) const; std::shared_ptr<wownero_transfer_query> copy(const std::shared_ptr<wownero_transfer_query>& src, const std::shared_ptr<wownero_transfer_query>& tgt) const;
boost::optional<bool> is_incoming() const; boost::optional<bool> is_incoming() const;
bool meets_criteria(monero_transfer* transfer, bool query_parent = true) const; bool meets_criteria(wownero_transfer* transfer, bool query_parent = true) const;
}; };
/** /**
* Models a Monero output with wallet extensions. * Models a Monero output with wallet extensions.
*/ */
struct monero_output_wallet : public monero_output { struct wownero_output_wallet : public wownero_output {
boost::optional<uint32_t> m_account_index; boost::optional<uint32_t> m_account_index;
boost::optional<uint32_t> m_subaddress_index; boost::optional<uint32_t> m_subaddress_index;
boost::optional<bool> m_is_spent; boost::optional<bool> m_is_spent;
boost::optional<bool> m_is_frozen; boost::optional<bool> m_is_frozen;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_wallet>& output_wallet); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_output_wallet>& output_wallet);
std::shared_ptr<monero_output_wallet> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const; std::shared_ptr<wownero_output_wallet> copy(const std::shared_ptr<wownero_output>& src, const std::shared_ptr<wownero_output>& tgt) const;
std::shared_ptr<monero_output_wallet> copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const; std::shared_ptr<wownero_output_wallet> copy(const std::shared_ptr<wownero_output_wallet>& src, const std::shared_ptr<wownero_output_wallet>& tgt) const;
void merge(const std::shared_ptr<monero_output>& self, const std::shared_ptr<monero_output>& other); void merge(const std::shared_ptr<wownero_output>& self, const std::shared_ptr<wownero_output>& other);
void merge(const std::shared_ptr<monero_output_wallet>& self, const std::shared_ptr<monero_output_wallet>& other); void merge(const std::shared_ptr<wownero_output_wallet>& self, const std::shared_ptr<wownero_output_wallet>& other);
}; };
/** /**
@@ -249,31 +249,31 @@ namespace monero {
* *
* All outputs are returned except those that do not meet the criteria defined in this query. * All outputs are returned except those that do not meet the criteria defined in this query.
*/ */
struct monero_output_query : public monero_output_wallet { struct wownero_output_query : public wownero_output_wallet {
std::vector<uint32_t> m_subaddress_indices; std::vector<uint32_t> m_subaddress_indices;
boost::optional<uint64_t> m_min_amount; boost::optional<uint64_t> m_min_amount;
boost::optional<uint64_t> m_max_amount; boost::optional<uint64_t> m_max_amount;
boost::optional<std::shared_ptr<monero_tx_query>> m_tx_query; boost::optional<std::shared_ptr<wownero_tx_query>> m_tx_query;
//boost::property_tree::ptree to_property_tree() const; //boost::property_tree::ptree to_property_tree() const;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_query>& output_query); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_output_query>& output_query);
static std::shared_ptr<monero_output_query> deserialize_from_block(const std::string& output_query_json); static std::shared_ptr<wownero_output_query> deserialize_from_block(const std::string& output_query_json);
std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output>& src, const std::shared_ptr<monero_output>& tgt) const; std::shared_ptr<wownero_output_query> copy(const std::shared_ptr<wownero_output>& src, const std::shared_ptr<wownero_output>& tgt) const;
std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output_wallet>& src, const std::shared_ptr<monero_output_wallet>& tgt) const; // TODO: necessary to override all super classes? std::shared_ptr<wownero_output_query> copy(const std::shared_ptr<wownero_output_wallet>& src, const std::shared_ptr<wownero_output_wallet>& tgt) const; // TODO: necessary to override all super classes?
std::shared_ptr<monero_output_query> copy(const std::shared_ptr<monero_output_query>& src, const std::shared_ptr<monero_output_query>& tgt) const; std::shared_ptr<wownero_output_query> copy(const std::shared_ptr<wownero_output_query>& src, const std::shared_ptr<wownero_output_query>& tgt) const;
bool meets_criteria(monero_output_wallet* output, bool query_parent = true) const; bool meets_criteria(wownero_output_wallet* output, bool query_parent = true) const;
}; };
/** /**
* Models a Monero transaction in the context of a wallet. * Models a Monero transaction in the context of a wallet.
*/ */
struct monero_tx_wallet : public monero_tx { struct wownero_tx_wallet : public wownero_tx {
boost::optional<std::shared_ptr<monero_tx_set>> m_tx_set; boost::optional<std::shared_ptr<wownero_tx_set>> m_tx_set;
boost::optional<bool> m_is_incoming; boost::optional<bool> m_is_incoming;
boost::optional<bool> m_is_outgoing; boost::optional<bool> m_is_outgoing;
std::vector<std::shared_ptr<monero_incoming_transfer>> m_incoming_transfers; std::vector<std::shared_ptr<wownero_incoming_transfer>> m_incoming_transfers;
boost::optional<std::shared_ptr<monero_outgoing_transfer>> m_outgoing_transfer; boost::optional<std::shared_ptr<wownero_outgoing_transfer>> m_outgoing_transfer;
boost::optional<std::string> m_note; boost::optional<std::string> m_note;
boost::optional<bool> m_is_locked; boost::optional<bool> m_is_locked;
boost::optional<uint64_t> m_input_sum; boost::optional<uint64_t> m_input_sum;
@@ -284,17 +284,17 @@ namespace monero {
boost::optional<std::string> m_extra_hex; boost::optional<std::string> m_extra_hex;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_wallet>& tx_wallet); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_tx_wallet>& tx_wallet);
std::shared_ptr<monero_tx_wallet> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const; std::shared_ptr<wownero_tx_wallet> copy(const std::shared_ptr<wownero_tx>& src, const std::shared_ptr<wownero_tx>& tgt) const;
std::shared_ptr<monero_tx_wallet> copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const; std::shared_ptr<wownero_tx_wallet> copy(const std::shared_ptr<wownero_tx_wallet>& src, const std::shared_ptr<wownero_tx_wallet>& tgt) const;
void merge(const std::shared_ptr<monero_tx>& self, const std::shared_ptr<monero_tx>& other); void merge(const std::shared_ptr<wownero_tx>& self, const std::shared_ptr<wownero_tx>& other);
void merge(const std::shared_ptr<monero_tx_wallet>& self, const std::shared_ptr<monero_tx_wallet>& other); void merge(const std::shared_ptr<wownero_tx_wallet>& self, const std::shared_ptr<wownero_tx_wallet>& other);
std::vector<std::shared_ptr<monero_transfer>> get_transfers() const; std::vector<std::shared_ptr<wownero_transfer>> get_transfers() const;
std::vector<std::shared_ptr<monero_transfer>> get_transfers(const monero_transfer_query& query) const; std::vector<std::shared_ptr<wownero_transfer>> get_transfers(const wownero_transfer_query& query) const;
std::vector<std::shared_ptr<monero_transfer>> filter_transfers(const monero_transfer_query& query); std::vector<std::shared_ptr<wownero_transfer>> filter_transfers(const wownero_transfer_query& query);
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_wallet() const; std::vector<std::shared_ptr<wownero_output_wallet>> get_outputs_wallet() const;
std::vector<std::shared_ptr<monero_output_wallet>> get_outputs_wallet(const monero_output_query& query) const; std::vector<std::shared_ptr<wownero_output_wallet>> get_outputs_wallet(const wownero_output_query& query) const;
std::vector<std::shared_ptr<monero_output_wallet>> filter_outputs_wallet(const monero_output_query& query); std::vector<std::shared_ptr<wownero_output_wallet>> filter_outputs_wallet(const wownero_output_query& query);
}; };
/** /**
@@ -302,7 +302,7 @@ namespace monero {
* *
* All transactions are returned except those that do not meet the criteria defined in this query. * All transactions are returned except those that do not meet the criteria defined in this query.
*/ */
struct monero_tx_query : public monero_tx_wallet { struct wownero_tx_query : public wownero_tx_wallet {
boost::optional<bool> m_is_outgoing; boost::optional<bool> m_is_outgoing;
boost::optional<bool> m_is_incoming; boost::optional<bool> m_is_incoming;
std::vector<std::string> m_hashes; std::vector<std::string> m_hashes;
@@ -312,17 +312,17 @@ namespace monero {
boost::optional<uint64_t> m_min_height; boost::optional<uint64_t> m_min_height;
boost::optional<uint64_t> m_max_height; boost::optional<uint64_t> m_max_height;
boost::optional<uint64_t> m_include_outputs; boost::optional<uint64_t> m_include_outputs;
boost::optional<std::shared_ptr<monero_transfer_query>> m_transfer_query; boost::optional<std::shared_ptr<wownero_transfer_query>> m_transfer_query;
boost::optional<std::shared_ptr<monero_output_query>> m_input_query; boost::optional<std::shared_ptr<wownero_output_query>> m_input_query;
boost::optional<std::shared_ptr<monero_output_query>> m_output_query; boost::optional<std::shared_ptr<wownero_output_query>> m_output_query;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_query>& tx_query); static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<wownero_tx_query>& tx_query);
static std::shared_ptr<monero_tx_query> deserialize_from_block(const std::string& tx_query_json); static std::shared_ptr<wownero_tx_query> deserialize_from_block(const std::string& tx_query_json);
std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx>& src, const std::shared_ptr<monero_tx>& tgt) const; std::shared_ptr<wownero_tx_query> copy(const std::shared_ptr<wownero_tx>& src, const std::shared_ptr<wownero_tx>& tgt) const;
std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx_wallet>& src, const std::shared_ptr<monero_tx_wallet>& tgt) const; // TODO: necessary to override all super classes? std::shared_ptr<wownero_tx_query> copy(const std::shared_ptr<wownero_tx_wallet>& src, const std::shared_ptr<wownero_tx_wallet>& tgt) const; // TODO: necessary to override all super classes?
std::shared_ptr<monero_tx_query> copy(const std::shared_ptr<monero_tx_query>& src, const std::shared_ptr<monero_tx_query>& tgt) const; std::shared_ptr<wownero_tx_query> copy(const std::shared_ptr<wownero_tx_query>& src, const std::shared_ptr<wownero_tx_query>& tgt) const;
bool meets_criteria(monero_tx_wallet* tx, bool query_children = true) const; bool meets_criteria(wownero_tx_wallet* tx, bool query_children = true) const;
}; };
/** /**
@@ -333,21 +333,21 @@ namespace monero {
* hex string which is needed in order to sign and submit the multisig * hex string which is needed in order to sign and submit the multisig
* transactions. * transactions.
*/ */
struct monero_tx_set : public serializable_struct { struct wownero_tx_set : public serializable_struct {
std::vector<std::shared_ptr<monero_tx_wallet>> m_txs; std::vector<std::shared_ptr<wownero_tx_wallet>> m_txs;
boost::optional<std::string> m_signed_tx_hex; boost::optional<std::string> m_signed_tx_hex;
boost::optional<std::string> m_unsigned_tx_hex; boost::optional<std::string> m_unsigned_tx_hex;
boost::optional<std::string> m_multisig_tx_hex; boost::optional<std::string> m_multisig_tx_hex;
//boost::property_tree::ptree to_property_tree() const; //boost::property_tree::ptree to_property_tree() const;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static monero_tx_set deserialize(const std::string& tx_set_json); static wownero_tx_set deserialize(const std::string& tx_set_json);
}; };
/** /**
* Monero integrated address model. * Monero integrated address model.
*/ */
struct monero_integrated_address : public serializable_struct { struct wownero_integrated_address : public serializable_struct {
std::string m_standard_address; std::string m_standard_address;
std::string m_payment_id; std::string m_payment_id;
std::string m_integrated_address; std::string m_integrated_address;
@@ -358,7 +358,7 @@ namespace monero {
/** /**
* Enumerates Monero network types. * Enumerates Monero network types.
*/ */
enum monero_tx_priority : uint8_t { enum wownero_tx_priority : uint8_t {
DEFAULT = 0, DEFAULT = 0,
UNIMPORTANT, UNIMPORTANT,
NORMAL, NORMAL,
@@ -368,13 +368,13 @@ namespace monero {
/** /**
* Configures a transaction to send, sweep, or create a payment URI. * Configures a transaction to send, sweep, or create a payment URI.
*/ */
struct monero_tx_config : public serializable_struct { struct wownero_tx_config : public serializable_struct {
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
boost::optional<uint64_t> m_amount; boost::optional<uint64_t> m_amount;
std::vector<std::shared_ptr<monero_destination>> m_destinations; std::vector<std::shared_ptr<wownero_destination>> m_destinations;
std::vector<uint32_t> m_subtract_fee_from; std::vector<uint32_t> m_subtract_fee_from;
boost::optional<std::string> m_payment_id; boost::optional<std::string> m_payment_id;
boost::optional<monero_tx_priority> m_priority; boost::optional<wownero_tx_priority> m_priority;
boost::optional<uint32_t> m_ring_size; boost::optional<uint32_t> m_ring_size;
boost::optional<uint64_t> m_fee; boost::optional<uint64_t> m_fee;
boost::optional<uint32_t> m_account_index; boost::optional<uint32_t> m_account_index;
@@ -388,18 +388,18 @@ namespace monero {
boost::optional<bool> m_sweep_each_subaddress; boost::optional<bool> m_sweep_each_subaddress;
boost::optional<std::string> m_key_image; boost::optional<std::string> m_key_image;
monero_tx_config() {} wownero_tx_config() {}
monero_tx_config(const monero_tx_config& config); wownero_tx_config(const wownero_tx_config& config);
monero_tx_config copy() const; wownero_tx_config copy() const;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
static std::shared_ptr<monero_tx_config> deserialize(const std::string& config_json); static std::shared_ptr<wownero_tx_config> deserialize(const std::string& config_json);
std::vector<std::shared_ptr<monero_destination>> get_normalized_destinations() const; std::vector<std::shared_ptr<wownero_destination>> get_normalized_destinations() const;
}; };
/** /**
* Models results from importing key images. * Models results from importing key images.
*/ */
struct monero_key_image_import_result : public serializable_struct { struct wownero_key_image_import_result : public serializable_struct {
boost::optional<uint64_t> m_height; boost::optional<uint64_t> m_height;
boost::optional<uint64_t> m_spent_amount; boost::optional<uint64_t> m_spent_amount;
boost::optional<uint64_t> m_unspent_amount; boost::optional<uint64_t> m_unspent_amount;
@@ -410,7 +410,7 @@ namespace monero {
/** /**
* Enumerates message verification results. * Enumerates message verification results.
*/ */
enum monero_message_signature_type : uint8_t { enum wownero_message_signature_type : uint8_t {
SIGN_WITH_SPEND_KEY = 0, SIGN_WITH_SPEND_KEY = 0,
SIGN_WITH_VIEW_KEY SIGN_WITH_VIEW_KEY
}; };
@@ -418,11 +418,11 @@ namespace monero {
/** /**
* Enumerates message verification results. * Enumerates message verification results.
*/ */
struct monero_message_signature_result : public serializable_struct { struct wownero_message_signature_result : public serializable_struct {
bool m_is_good; bool m_is_good;
uint32_t m_version; uint32_t m_version;
bool m_is_old; bool m_is_old;
monero_message_signature_type m_signature_type; wownero_message_signature_type m_signature_type;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
}; };
@@ -430,7 +430,7 @@ namespace monero {
/** /**
* Base class for results from checking a transaction or reserve proof. * Base class for results from checking a transaction or reserve proof.
*/ */
struct monero_check : public serializable_struct { struct wownero_check : public serializable_struct {
bool m_is_good; bool m_is_good;
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
@@ -439,7 +439,7 @@ namespace monero {
/** /**
* Results from checking a transaction key. * Results from checking a transaction key.
*/ */
struct monero_check_tx : public monero_check { struct wownero_check_tx : public wownero_check {
boost::optional<bool> m_in_tx_pool; boost::optional<bool> m_in_tx_pool;
boost::optional<uint64_t> m_num_confirmations; boost::optional<uint64_t> m_num_confirmations;
boost::optional<uint64_t> m_received_amount; boost::optional<uint64_t> m_received_amount;
@@ -450,7 +450,7 @@ namespace monero {
/** /**
* Results from checking a reserve proof. * Results from checking a reserve proof.
*/ */
struct monero_check_reserve : public monero_check { struct wownero_check_reserve : public wownero_check {
boost::optional<uint64_t> m_total_amount; boost::optional<uint64_t> m_total_amount;
boost::optional<uint64_t> m_unconfirmed_spent_amount; boost::optional<uint64_t> m_unconfirmed_spent_amount;
@@ -460,7 +460,7 @@ namespace monero {
/** /**
* Models information about a multisig wallet. * Models information about a multisig wallet.
*/ */
struct monero_multisig_info : serializable_struct { struct wownero_multisig_info : serializable_struct {
bool m_is_multisig; bool m_is_multisig;
bool m_is_ready; bool m_is_ready;
uint32_t m_threshold; uint32_t m_threshold;
@@ -474,7 +474,7 @@ namespace monero {
* multisig wallet's address xor another multisig hex to share with * multisig wallet's address xor another multisig hex to share with
* participants to create the wallet. * participants to create the wallet.
*/ */
struct monero_multisig_init_result : serializable_struct { struct wownero_multisig_init_result : serializable_struct {
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
boost::optional<std::string> m_multisig_hex; boost::optional<std::string> m_multisig_hex;
@@ -484,7 +484,7 @@ namespace monero {
/** /**
* Models the result of signing multisig tx hex. * Models the result of signing multisig tx hex.
*/ */
struct monero_multisig_sign_result : serializable_struct { struct wownero_multisig_sign_result : serializable_struct {
boost::optional<std::string> m_signed_multisig_tx_hex; boost::optional<std::string> m_signed_multisig_tx_hex;
std::vector<std::string> m_tx_hashes; std::vector<std::string> m_tx_hashes;
@@ -494,15 +494,15 @@ namespace monero {
/** /**
* Monero address book entry model. * Monero address book entry model.
*/ */
struct monero_address_book_entry : serializable_struct { struct wownero_address_book_entry : serializable_struct {
boost::optional<uint64_t> m_index; // TODO: not boost::optional boost::optional<uint64_t> m_index; // TODO: not boost::optional
boost::optional<std::string> m_address; boost::optional<std::string> m_address;
boost::optional<std::string> m_description; boost::optional<std::string> m_description;
boost::optional<std::string> m_payment_id; boost::optional<std::string> m_payment_id;
monero_address_book_entry() {} wownero_address_book_entry() {}
monero_address_book_entry(uint64_t index, const std::string& address, const std::string& description) : m_index(index), m_address(address), m_description(description) {} wownero_address_book_entry(uint64_t index, const std::string& address, const std::string& description) : m_index(index), m_address(address), m_description(description) {}
monero_address_book_entry(uint64_t index, const std::string& address, const std::string& description, const std::string& payment_id) : m_index(index), m_address(address), m_description(description), m_payment_id(payment_id) {} wownero_address_book_entry(uint64_t index, const std::string& address, const std::string& description, const std::string& payment_id) : m_index(index), m_address(address), m_description(description), m_payment_id(payment_id) {}
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
}; };
} }
@@ -1,10 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include "wallet2.h" #include "wallet2.h"
#include "wallet/monero_wallet_full.h" #include "wallet/wownero_wallet_full.h"
#include "utils/gen_utils.h" #include "utils/gen_utils.h"
#include "utils/monero_utils.h" #include "utils/wownero_utils.h"
//#include "monero_wallet_model.h" //#include "wownero_wallet_model.h"
using namespace std; using namespace std;
@@ -13,16 +13,16 @@ using namespace std;
// constants // constants
const int LOG_LEVEL = 2; const int LOG_LEVEL = 2;
const string DAEMON_URI = "http://localhost:28081"; const string DAEMON_URI = "http://localhost:28081";
const monero_network_type NETWORK_TYPE = monero_network_type::TESTNET; const wownero_network_type NETWORK_TYPE = wownero_network_type::TESTNET;
// ------------------------ MULTISIG STRESS TEST ------------------------------ // ------------------------ MULTISIG STRESS TEST ------------------------------
void synchronize_multisig_participants(vector<monero_wallet*> wallets) { void synchronize_multisig_participants(vector<wownero_wallet*> wallets) {
// collect multisig hex of all participants to synchronize // collect multisig hex of all participants to synchronize
vector<string> multisig_hexes; vector<string> multisig_hexes;
for (int i = 0; i < wallets.size(); i++) { for (int i = 0; i < wallets.size(); i++) {
monero_wallet* wallet = wallets[i]; wownero_wallet* wallet = wallets[i];
wallet->sync(); wallet->sync();
multisig_hexes.push_back(wallet->export_multisig_hex()); // TODO: does wallet need saved? multisig_hexes.push_back(wallet->export_multisig_hex()); // TODO: does wallet need saved?
} }
@@ -31,13 +31,13 @@ void synchronize_multisig_participants(vector<monero_wallet*> wallets) {
for (int i = 0; i < wallets.size(); i++) { for (int i = 0; i < wallets.size(); i++) {
vector<string> peer_multisig_hexes; vector<string> peer_multisig_hexes;
for (int j = 0; j < wallets.size(); j++) if (j != i) peer_multisig_hexes.push_back(multisig_hexes[j]); for (int j = 0; j < wallets.size(); j++) if (j != i) peer_multisig_hexes.push_back(multisig_hexes[j]);
monero_wallet* wallet = wallets[i]; wownero_wallet* wallet = wallets[i];
wallet->sync(); // TODO monero-project: creating multisig tx fails if wallet not explicitly synced before import_multisig_hex: https://github.com/monero-project/monero/issues/6850 wallet->sync(); // TODO wownero-project: creating multisig tx fails if wallet not explicitly synced before import_multisig_hex: https://github.com/wownero-project/wownero/issues/6850
wallet->import_multisig_hex(peer_multisig_hexes); wallet->import_multisig_hex(peer_multisig_hexes);
} }
} }
void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*> participants, int M, int N, int account_idx, int num_addresses_to_fund) { void init_multisig_wallets(wownero_wallet* funding_wallet, vector<wownero_wallet*> participants, int M, int N, int account_idx, int num_addresses_to_fund) {
std::cout << "init_multisig_wallets(" << M << ", " << N << ")" << std::endl; std::cout << "init_multisig_wallets(" << M << ", " << N << ")" << std::endl;
if (participants.size() != N) throw std::runtime_error("participants != N"); if (participants.size() != N) throw std::runtime_error("participants != N");
@@ -45,21 +45,21 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
// prepare multisig hexes // prepare multisig hexes
vector<string> prepared_multisig_hexes; vector<string> prepared_multisig_hexes;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
monero_wallet* participant = participants[i]; wownero_wallet* participant = participants[i];
prepared_multisig_hexes.push_back(participant->prepare_multisig()); prepared_multisig_hexes.push_back(participant->prepare_multisig());
} }
// make wallets multisig // make wallets multisig
vector<string> made_multisig_hexes; vector<string> made_multisig_hexes;
for (int i = 0; i < participants.size(); i++) { for (int i = 0; i < participants.size(); i++) {
monero_wallet* participant = participants[i]; wownero_wallet* participant = participants[i];
// // test bad input // // test bad input
// try { // try {
// participant.make_multisig(Arrays.asList("asd", "dsa"), M, TestUtils.WALLET_PASSWORD); // participant.make_multisig(Arrays.asList("asd", "dsa"), M, TestUtils.WALLET_PASSWORD);
// throw new RuntimeException("Should have thrown error making wallet multisig with incorrect values"); // throw new RuntimeException("Should have thrown error making wallet multisig with incorrect values");
// } catch (MoneroError e) { // } catch (MoneroError e) {
// assertEquals("basic_string", e.getMessage()); // TODO (monero-project): improve error message https://github.com/monero-project/monero/issues/8493 // assertEquals("basic_string", e.getMessage()); // TODO (wownero-project): improve error message https://github.com/wownero-project/wownero/issues/8493
// } // }
// collect prepared multisig hexes from wallet's peers // collect prepared multisig hexes from wallet's peers
@@ -90,7 +90,7 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
// exchange multisig keys with each wallet and collect results // exchange multisig keys with each wallet and collect results
vector<string> exchange_multisig_hexes; vector<string> exchange_multisig_hexes;
for (int j = 0; j < participants.size(); j++) { for (int j = 0; j < participants.size(); j++) {
monero_wallet* participant = participants[j]; wownero_wallet* participant = participants[j];
// // test bad input // // test bad input
// try { // try {
@@ -105,7 +105,7 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
for (int k = 0; k < participants.size(); k++) if (k != j) peer_multisig_hexes.push_back(prev_multisig_hexes[k]); for (int k = 0; k < participants.size(); k++) if (k != j) peer_multisig_hexes.push_back(prev_multisig_hexes[k]);
// import the multisig hexes of the wallet's peers // import the multisig hexes of the wallet's peers
monero_multisig_init_result result = participant->exchange_multisig_keys(peer_multisig_hexes, ""); wownero_multisig_init_result result = participant->exchange_multisig_keys(peer_multisig_hexes, "");
// test result // test result
if (result.m_multisig_hex->empty()) throw runtime_error("m_multisig_hex is empty"); if (result.m_multisig_hex->empty()) throw runtime_error("m_multisig_hex is empty");
@@ -124,8 +124,8 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
} }
// validate final multisig // validate final multisig
monero_wallet* participant = participants[0]; wownero_wallet* participant = participants[0];
monero_utils::validate_address(participant->get_primary_address(), NETWORK_TYPE); wownero_utils::validate_address(participant->get_primary_address(), NETWORK_TYPE);
//test_multisig_info(participant->get_multisig_info(), M, N); // TODO //test_multisig_info(participant->get_multisig_info(), M, N); // TODO
string seed = participant->get_seed(); string seed = participant->get_seed();
if (seed.empty()) throw std::runtime_error("seed should not be empty"); if (seed.empty()) throw std::runtime_error("seed should not be empty");
@@ -147,9 +147,9 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
for (int i = 0; i < account_idx; i++) participant->create_account(); for (int i = 0; i < account_idx; i++) participant->create_account();
// get destinations to subaddresses within the account of the multisig wallet // get destinations to subaddresses within the account of the multisig wallet
vector<shared_ptr<monero_destination>> destinations; vector<shared_ptr<wownero_destination>> destinations;
for (int i = 0; i < num_addresses_to_fund; i++) { for (int i = 0; i < num_addresses_to_fund; i++) {
shared_ptr<monero_destination> destination = make_shared<monero_destination>(); shared_ptr<wownero_destination> destination = make_shared<wownero_destination>();
destination->m_address = participant->get_address(account_idx, i); destination->m_address = participant->get_address(account_idx, i);
destination->m_amount = 200000000000; // TODO: add a 0 for 2 XMR destination->m_amount = 200000000000; // TODO: add a 0 for 2 XMR
destinations.push_back(destination); destinations.push_back(destination);
@@ -162,12 +162,12 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
// send funds from the main test wallet to destinations in the first multisig wallet // send funds from the main test wallet to destinations in the first multisig wallet
std::cout << "Sending funds from main wallet" << std::endl; std::cout << "Sending funds from main wallet" << std::endl;
monero_tx_config tx_config; wownero_tx_config tx_config;
tx_config.m_account_index = 0; tx_config.m_account_index = 0;
tx_config.m_destinations = destinations; tx_config.m_destinations = destinations;
tx_config.m_relay = true; tx_config.m_relay = true;
shared_ptr<monero_tx_wallet> tx = funding_wallet->create_tx(tx_config); shared_ptr<wownero_tx_wallet> tx = funding_wallet->create_tx(tx_config);
monero_utils::free(tx); wownero_utils::free(tx);
// attempt to start mining // attempt to start mining
std::cout << "Starting mining" << std::endl; std::cout << "Starting mining" << std::endl;
@@ -181,8 +181,8 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
gen_utils::wait_for(5000); gen_utils::wait_for(5000);
// fetch and test outputs // fetch and test outputs
monero_output_query query; wownero_output_query query;
vector<shared_ptr<monero_output_wallet>> outputs = participant->get_outputs(query); vector<shared_ptr<wownero_output_wallet>> outputs = participant->get_outputs(query);
if (outputs.size() == 0) std::cout << "No output reported yet" << endl; if (outputs.size() == 0) std::cout << "No output reported yet" << endl;
else { else {
@@ -194,13 +194,13 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
// outputs are not spent // outputs are not spent
// break if output is unlocked // break if output is unlocked
shared_ptr<monero_tx_wallet> tx = std::static_pointer_cast<monero_tx_wallet>(outputs[0]->m_tx); shared_ptr<wownero_tx_wallet> tx = std::static_pointer_cast<wownero_tx_wallet>(outputs[0]->m_tx);
if (!tx->m_is_locked.get()) { if (!tx->m_is_locked.get()) {
monero_utils::free(outputs); wownero_utils::free(outputs);
break; break;
} }
} }
monero_utils::free(outputs); wownero_utils::free(outputs);
} }
// stop mining // stop mining
@@ -210,12 +210,12 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
for (int i = 0; i < num_addresses_to_fund; i++) { for (int i = 0; i < num_addresses_to_fund; i++) {
if (participant->get_unlocked_balance(account_idx, i) == 0) throw std::runtime_error("balance expected to be > 0"); if (participant->get_unlocked_balance(account_idx, i) == 0) throw std::runtime_error("balance expected to be > 0");
} }
monero_output_query output_query; wownero_output_query output_query;
output_query.m_account_index = account_idx; output_query.m_account_index = account_idx;
vector<shared_ptr<monero_output_wallet>> outputs = participant->get_outputs(output_query); vector<shared_ptr<wownero_output_wallet>> outputs = participant->get_outputs(output_query);
if (outputs.size() == 0) throw runtime_error("no outputs returned"); if (outputs.size() == 0) throw runtime_error("no outputs returned");
if (outputs.size() < 3) std::cout << "WARNING: not one output per subaddress?"; if (outputs.size() < 3) std::cout << "WARNING: not one output per subaddress?";
monero_utils::free(outputs); wownero_utils::free(outputs);
// wallet requires importing multisig to be reliable // wallet requires importing multisig to be reliable
if (!participant->is_multisig_import_needed()) throw std::runtime_error("multisig import should be needed"); if (!participant->is_multisig_import_needed()) throw std::runtime_error("multisig import should be needed");
@@ -250,7 +250,7 @@ void init_multisig_wallets(monero_wallet* funding_wallet, vector<monero_wallet*>
// } // }
} }
void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = "") { void test_multisig_stress(wownero_wallet* funding_wallet, string wallet_name = "") {
// test config // test config
int M = 2; int M = 2;
@@ -264,10 +264,10 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = ""
std::cout << "Stress testing multisig wallets: " << wallet_path << std::endl; std::cout << "Stress testing multisig wallets: " << wallet_path << std::endl;
// open or create multisig wallets // open or create multisig wallets
vector<monero_wallet*> participants; vector<wownero_wallet*> participants;
try { try {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
participants.push_back(monero_wallet_full::open_wallet(wallet_path + string("_") + std::to_string(i), "", NETWORK_TYPE)); participants.push_back(wownero_wallet_full::open_wallet(wallet_path + string("_") + std::to_string(i), "", NETWORK_TYPE));
} }
for (int i = 0; i < participants.size(); i++) { for (int i = 0; i < participants.size(); i++) {
participants[i]->set_daemon_connection(DAEMON_URI); participants[i]->set_daemon_connection(DAEMON_URI);
@@ -276,11 +276,11 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = ""
} }
} catch (const exception& e) { } catch (const exception& e) {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
monero_wallet_config wallet_config; wownero_wallet_config wallet_config;
wallet_config.m_path = wallet_path + string("_") + std::to_string(i); wallet_config.m_path = wallet_path + string("_") + std::to_string(i);
wallet_config.m_network_type = monero_network_type::TESTNET; wallet_config.m_network_type = wownero_network_type::TESTNET;
wallet_config.m_server = monero_rpc_connection(DAEMON_URI); wallet_config.m_server = wownero_rpc_connection(DAEMON_URI);
participants.push_back(monero_wallet_full::create_wallet(wallet_config)); participants.push_back(wownero_wallet_full::create_wallet(wallet_config));
} }
for (int i = 0; i < participants.size(); i++) { for (int i = 0; i < participants.size(); i++) {
participants[i]->sync(); participants[i]->sync();
@@ -288,19 +288,19 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = ""
} }
init_multisig_wallets(funding_wallet, participants, M, N, account_idx, num_addresses_to_fund); init_multisig_wallets(funding_wallet, participants, M, N, account_idx, num_addresses_to_fund);
} }
monero_wallet* participant = participants[0]; wownero_wallet* participant = participants[0];
// start mining // start mining
funding_wallet->start_mining(1, false, false); funding_wallet->start_mining(1, false, false);
// receive notifications when the wallet receives funds // receive notifications when the wallet receives funds
struct : monero_wallet_listener { struct : wownero_wallet_listener {
void on_output_received(const monero_output_wallet& output) { void on_output_received(const wownero_output_wallet& output) {
cout << "Wallet received funds!" << endl; cout << "Wallet received funds!" << endl;
uint64_t amount = output.m_amount.get(); uint64_t amount = output.m_amount.get();
string tx_hash = output.m_tx->m_hash.get(); string tx_hash = output.m_tx->m_hash.get();
bool is_confirmed = output.m_tx->m_is_confirmed.get(); bool is_confirmed = output.m_tx->m_is_confirmed.get();
bool is_locked = static_pointer_cast<monero_tx_wallet>(output.m_tx)->m_is_locked.get(); bool is_locked = static_pointer_cast<wownero_tx_wallet>(output.m_tx)->m_is_locked.get();
int account_index = output.m_account_index.get(); int account_index = output.m_account_index.get();
int subaddress_index = output.m_subaddress_index.get(); int subaddress_index = output.m_subaddress_index.get();
} }
@@ -319,30 +319,30 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = ""
synchronize_multisig_participants(participants); synchronize_multisig_participants(participants);
// create txs to cycle funds // create txs to cycle funds
monero_tx_config tx_config; wownero_tx_config tx_config;
tx_config.m_account_index = account_idx; tx_config.m_account_index = account_idx;
for (int i = 0; i < num_addresses_to_fund; i++) { for (int i = 0; i < num_addresses_to_fund; i++) {
shared_ptr<monero_destination> destination = make_shared<monero_destination>(); shared_ptr<wownero_destination> destination = make_shared<wownero_destination>();
destination->m_address = participant->get_address(0, i); destination->m_address = participant->get_address(0, i);
destination->m_amount = unlocked_balance / (num_addresses_to_fund * 3); destination->m_amount = unlocked_balance / (num_addresses_to_fund * 3);
tx_config.m_destinations.push_back(destination); tx_config.m_destinations.push_back(destination);
} }
vector<shared_ptr<monero_tx_wallet>> txs = participant->create_txs(tx_config); vector<shared_ptr<wownero_tx_wallet>> txs = participant->create_txs(tx_config);
if (txs.empty()) throw runtime_error("txs is empty"); if (txs.empty()) throw runtime_error("txs is empty");
if ((*txs[0]->m_tx_set.get()->m_multisig_tx_hex).empty()) throw runtime_error("multisig_tx_hex is empty"); if ((*txs[0]->m_tx_set.get()->m_multisig_tx_hex).empty()) throw runtime_error("multisig_tx_hex is empty");
//assertNull(txSet.getSignedTxHex()); //assertNull(txSet.getSignedTxHex());
//assertNull(txSet.getUnsignedTxHex()); //assertNull(txSet.getUnsignedTxHex());
// describe multisig tx hex and test // describe multisig tx hex and test
monero_tx_set tx_set = participant->describe_tx_set(*txs[0]->m_tx_set.get()); wownero_tx_set tx_set = participant->describe_tx_set(*txs[0]->m_tx_set.get());
monero_utils::free(tx_set.m_txs); wownero_utils::free(tx_set.m_txs);
// sign the tx with participants 1 through m - 1 to meet threshold // sign the tx with participants 1 through m - 1 to meet threshold
string multisig_tx_hex = txs[0]->m_tx_set.get()->m_multisig_tx_hex.get(); string multisig_tx_hex = txs[0]->m_tx_set.get()->m_multisig_tx_hex.get();
monero_utils::free(txs); wownero_utils::free(txs);
std::cout << "Signing" << std::endl; std::cout << "Signing" << std::endl;
for (int j = 1; j < M; j++) { for (int j = 1; j < M; j++) {
monero_multisig_sign_result result = participants[j]->sign_multisig_tx_hex(multisig_tx_hex); wownero_multisig_sign_result result = participants[j]->sign_multisig_tx_hex(multisig_tx_hex);
multisig_tx_hex = result.m_signed_multisig_tx_hex.get(); multisig_tx_hex = result.m_signed_multisig_tx_hex.get();
} }
@@ -353,15 +353,15 @@ void test_multisig_stress(monero_wallet* funding_wallet, string wallet_name = ""
std::cout << "Tx submitted successfully!" << std::endl; std::cout << "Tx submitted successfully!" << std::endl;
// fetch the wallet's multisig txs // fetch the wallet's multisig txs
monero_tx_query tx_query; wownero_tx_query tx_query;
tx_query.m_hashes = tx_hashes; tx_query.m_hashes = tx_hashes;
vector<shared_ptr<monero_tx_wallet>> multisig_txs = participant->get_txs(tx_query); vector<shared_ptr<wownero_tx_wallet>> multisig_txs = participant->get_txs(tx_query);
if (multisig_txs.size() != tx_hashes.size()) throw runtime_error("multisigTxs.size() != txHashes.size()"); if (multisig_txs.size() != tx_hashes.size()) throw runtime_error("multisigTxs.size() != txHashes.size()");
vector<shared_ptr<monero_tx_wallet>> all_txs = participant->get_txs(); vector<shared_ptr<wownero_tx_wallet>> all_txs = participant->get_txs();
num_txs = all_txs.size(); num_txs = all_txs.size();
std::cout << "All txs size: " << all_txs.size() << std::endl; std::cout << "All txs size: " << all_txs.size() << std::endl;
monero_utils::free(multisig_txs); wownero_utils::free(multisig_txs);
monero_utils::free(all_txs); wownero_utils::free(all_txs);
if (num_txs >= max_txs) break; if (num_txs >= max_txs) break;
} }
} catch (const exception& e) { } catch (const exception& e) {
@@ -415,26 +415,26 @@ int main(int argc, const char* argv[]) {
int network_type = 2; int network_type = 2;
// load test wallet // load test wallet
monero_wallet* wallet = monero_wallet_full::open_wallet("../../test_wallets/test_wallet_1", "supersecretpassword123", monero_network_type::TESTNET); wownero_wallet* wallet = wownero_wallet_full::open_wallet("../../test_wallets/test_wallet_1", "supersecretpassword123", wownero_network_type::TESTNET);
wallet->set_daemon_connection(DAEMON_URI); wallet->set_daemon_connection(DAEMON_URI);
wallet->sync(); wallet->sync();
wallet->start_syncing(5000); wallet->start_syncing(5000);
// get txs // get txs
vector<shared_ptr<monero_tx_wallet>> txs = wallet->get_txs(); vector<shared_ptr<wownero_tx_wallet>> txs = wallet->get_txs();
MINFO("Wallet has " << txs.size() << " txs"); MINFO("Wallet has " << txs.size() << " txs");
for (int i = 0; i < txs.size() && i < 10; i++) MINFO(txs[i]->serialize()); for (int i = 0; i < txs.size() && i < 10; i++) MINFO(txs[i]->serialize());
monero_utils::free(txs); wownero_utils::free(txs);
// get transfers // get transfers
vector<shared_ptr<monero_transfer>> transfers = wallet->get_transfers(monero_transfer_query()); vector<shared_ptr<wownero_transfer>> transfers = wallet->get_transfers(wownero_transfer_query());
MINFO("Wallet has " << transfers.size() << " transfers"); MINFO("Wallet has " << transfers.size() << " transfers");
monero_utils::free(transfers); wownero_utils::free(transfers);
// get outputs // get outputs
vector<shared_ptr<monero_output_wallet>> outputs = wallet->get_outputs(monero_output_query()); vector<shared_ptr<wownero_output_wallet>> outputs = wallet->get_outputs(wownero_output_query());
MINFO("Wallet has " << outputs.size() << " outputs"); MINFO("Wallet has " << outputs.size() << " outputs");
monero_utils::free(outputs); wownero_utils::free(outputs);
// multisig stress test // multisig stress test
test_multisig_stress(wallet); test_multisig_stress(wallet);
-28
View File
@@ -1,28 +0,0 @@
TODO
rename monero-project submodule to monero-project
add device and device_trezor after testing
in models, strings and pointers do not have to be boost::optional
preserve rpc error codes, just throwing runtime_error now
monero_wallet.cpp move utilities in monero_namespace to be private
polish model: remove all boost::optional from model to be consistent with monero-project?
ensure model toPropertyTrees(), etc are not unecessarily copying return objects
monero_wallet_listener should be a class?
way to use copy constructors instead of query copy(sp, sp) methods?
separate wallet default impl from must impl
create_tx and send_tx request arg should be const; need to copy
should not need wallet.h / wallet.cpp as dependency, why are GUI deps needed?
make model fields private and use accessors / mutators?
remove jstring2string, be consistent with other string inits
number of mining threads should be uint32_t instead of uint64_t
getReserveProofAccount() jni seg fault
sign/submit tx
nodeToTransferRequest(), etc need a final else catch-all
MoneroWallet getChainHeight() calling daemon connection every time, surely better way
toPropertyTree() should take node as parameter; optimize memory elsewhere (move shared_ptrs, etc)
enable debug logging
model accessors/mutators/chaining?
further automate build process
LOW PRIORITY
throw MoneroErrors with error codes instead of runtime_errors
handle e.g. restricted or hw wallet limitations in wallet_rpc_server, e.g. on_import_outputs?
+94
View File
@@ -0,0 +1,94 @@
#!/bin/bash
# this file is for installing static dependencies, in case you need those.
# works on ubuntu20/22
#run as root/sudo
export OPENSSL_ROOT_DIR=/usr/local/openssl/
export CFLAGS="-fPIC"
export CPPFLAGS="-fPIC"
export CXXFLAGS="-fPIC"
# boost
wget https://boostorg.jfrog.io/artifactory/main/release/1.73.0/source/boost_1_73_0.tar.gz
tar -xzf boost_1_73_0.tar.gz
pushd boost_1_73_0
./bootstrap.sh
./b2 --with-atomic --with-system --with-filesystem --with-thread --with-date_time --with-chrono --with-regex --with-serialization --with-program_options --with-locale variant=release link=static runtime-link=static cflags="-fPIC" cxxflags="-fPIC" install -a --prefix=/usr/local/
popd
rm -rf boost_1_73_0
# openssl
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar -xvf openssl-1.1.1i.tar.gz
rm -xvf openssl-1.1.1i.tar.gz
pushd openssl-1.1.1i
./config no-shared no-dso --prefix=/usr/local/openssl
make -j8
make install
popd
rm -rf openssl-1.1.1i
# expat
wget https://github.com/libexpat/libexpat/releases/download/R_2_4_8/expat-2.4.8.tar.bz2
tar -xf expat-2.4.8.tar.bz2
rm expat-2.4.8.tar.bz2
pushd expat-2.4.8
./configure --enable-static --disable-shared --prefix=/usr/local/expat/
make -j8
make -j8 install
popd
rm -rf expat-2.4.8
# libunbound
wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.16.2.tar.gz
tar -xzf unbound-1.16.2.tar.gz
rm unbound-1.16.2.tar.gz
pushd unbound-1.16.2
./configure --disable-shared --enable-static --without-pyunbound --with-libexpat=/usr/local/expat/ --with-ssl=/usr/local/openssl/ --with-libevent=no --without-pythonmodule --disable-flto --with-pthreads --with-libunbound-only --with-pic
make -j8
make -j8 install
popd
rm -rf unbound-1.16.2
# zmq
git clone -b v4.3.2 --depth 1 https://github.com/zeromq/libzmq
pushd libzmq
git reset --hard a84ffa12b2eb3569ced199660bac5ad128bff1f0
./autogen.sh
./configure --disable-shared --enable-static --disable-libunwind --with-libsodium
make -j8
make -j8 install
popd
rm -rf libzmq
# zlib
git clone -b v1.2.11 --depth 1 https://github.com/madler/zlib
pushd zlib
git reset --hard cacf7f1d4e3d44d871b605da3b647f07d718623f
./configure --static --prefix=/usr/local/zlib
make -j8
make -j8 install
popd
rm -rf zlib
# libusb
git clone -b v1.0.23 --depth 1 https://github.com/libusb/libusb
pushd libusb
git reset --hard e782eeb2514266f6738e242cdcb18e3ae1ed06fa
./autogen.sh --disable-shared --enable-static
make -j8
make -j8 install
popd
rm -rf libusb
# libsodium
# on ubuntu, `libsodium-dev` already comes with a static .a
# miniupnp
git clone -b miniupnpc_2_2_1 --depth 1 https://github.com/miniupnp/miniupnp.git
pushd miniupnp/miniupnpc
git reset --hard 544e6fcc73c5ad9af48a8985c94f0f1d742ef2e0
cmake -Bbuild -DUPNPC_BUILD_STATIC=1 -DUPNPC_BUILD_SHARED=OFF -DUPNPC_BUILD_TESTS=OFF -DUPNPC_BUILD_SAMPLE=OFF .
sudo make -Cbuild -j8 install
popd
rm -rf miniupnp