From 92d83c6fb3c64b466ee4c477634e6f4ecd43adf8 Mon Sep 17 00:00:00 2001 From: Aido Date: Sun, 4 Sep 2016 00:16:37 +0000 Subject: [PATCH] ccoin: Move core wallet functionality into it's own separate library --- include/ccoin/Makefile.am | 10 +++++----- include/ccoin/{ => wallet}/wallet.h | 12 +++++++----- lib/Makefile.am | 12 ++++++------ lib/{ => wallet}/wallet.c | 29 ++++++++++++++++------------- src/Makefile.am | 4 ++-- src/main.c | 9 +++++---- src/wallet.c | 3 +-- src/wallet.h | 2 +- test/Makefile.am | 6 +++--- test/wallet.c | 2 +- 10 files changed, 47 insertions(+), 42 deletions(-) rename include/ccoin/{ => wallet}/wallet.h (86%) rename lib/{ => wallet}/wallet.c (91%) diff --git a/include/ccoin/Makefile.am b/include/ccoin/Makefile.am index ef3dbb44..9f10c845 100644 --- a/include/ccoin/Makefile.am +++ b/include/ccoin/Makefile.am @@ -30,8 +30,7 @@ ccoininclude_HEADERS = \ parr.h \ script.h \ serialize.h \ - util.h \ - wallet.h + util.h ccoinnetincludedir=$(includedir)/ccoin/net @@ -42,9 +41,10 @@ ccoinnetinclude_HEADERS = \ net/netbase.h \ net/peerman.h -ccoinaesincludedir = $(includedir)/ccoin/crypto +ccoinwalletincludedir = $(includedir)/ccoin -ccoinaesinclude_HEADERS = \ +ccoinwalletinclude_HEADERS = \ crypto/aes_util.h \ - crypto/ctaes.h + crypto/ctaes.h \ + wallet/wallet.h diff --git a/include/ccoin/wallet.h b/include/ccoin/wallet/wallet.h similarity index 86% rename from include/ccoin/wallet.h rename to include/ccoin/wallet/wallet.h index be87c98c..d4e2b473 100644 --- a/include/ccoin/wallet.h +++ b/include/ccoin/wallet/wallet.h @@ -7,10 +7,12 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php. */ -#include -#include -#include -#include +#include // for cstring +#include // for parr_idx, parr + +#include // for bool +#include // for size_t +#include // for uint32_t #ifdef __cplusplus extern "C" { @@ -71,4 +73,4 @@ extern bool wallet_valid_name(const char *name); } #endif -#endif +#endif /* __LIBCCOIN_WALLET_H__ */ diff --git a/lib/Makefile.am b/lib/Makefile.am index 5169dc21..2a9e2cd2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -47,10 +47,9 @@ libccoin_la_SOURCES= \ script_sign.c \ serialize.c \ util.c \ - utxo.c \ - wallet.c + utxo.c -noinst_LTLIBRARIES= libccoinnet.la libccoinaes.la +noinst_LTLIBRARIES= libccoinnet.la libccoinwallet.la libccoinnet_la_SOURCES= \ net/dns.c \ @@ -58,6 +57,7 @@ libccoinnet_la_SOURCES= \ net/netbase.c \ net/peerman.c -libccoinaes_la_SOURCES= \ - crypto/aes_util.c \ - crypto/ctaes.c +libccoinwallet_la_SOURCES= \ + crypto/aes_util.c \ + crypto/ctaes.c \ + wallet/wallet.c diff --git a/lib/wallet.c b/lib/wallet/wallet.c similarity index 91% rename from lib/wallet.c rename to lib/wallet/wallet.c index 3255393c..3f464875 100644 --- a/lib/wallet.c +++ b/lib/wallet/wallet.c @@ -6,19 +6,22 @@ */ #include "picocoin-config.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#include // for bp_pubkey_get_address +#include // for const_buffer +#include // for chain_info, etc +#include // for hd_extended_key_free, etc +#include // for bp_key_free, bp_key, etc +#include // for mbr_free, mbuf_reader, etc +#include // for p2p_message, etc +#include // for deser_u32, deser_varstr, etc +#include // for ARRAY_SIZE +#include // for wallet, wallet_account, etc + +#include // for assert +#include // for isalnum +#include // for NULL, fprintf, stderr +#include // for free, calloc +#include // for memset, strncmp, strcmp, etc static void account_free(struct wallet_account *acct); diff --git a/src/Makefile.am b/src/Makefile.am index f7d6494a..92dc2c9f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,11 +15,11 @@ brd_LDADD = $(top_builddir)/lib/libccoin.la \ picocoin_SOURCES= \ main.c \ picocoin.h \ - wallet.c wallet.h + wallet.c wallet.h picocoin_LDADD = $(top_builddir)/lib/libccoin.la \ $(top_builddir)/lib/libccoinnet.la \ - $(top_builddir)/lib/libccoinaes.la \ + $(top_builddir)/lib/libccoinwallet.la \ @CRYPTO_LIBS@ @GMP_LIBS@ @ARGP_LIBS@ \ @EVENT_LIBS@ @JANSSON_LIBS@ diff --git a/src/main.c b/src/main.c index 5f266d85..3de10069 100644 --- a/src/main.c +++ b/src/main.c @@ -18,18 +18,19 @@ #include // for ARRAY_SIZE, czstr_equal, etc #include "wallet.h" // for cur_wallet_addresses, etc +#include // for event_free, event_base_new, etc +#include // for json_decref, json_dumpf, etc +#include // for RAND_bytes + #include #include // for assert #include // for bool #include // for isspace #include // for errno -#include // for event_free, event_base_new, etc #include // for open -#include // for RAND_bytes #include // for fprintf, printf, NULL, etc #include // for free, exit #include // for strcmp, strdup, strlen, etc -#include enum command_type { CMD_CHAIN_SET, @@ -664,4 +665,4 @@ int main (int argc, char *argv[]) free(log_state); return 0; -} +} \ No newline at end of file diff --git a/src/wallet.c b/src/wallet.c index bab39837..3019cee0 100644 --- a/src/wallet.c +++ b/src/wallet.c @@ -17,7 +17,7 @@ #include // for encode_hex #include // for bp_privkey_get, etc #include // for parr, parr_idx -#include // for wallet, wallet_free, etc +#include // for wallet, ser_wallet, etc #include // for parr_new #include // for json_object_set_new, etc @@ -444,4 +444,3 @@ void cur_wallet_defaultAccount(const char *acct_name) return; } } - diff --git a/src/wallet.h b/src/wallet.h index c897f0a7..8bab2f79 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -14,4 +14,4 @@ extern void cur_wallet_dump(void); extern void cur_wallet_addresses(void); extern void cur_wallet_free(void); -#endif /* __PICOCOIN_WALLET_H__ */ +#endif /* __PICOCOIN_WALLET_H__ */ \ No newline at end of file diff --git a/test/Makefile.am b/test/Makefile.am index 44cf6efa..ae180e2c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -46,8 +46,8 @@ chain_verf_LDADD = $(COMMON_LDADD) clist_LDADD = $(COMMON_LDADD) cstr_LDADD = $(COMMON_LDADD) coredefs_LDADD = $(COMMON_LDADD) -ctaes_LDADD = $(COMMON_LDADD) $(top_builddir)/lib/libccoinaes.la -aes_util_LDADD = $(COMMON_LDADD) $(top_builddir)/lib/libccoinaes.la +ctaes_LDADD = $(COMMON_LDADD) $(top_builddir)/lib/libccoinwallet.la +aes_util_LDADD = $(COMMON_LDADD) $(top_builddir)/lib/libccoinwallet.la crypto_LDADD = $(COMMON_LDADD) fileio_LDADD = $(COMMON_LDADD) hash_LDADD = $(COMMON_LDADD) @@ -66,5 +66,5 @@ script_parse_LDADD = $(COMMON_LDADD) tx_LDADD = $(COMMON_LDADD) tx_valid_LDADD = $(COMMON_LDADD) util_LDADD = $(COMMON_LDADD) $(top_builddir)/lib/libccoinnet.la -wallet_LDADD = $(COMMON_LDADD) +wallet_LDADD = $(COMMON_LDADD) $(top_builddir)/lib/libccoinwallet.la wallet_basics_LDADD = $(COMMON_LDADD) diff --git a/test/wallet.c b/test/wallet.c index 61a31103..6f83a11c 100644 --- a/test/wallet.c +++ b/test/wallet.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include static bool key_eq(const struct bp_key *key1,