Skip to content

Commit 133c8ab

Browse files
author
Chethan Krishna
committed
wallet-utility: extract addresses and private keys
usage: ./wallet-utility -datadir=<directory> help: ./wallet-utility -h
1 parent e0d02ff commit 133c8ab

File tree

8 files changed

+426
-3
lines changed

8 files changed

+426
-3
lines changed

Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ endif
1212
BITCOIND_BIN=$(top_builddir)/src/bitcoind$(EXEEXT)
1313
BITCOIN_QT_BIN=$(top_builddir)/src/qt/bitcoin-qt$(EXEEXT)
1414
BITCOIN_CLI_BIN=$(top_builddir)/src/bitcoin-cli$(EXEEXT)
15+
WALLET_UTILITY_BIN=$(top_builddir)/src/wallet-utility$(EXEEXT)
1516
BITCOIN_WIN_INSTALLER=$(PACKAGE)-$(PACKAGE_VERSION)-win$(WINDOWS_BITS)-setup$(EXEEXT)
1617

1718
OSX_APP=Bitcoin-Qt.app
@@ -63,6 +64,7 @@ $(BITCOIN_WIN_INSTALLER): all-recursive
6364
STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIND_BIN) $(top_builddir)/release
6465
STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_QT_BIN) $(top_builddir)/release
6566
STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_CLI_BIN) $(top_builddir)/release
67+
STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(WALLET_UTILITY_BIN) $(top_builddir)/release
6668
@test -f $(MAKENSIS) && $(MAKENSIS) -V2 $(top_builddir)/share/setup.nsi || \
6769
echo error: could not build $@
6870
@echo built $@
@@ -145,6 +147,9 @@ $(BITCOIND_BIN): FORCE
145147
$(BITCOIN_CLI_BIN): FORCE
146148
$(MAKE) -C src $(@F)
147149

150+
$(WALLET_UTILITY_BIN): FORCE
151+
$(MAKE) -C src $(@F)
152+
148153
if USE_LCOV
149154

150155
baseline.info:

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
191191

192192
AC_ARG_WITH([utils],
193193
[AS_HELP_STRING([--with-utils],
194-
[build bitcoin-cli bitcoin-tx (default=yes)])],
194+
[build bitcoin-cli bitcoin-tx wallet-utility (default=yes)])],
195195
[build_bitcoin_utils=$withval],
196196
[build_bitcoin_utils=yes])
197197

@@ -766,7 +766,7 @@ AC_MSG_CHECKING([whether to build bitcoind])
766766
AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
767767
AC_MSG_RESULT($build_bitcoind)
768768

769-
AC_MSG_CHECKING([whether to build utils (bitcoin-cli bitcoin-tx)])
769+
AC_MSG_CHECKING([whether to build utils (bitcoin-cli bitcoin-tx wallet-utility)])
770770
AM_CONDITIONAL([BUILD_BITCOIN_UTILS], [test x$build_bitcoin_utils = xyes])
771771
AC_MSG_RESULT($build_bitcoin_utils)
772772

src/Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ endif
7474

7575
if BUILD_BITCOIN_UTILS
7676
bin_PROGRAMS += bitcoin-cli bitcoin-tx
77+
if ENABLE_WALLET
78+
bin_PROGRAMS += wallet-utility
79+
endif
7780
endif
7881

7982
.PHONY: FORCE check-symbols check-security
@@ -367,6 +370,14 @@ bitcoin_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS)
367370
bitcoin_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
368371
bitcoin_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
369372

373+
# wallet-utility binary #
374+
if ENABLE_WALLET
375+
wallet_utility_SOURCES = wallet-utility.cpp
376+
wallet_utility_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAG)
377+
wallet_utility_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
378+
wallet_utility_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
379+
endif
380+
370381
if TARGET_WINDOWS
371382
bitcoin_cli_SOURCES += bitcoin-cli-res.rc
372383
endif
@@ -377,6 +388,10 @@ bitcoin_cli_LDADD = \
377388
$(LIBBITCOIN_UTIL)
378389

379390
bitcoin_cli_LDADD += $(BOOST_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(EVENT_LIBS)
391+
if ENABLE_WALLET
392+
wallet_utility_LDADD = libbitcoin_wallet.a $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBSECP256K1) $(LIBBITCOIN_UTIL) $(BOOST_LIBS) $(BDB_LIBS) $(CRYPTO_LIBS)
393+
endif
394+
380395
#
381396

382397
# bitcoin-tx binary #

src/Makefile.test.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ if ENABLE_WALLET
9292
BITCOIN_TESTS += \
9393
test/accounting_tests.cpp \
9494
wallet/test/wallet_tests.cpp \
95-
test/rpc_wallet_tests.cpp
95+
test/rpc_wallet_tests.cpp \
96+
test/walletutil_tests.cpp
9697
endif
9798

9899
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)

src/test/test_bitcoin.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,41 @@ TestingSetup::~TestingSetup()
9696
boost::filesystem::remove_all(pathTemp);
9797
}
9898

99+
WalletSetup::WalletSetup(const std::string& chainName) : BasicTestingSetup(chainName)
100+
{
101+
ClearDatadirCache();
102+
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
103+
boost::filesystem::create_directories(pathTemp);
104+
mapArgs["-datadir"] = pathTemp.string();
105+
#ifdef ENABLE_WALLET
106+
bool fFirstRun;
107+
pwalletMain = new CWallet("wallet.dat");
108+
pwalletMain->LoadWallet(fFirstRun);
109+
pwalletMain->TopUpKeyPool(5);
110+
RegisterValidationInterface(pwalletMain);
111+
#endif
112+
}
113+
114+
WalletSetup::~WalletSetup()
115+
{
116+
#ifdef ENABLE_WALLET
117+
UnregisterValidationInterface(pwalletMain);
118+
delete pwalletMain;
119+
pwalletMain = NULL;
120+
bitdb.Flush(true);
121+
bitdb.Reset();
122+
#endif
123+
124+
/*
125+
* Attempting to remove Berkeley DB related files in windows
126+
* errors while running wallet tests. Delete only on
127+
* non windows platforms for now (files are created in tmp)
128+
*/
129+
#ifndef WIN32
130+
boost::filesystem::remove_all(pathTemp);
131+
#endif
132+
}
133+
99134
TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
100135
{
101136
// Generate a 100-block chain:

src/test/test_bitcoin.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ struct TestingSetup: public BasicTestingSetup {
3333
~TestingSetup();
3434
};
3535

36+
/** Wallet setup that configures a complete environment.
37+
* Included are data directory, coins database, script check threads
38+
* and wallet with 5 unused keys.
39+
*/
40+
struct WalletSetup: public BasicTestingSetup {
41+
boost::filesystem::path pathTemp;
42+
43+
WalletSetup(const std::string& chainName = CBaseChainParams::MAIN);
44+
~WalletSetup();
45+
};
46+
3647
class CBlock;
3748
struct CMutableTransaction;
3849
class CScript;

src/test/walletutil_tests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "main.h"
2+
#include "test/test_bitcoin.h"
3+
#include <boost/test/unit_test.hpp>
4+
5+
#ifdef ENABLE_WALLET
6+
#include "wallet/db.h"
7+
#include "wallet/wallet.h"
8+
extern CWallet* pwalletMain;
9+
#endif
10+
11+
using namespace std;
12+
13+
BOOST_FIXTURE_TEST_SUITE(walletutil_tests, WalletSetup)
14+
15+
BOOST_AUTO_TEST_CASE(walletutil_test)
16+
{
17+
#ifdef WIN32
18+
string strCmd = "wallet-utility -datadir="+mapArgs["-datadir"];
19+
#else
20+
string strCmd = "./wallet-utility -datadir="+mapArgs["-datadir"];
21+
#endif
22+
int ret = system(strCmd.c_str());
23+
BOOST_CHECK(ret == 0);
24+
25+
strCmd += " -dumppass";
26+
ret = system(strCmd.c_str());
27+
BOOST_CHECK(ret == 0);
28+
}
29+
30+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)