Skip to content

Commit

Permalink
Merge pull request exantech#2 from safex/win_wallet
Browse files Browse the repository at this point in the history
Windows libwallet implementation
  • Loading branch information
atanmarko authored Dec 5, 2018
2 parents c7184fb + 511e29d commit 8ed1520
Show file tree
Hide file tree
Showing 24 changed files with 2,322 additions and 1,725 deletions.
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PWD=${shell pwd}
BOOST_LIBS=chrono,date_time,filesystem,program_options,regex,serialization,system,thread,locale
THREADS?=6


.PHONY: all
all: binding.gyp deps
node_modules/.bin/node-pre-gyp configure build
Expand Down Expand Up @@ -42,10 +43,24 @@ safexcore:
git clone --depth 1 --recurse-submodules -b ${SAFEX_BRANCH} https://github.com/safex/safexcore
cp safexcore/src/wallet/api/wallet_api.h include

ifeq ($(OS),Windows_NT)
#windows
safexcore/build: boost safexcore
mkdir -p safexcore/build
mkdir -p deps
cp safexcore/src/wallet/api/win_wrapper/windows_wrapper.h include
cd safexcore/build && cmake -G "MSYS Makefiles" -DBUILD_TAG="win-x64" -DCMAKE_TOOLCHAIN_FILE=../cmake/64-bit-toolchain.cmake -DMSYS2_FOLDER=c:/msys64 -DARCH="x86-64" \
-DBUILD_64=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_GUI_DEPS=ON -DBUILD_TESTS=OFF -DSTATIC=ON -DBOOST_ROOT=${PWD}/boost -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true \
-DBUILD_WIN_WALLET_WRAPPER=ON -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PWD}/deps ..
cd safexcore/build && make -j${THREADS}
cp safexcore/build/src/wallet/api/win_wrapper/libwin_wallet_wrapper.* ${PWD}/deps
cd deps && '/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/lib.exe' /machine:x64 /def:libwin_wallet_wrapper.def
else
#linux, mac
safexcore/build: boost safexcore
mkdir -p safexcore/build
mkdir -p deps
cd safexcore/build && cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_GUI_DEPS=ON -DEMBEDDED_WALLET=1 \
cd safexcore/build && cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_GUI_DEPS=ON \
-DBUILD_TESTS=OFF -DSTATIC=ON -DBOOST_ROOT=${PWD}/boost \
-DCMAKE_BUILD_TYPE=${SAFEX_BUILD_TYPE} \
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true \
Expand All @@ -54,3 +69,6 @@ safexcore/build: boost safexcore

cd safexcore/build && make -j${THREADS} wallet_merged epee easylogging lmdb unbound VERBOSE=1
cp safexcore/build/lib/libwallet_merged.a ${PWD}/deps

endif

214 changes: 152 additions & 62 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,57 +1,139 @@
{
"conditions": [
['OS=="linux"', {
"variables": {
'additional_libraries': [
"-lpcsclite",
]
}
}],
['OS=="mac"', {
"variables": {
'additional_libraries': [
"-framework PCSC",
]
}
}]
],
"targets": [
{
"target_name": "build_safex",
"type": "none",
"actions": [
[
'OS=="win"',
{

"targets":[
{
"action_name": "retrieve_from_github",
"inputs": "",
"outputs": [
"../deps/libwallet_merged.a",
"../deps/libepee.a",
"../deps/libeasylogging.a",
"../deps/liblmdb.a",
"../deps/libunbound.a",
"target_name": "build_safex",
"type": "none",
"actions": [
{
"action_name": "retrieve_from_github",
"inputs": "",
"outputs": [
"../deps/libwin_wallet_wrapper.dll",
],
"action": [
"make deps","--directory=.."],
"message": "Building windows safex libraries"
}
]
},
{
"target_name": "safex",
"dependencies": [
"build_safex"
],
"action": ["make","deps"],
"message": "Building safex libraries",
"sources": [
"src/addon.cc",
"src/wallet.cc",
"src/walletcallbacks.cc",
"src/walletargs.cc",
"src/deferredtask.cc",
"src/wallettasks.cc",
"src/pendingtransaction.cc",
"src/win/winwallet.cpp",
"src/win/winwalletlistener.cpp",
"src/win/winwalletmanager.cpp",
"src/win/winpendingtransaction.cpp",
"src/win/misc.cpp"
],
"libraries": [
'-l../deps/libwin_wallet_wrapper.lib'
],
"include_dirs": [
"include",
"src",
"src/win",
"<!(node -e \"require('nan')\")"
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [
"<(module_name)"
],
"copies": [
{
"files": [
"<(PRODUCT_DIR)/<(module_name).node",
"./deps/libwin_wallet_wrapper.dll"
],
"destination": "<(module_path)"
}
]
}
]
},
{ #nonwin
"conditions":[
[
'OS=="linux"',
{
"variables": {
'additional_libraries': [
"-lpcsclite"
]
}
}
],
[
'OS=="mac"',
{
"variables": {
'additional_libraries': [
"-framework PCSC"
]
}
}
]
],
},
{
"target_name": "safex",
"dependencies": ["build_safex"],
"sources": [
"src/addon.cc",
"src/wallet.cc",
"src/walletcallbacks.cc",
"src/walletargs.cc",
"src/deferredtask.cc",
"src/wallettasks.cc",
"src/pendingtransaction.cc"],
"libraries": [
"../deps/libwallet_merged.a",
"../deps/libepee.a",
"../deps/libeasylogging.a",
"../deps/liblmdb.a",
"../deps/libunbound.a",
"targets":[
{
"target_name": "build_safex",
"type": "none",
"actions": [
{
"action_name": "retrieve_from_github",
"inputs": "",
"outputs": [
"../deps/libwallet_merged.a",
"../deps/libepee.a",
"../deps/libeasylogging.a",
"../deps/liblmdb.a",
"../deps/libunbound.a"
],
"action": [
"make",
"deps"
],
"message": "Building safex libraries"
}
]
},
{
"target_name": "safex",
"dependencies": [
"build_safex"
],
"sources": [
"src/addon.cc",
"src/wallet.cc",
"src/walletcallbacks.cc",
"src/walletargs.cc",
"src/deferredtask.cc",
"src/wallettasks.cc",
"src/pendingtransaction.cc"
],
"libraries": [
"../deps/libwallet_merged.a",
"../deps/libepee.a",
"../deps/libeasylogging.a",
"../deps/liblmdb.a",
"../deps/libunbound.a",
"../deps/libboost_serialization.a",
"../deps/libboost_thread.a",
"../deps/libboost_system.a",
Expand All @@ -61,25 +143,33 @@
"../deps/libboost_program_options.a",
"../deps/libboost_regex.a",
"<@(additional_libraries)",
"-lssl",
"-lssl",
"-lcrypto",
"-lz",
""],
"include_dirs": [
"include",
""
],
"include_dirs": [
"include",
"<!(node -e \"require('nan')\")"
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
]
},
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
"target_name": "action_after_build",
"type": "none",
"dependencies": [
"<(module_name)"
],
"copies": [
{
"files": [
"<(PRODUCT_DIR)/<(module_name).node"
],
"destination": "<(module_path)"
}
]
}
]
}
}
]
]
}
86 changes: 51 additions & 35 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ safex.setupLog(3, "index.log");
var wallet;
var sent = false;
const wallet_path = path.join(__dirname, 'test-wallet');

var args = {
'path': wallet_path,
'password': '123',
'network': 'testnet',
'daemonAddress': 'localhost:29393',
'restoreHeight': 0,
'mnemonic' : 'nifty inflamed against focus gasp ethics spying gulp tiger cogs evicted cohesive woken nylon erosion tell saved fatal alkaline acquire lemon maps hull imitate saved'
}

// const wallet_path = "C:/Users/marko/balkaneum/temp/test-wallet";
// const wallet_path = "test-wallet";

// var args = {
// 'path': wallet_path,
// 'password': '123',
// 'network': 'testnet',
// 'daemonAddress': 'localhost:29393',
// 'restoreHeight': 0,
// 'addressString': 'SFXtzRzqWR2J3ytgxg1AxBfM8ZFgZmywoXHtqeqwsk3Gi63B2c3mvLNct35m268Pg2eGqHLmJubC7GPdvb1KxhTvHeVd4WKD9RQ',
// 'viewKeyString': '',
// 'spendKeyString': ''
// 'path': wallet_path,
// 'password': '123',
// 'network': 'testnet',
// 'daemonAddress': '192.168.1.194:29393',
// 'restoreHeight': 0,
// 'mnemonic' : 'nifty inflamed against focus gasp ethics spying gulp tiger cogs evicted cohesive woken nylon erosion tell saved fatal alkaline acquire lemon maps hull imitate saved'
// }


var args = {
'path': wallet_path,
'password': '123',
'network': 'testnet',
'daemonAddress': '192.168.1.194:29393',
'restoreHeight': 0,
'addressString': 'SFXtzU6Azx3N61CBXBK2KZBGUw2U3XQXKEZkSvBrfeczNvn6yXeWk4wXkNajNNe7xv1eeuH4rrrFiJMC5Ed1uN3GXt5vuDJkV3B',
'viewKeyString': 'c135405a2f0e0b6302e0c2d0a5f056fbf7f37eaad7bf67769d6fa35d2a55e200',
'spendKeyString': '5270759c9602bef14a0f937f25cc84e4b599b5ab3e22ab874ceff7799ec69a03'
}

if (!safex.walletExists(wallet_path)) {
console.log("wallet doesn't exist. creating new one: " + wallet_path);
if(args.mnemonic)
Expand Down Expand Up @@ -84,26 +86,40 @@ promise

if (!sent) {
sent = true;
// //cash
// wallet.createTransaction({
// 'address': 'SFXtzT37s8jWtjUx8kfWD24PU2mMLqYkt7DQ3KzJKC7B3pp67XFpFJhiEvwTe1DX9gT7nWcYZQRt7UWnEoWDcjmLdegfWoLVZwY',
// 'amount': '21300000000', //send 2.13 cash
// })
wallet.createTransaction({
'address': 'SFXtzT37s8jWtjUx8kfWD24PU2mMLqYkt7DQ3KzJKC7B3pp67XFpFJhiEvwTe1DX9gT7nWcYZQRt7UWnEoWDcjmLdegfWoLVZwY',
'amount': '30000000000', //send 3 tokens
'tx_type': 1 //token transaction
}).then((tx) => {
console.log("token transaction created: " + tx.transactionsIds());

tx.commit().then(() => {
console.log("transaction commited successfully");
}).catch((e) => {
console.log("error on commiting transaction: " + e);
});
}).catch((e) => {
sent = false;
console.log("couldn't create transaction: " + e);
});
// }).then((tx) => {
// console.log("cash transaction created: " + tx.transactionsIds());
//
// tx.commit().then(() => {
// console.log("cash transaction commited successfully");
// }).catch((e) => {
// console.log("error on commiting transaction: " + e);
// });
// }).catch((e) => {
// sent = false;
// console.log("couldn't create transaction: " + e);
// });
//
//token
// wallet.createTransaction({
// 'address': 'SFXtzT37s8jWtjUx8kfWD24PU2mMLqYkt7DQ3KzJKC7B3pp67XFpFJhiEvwTe1DX9gT7nWcYZQRt7UWnEoWDcjmLdegfWoLVZwY',
// 'amount': '30000000000', //send 3 tokens
// 'tx_type': 1 //token transaction
// }).then((tx) => {
// console.log("token transaction created: " + tx.transactionsIds());
//
// tx.commit().then(() => {
// console.log("transaction commited successfully");
// }).catch((e) => {
// console.log("error on commiting transaction: " + e);
// });
// }).catch((e) => {
// sent = false;
// console.log("couldn't create transaction: " + e);
// });
}
});

Expand Down
Loading

0 comments on commit 8ed1520

Please sign in to comment.