Skip to content

Commit 0c15767

Browse files
authored
Merge pull request #24 from danjurious/bitpay-12.1
wallet-utility: extract addresses and private keys
2 parents e0d02ff + 3658026 commit 0c15767

File tree

8 files changed

+430
-3
lines changed

8 files changed

+430
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ share/BitcoindComparisonTool.jar
114114
/doc/doxygen/
115115

116116
libbitcoinconsensus.pc
117+
wallet-utility

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ EXTRA_DIST += \
1717
test/data/txcreate2.hex \
1818
test/data/txcreatedata1.hex \
1919
test/data/txcreatedata2.hex \
20-
test/data/txcreatesign.hex
20+
test/data/txcreatesign.hex \
21+
test/wallet-utility.py \
22+
test/data/wallet.dat
2123

2224
JSON_TEST_FILES = \
2325
test/data/script_valid.json \
@@ -130,6 +132,10 @@ bitcoin_test_clean : FORCE
130132
check-local:
131133
@echo "Running test/bitcoin-util-test.py..."
132134
$(AM_V_at)srcdir=$(srcdir) PYTHONPATH=$(builddir)/test $(srcdir)/test/bitcoin-util-test.py
135+
if ENABLE_WALLET
136+
@echo "Running test/wallet-utility.py..."
137+
$(AM_V_at)srcdir=$(srcdir) PYTHONPATH=$(builddir)/test $(srcdir)/test/wallet-utility.py
138+
endif
133139
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check
134140
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check
135141

src/test/data/wallet.dat

16 KB
Binary file not shown.

src/test/wallet-utility.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/python
2+
# Copyright 2014 BitPay, Inc.
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
import subprocess
7+
import os
8+
import json
9+
import sys
10+
import buildenv
11+
import shutil
12+
13+
def assert_equal(thing1, thing2):
14+
if thing1 != thing2:
15+
raise AssertionError("%s != %s"%(str(thing1),str(thing2)))
16+
17+
if __name__ == '__main__':
18+
datadir = os.environ["srcdir"] + "/test/data"
19+
execprog = './wallet-utility' + buildenv.exeext
20+
execargs = '-datadir=' + datadir
21+
execrun = execprog + ' ' + execargs
22+
23+
proc = subprocess.Popen(execrun, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
24+
try:
25+
outs = proc.communicate()
26+
except OSError:
27+
print("OSError, Failed to execute " + execprog)
28+
sys.exit(1)
29+
30+
output = json.loads(outs[0])
31+
32+
assert_equal(output[0], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av")
33+
assert_equal(output[1], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8")
34+
assert_equal(output[2], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F")
35+
36+
execargs = '-datadir=' + datadir + ' -dumppass'
37+
execrun = execprog + ' ' + execargs
38+
39+
proc = subprocess.Popen(execrun, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
40+
try:
41+
outs = proc.communicate()
42+
except OSError:
43+
print("OSError, Failed to execute " + execprog)
44+
sys.exit(1)
45+
46+
output = json.loads(outs[0])
47+
48+
assert_equal(output[0]['addr'], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av")
49+
assert_equal(output[0]['pkey'], "5Jz5BWE2WQxp1hGqDZeisQFV1mRFR2AVBAgiXCbNcZyXNjD9aUd")
50+
assert_equal(output[1]['addr'], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8")
51+
assert_equal(output[1]['pkey'], "5HsX2b3v2GjngYQ5ZM4mLp2b2apw6aMNVaPELV1YmpiYR1S4jzc")
52+
assert_equal(output[2]['addr'], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F")
53+
assert_equal(output[2]['pkey'], "5KCWAs1wX2ESiL4PfDR8XYVSSETHFd2jaRGxt1QdanBFTit4XcH")
54+
55+
if os.path.exists(datadir + '/database'):
56+
if os.path.isdir(datadir + '/database'):
57+
shutil.rmtree(datadir + '/database')
58+
59+
if os.path.exists(datadir + '/db.log'):
60+
os.remove(datadir + '/db.log')
61+
sys.exit(0)

0 commit comments

Comments
 (0)