mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
High level library draft for Wallets : Open, Generate
This commit is contained in:
parent
5f31331c6e
commit
c1ea0ef1fc
@ -69,8 +69,8 @@ else()
|
|||||||
else()
|
else()
|
||||||
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
|
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} -maes")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} -maes -fPIC")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} -maes")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} -maes -fPIC")
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
|
||||||
endif()
|
endif()
|
||||||
|
@ -11,6 +11,7 @@ file(GLOB_RECURSE SIMPLEWALLET simplewallet/*)
|
|||||||
file(GLOB_RECURSE CONN_TOOL connectivity_tool/*)
|
file(GLOB_RECURSE CONN_TOOL connectivity_tool/*)
|
||||||
file(GLOB_RECURSE WALLET wallet/*)
|
file(GLOB_RECURSE WALLET wallet/*)
|
||||||
file(GLOB_RECURSE MINER miner/*)
|
file(GLOB_RECURSE MINER miner/*)
|
||||||
|
file(GLOB_RECURSE MONERO_WALLET_WRAPPER monero_wallet_wrapper/*)
|
||||||
|
|
||||||
source_group(common FILES ${COMMON})
|
source_group(common FILES ${COMMON})
|
||||||
source_group(crypto FILES ${CRYPTO})
|
source_group(crypto FILES ${CRYPTO})
|
||||||
@ -23,6 +24,7 @@ source_group(simplewallet FILES ${SIMPLEWALLET})
|
|||||||
source_group(connectivity-tool FILES ${CONN_TOOL})
|
source_group(connectivity-tool FILES ${CONN_TOOL})
|
||||||
source_group(wallet FILES ${WALLET})
|
source_group(wallet FILES ${WALLET})
|
||||||
source_group(simpleminer FILES ${MINER})
|
source_group(simpleminer FILES ${MINER})
|
||||||
|
source_group(monero_wallet_wrapper FILES ${MONERO_WALLET_WRAPPER})
|
||||||
|
|
||||||
add_library(common ${COMMON})
|
add_library(common ${COMMON})
|
||||||
add_library(crypto ${CRYPTO})
|
add_library(crypto ${CRYPTO})
|
||||||
@ -41,6 +43,14 @@ add_dependencies(daemon version)
|
|||||||
add_dependencies(rpc version)
|
add_dependencies(rpc version)
|
||||||
add_dependencies(simplewallet version)
|
add_dependencies(simplewallet version)
|
||||||
|
|
||||||
set_property(TARGET common crypto cryptonote_core rpc wallet PROPERTY FOLDER "libs")
|
|
||||||
|
add_library(monerowallet SHARED ${MONERO_WALLET_WRAPPER})
|
||||||
|
add_dependencies(monerowallet wallet)
|
||||||
|
target_link_libraries(monerowallet wallet cryptonote_core crypto common upnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
||||||
|
|
||||||
|
#target_link_libraries(monerowallet wallet rpc cryptonote_core crypto common upnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
||||||
|
|
||||||
|
set_property(TARGET common crypto cryptonote_core rpc wallet monerowallet PROPERTY FOLDER "libs")
|
||||||
set_property(TARGET daemon simplewallet connectivity_tool simpleminer PROPERTY FOLDER "prog")
|
set_property(TARGET daemon simplewallet connectivity_tool simpleminer PROPERTY FOLDER "prog")
|
||||||
set_property(TARGET daemon PROPERTY OUTPUT_NAME "bitmonerod")
|
set_property(TARGET daemon PROPERTY OUTPUT_NAME "bitmonerod")
|
||||||
|
|
||||||
|
98
src/monero_wallet_wrapper/MoneroWallet.cc
Normal file
98
src/monero_wallet_wrapper/MoneroWallet.cc
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include "MoneroWallet.hh"
|
||||||
|
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "wallet/wallet2.h"
|
||||||
|
|
||||||
|
using namespace Monero;
|
||||||
|
|
||||||
|
amount_t fromMini(amount_mini_t pAmountMini) {
|
||||||
|
return pAmountMini * pow(10,-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
amount_mini_t toMini(amount_t pAmount) {
|
||||||
|
return pAmount * pow(10,12);
|
||||||
|
}
|
||||||
|
|
||||||
|
Wallet::Wallet(const std::string& pWalletFile, const std::string& pWalletPassword)
|
||||||
|
: wallet_impl(new tools::wallet2())
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
wallet_impl->load(pWalletFile, pWalletPassword);
|
||||||
|
}
|
||||||
|
catch(tools::error::invalid_password) {
|
||||||
|
throw(Errors::iInvalidPassword);
|
||||||
|
}
|
||||||
|
catch(tools::error::file_error_base<1>) {
|
||||||
|
throw(Errors::iInvalidFile);
|
||||||
|
}
|
||||||
|
// catch(tools::error::file_read_error) {
|
||||||
|
// throw(Errors::iInvalidFile);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Wallet::Wallet(tools::wallet2* pWalletImpl)
|
||||||
|
: wallet_impl(pWalletImpl)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Wallet::~Wallet() {
|
||||||
|
wallet_impl->store();
|
||||||
|
delete wallet_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Wallet::getAddress() const {
|
||||||
|
|
||||||
|
return wallet_impl->get_account().get_public_address_str();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
amount_mini_t Wallet::getBalanceMini() const {
|
||||||
|
return wallet_impl->balance();
|
||||||
|
}
|
||||||
|
|
||||||
|
amount_mini_t Wallet::getUnlockedBalanceMini() const {
|
||||||
|
return wallet_impl->unlocked_balance();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
amount_t Wallet::getBalance() const {
|
||||||
|
return fromMini(getBalanceMini());
|
||||||
|
}
|
||||||
|
|
||||||
|
amount_t Wallet::getUnlockedBalance() const {
|
||||||
|
return fromMini(getUnlockedBalanceMini());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Wallet::walletExists(const std::string pWalletFile, bool& oWallet_data_exists, bool& oWallet_keys_exist) {
|
||||||
|
|
||||||
|
bool lDataExists = false;
|
||||||
|
bool lKeysExists = false;
|
||||||
|
tools::wallet2::wallet_exists(pWalletFile, lDataExists, lKeysExists);
|
||||||
|
|
||||||
|
return lKeysExists;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Wallet Wallet::generateWallet(const std::string pWalletFile, const std::string& pWalletPassword) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
tools::wallet2* lWalletImpl = new tools::wallet2();
|
||||||
|
lWalletImpl->generate(pWalletFile, pWalletPassword);
|
||||||
|
return Wallet(lWalletImpl);
|
||||||
|
}
|
||||||
|
catch(tools::error::file_save_error) {
|
||||||
|
throw(Errors::iNotWritableFile);
|
||||||
|
}
|
||||||
|
catch(tools::error::file_exists) {
|
||||||
|
throw(Errors::iNotWritableFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/monero_wallet_wrapper/MoneroWallet.hh
Normal file
74
src/monero_wallet_wrapper/MoneroWallet.hh
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
// #include <inttypes.h>
|
||||||
|
|
||||||
|
namespace tools { class wallet2; }
|
||||||
|
|
||||||
|
namespace Monero {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef unsigned long long amount_mini_t;
|
||||||
|
typedef long double amount_t;
|
||||||
|
|
||||||
|
namespace Errors {
|
||||||
|
|
||||||
|
class InvalidPassword: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual const char* what() const throw()
|
||||||
|
{
|
||||||
|
return "Wrong wallet password";
|
||||||
|
}
|
||||||
|
} iInvalidPassword;
|
||||||
|
|
||||||
|
class InvalidFile: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual const char* what() const throw()
|
||||||
|
{
|
||||||
|
return "Wallet file not found or invalid";
|
||||||
|
}
|
||||||
|
} iInvalidFile;
|
||||||
|
|
||||||
|
class NotWritableFile: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual const char* what() const throw()
|
||||||
|
{
|
||||||
|
return "Unable to write file";
|
||||||
|
}
|
||||||
|
|
||||||
|
} iNotWritableFile;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Wallet {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Wallet(const std::string& pWalletFile, const std::string& pWalletPassword);
|
||||||
|
~Wallet();
|
||||||
|
|
||||||
|
/* Offline methods */
|
||||||
|
const std::string getAddress() const;
|
||||||
|
|
||||||
|
amount_mini_t getBalanceMini() const;
|
||||||
|
amount_mini_t getUnlockedBalanceMini() const;
|
||||||
|
|
||||||
|
amount_t getBalance() const;
|
||||||
|
amount_t getUnlockedBalance() const;
|
||||||
|
/**/
|
||||||
|
|
||||||
|
static bool walletExists(const std::string pWalletFile, bool& oWallet_data_exists, bool& oWallet_keys_exist);
|
||||||
|
static Wallet generateWallet(const std::string pWalletFile, const std::string& pWalletPassword);
|
||||||
|
|
||||||
|
private:
|
||||||
|
tools::wallet2* wallet_impl;
|
||||||
|
|
||||||
|
Wallet(tools::wallet2* pWalletImpl);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,6 @@
|
|||||||
#include <boost/serialization/vector.hpp>
|
#include <boost/serialization/vector.hpp>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
#include "include_base_utils.h"
|
|
||||||
#include "cryptonote_core/account.h"
|
#include "cryptonote_core/account.h"
|
||||||
#include "cryptonote_core/account_boost_serialization.h"
|
#include "cryptonote_core/account_boost_serialization.h"
|
||||||
#include "cryptonote_core/cryptonote_basic_impl.h"
|
#include "cryptonote_core/cryptonote_basic_impl.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user