diff --git a/Makefile.am b/Makefile.am index 442a59ebc..bb8195029 100644 --- a/Makefile.am +++ b/Makefile.am @@ -78,6 +78,7 @@ src_libbitcoin_explorer_la_SOURCES = \ src/commands/electrum-new.cpp \ src/commands/electrum-to-seed.cpp \ src/commands/fetch-balance.cpp \ + src/commands/fetch-block.cpp \ src/commands/fetch-header.cpp \ src/commands/fetch-height.cpp \ src/commands/fetch-history.cpp \ @@ -218,6 +219,7 @@ test_libbitcoin_explorer_test_SOURCES = \ test/commands/electrum-new.cpp \ test/commands/electrum-to-seed.cpp \ test/commands/fetch-balance.cpp \ + test/commands/fetch-block.cpp \ test/commands/fetch-header.cpp \ test/commands/fetch-height.cpp \ test/commands/fetch-history.cpp \ @@ -339,6 +341,7 @@ include_bitcoin_explorer_commands_HEADERS = \ include/bitcoin/explorer/commands/electrum-new.hpp \ include/bitcoin/explorer/commands/electrum-to-seed.hpp \ include/bitcoin/explorer/commands/fetch-balance.hpp \ + include/bitcoin/explorer/commands/fetch-block.hpp \ include/bitcoin/explorer/commands/fetch-header.hpp \ include/bitcoin/explorer/commands/fetch-height.hpp \ include/bitcoin/explorer/commands/fetch-history.hpp \ diff --git a/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj b/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj index 148b9d57f..3622d1f01 100644 --- a/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj +++ b/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj @@ -106,6 +106,7 @@ + diff --git a/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters b/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters index eac87e93c..1f1a30906 100644 --- a/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters +++ b/builds/msvc/vs2013/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters @@ -126,6 +126,9 @@ src\commands + + src\commands + src\commands diff --git a/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj b/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj index 94c340f6a..d994e58ba 100644 --- a/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj +++ b/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj @@ -110,6 +110,7 @@ + @@ -232,6 +233,7 @@ + diff --git a/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters b/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters index bc55196c6..7934ebf49 100644 --- a/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters +++ b/builds/msvc/vs2013/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters @@ -150,6 +150,9 @@ src\commands + + src\commands + src\commands @@ -512,6 +515,9 @@ include\bitcoin\explorer\commands + + include\bitcoin\explorer\commands + include\bitcoin\explorer\commands diff --git a/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj b/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj index 2751c4a72..b0653c69c 100644 --- a/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj +++ b/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj @@ -106,6 +106,7 @@ + diff --git a/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters b/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters index eac87e93c..1f1a30906 100644 --- a/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters +++ b/builds/msvc/vs2015/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters @@ -126,6 +126,9 @@ src\commands + + src\commands + src\commands diff --git a/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj b/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj index e3cce7dd9..b6977a934 100644 --- a/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj +++ b/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj @@ -110,6 +110,7 @@ + @@ -232,6 +233,7 @@ + diff --git a/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters b/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters index a7d7d9a7b..759e630d3 100644 --- a/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters +++ b/builds/msvc/vs2015/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters @@ -150,6 +150,9 @@ src\commands + + src\commands + src\commands @@ -512,6 +515,9 @@ include\bitcoin\explorer\commands + + include\bitcoin\explorer\commands + include\bitcoin\explorer\commands diff --git a/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj b/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj index 1646ef704..9b30bac9f 100644 --- a/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj +++ b/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj @@ -106,6 +106,7 @@ + diff --git a/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters b/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters index eac87e93c..1f1a30906 100644 --- a/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters +++ b/builds/msvc/vs2017/libbitcoin-explorer-test/libbitcoin-explorer-test.vcxproj.filters @@ -126,6 +126,9 @@ src\commands + + src\commands + src\commands diff --git a/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj b/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj index c7f50150b..372586cd4 100644 --- a/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj +++ b/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj @@ -110,6 +110,7 @@ + @@ -232,6 +233,7 @@ + diff --git a/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters b/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters index 8afed9a07..73de6148b 100644 --- a/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters +++ b/builds/msvc/vs2017/libbitcoin-explorer/libbitcoin-explorer.vcxproj.filters @@ -150,6 +150,9 @@ src\commands + + src\commands + src\commands @@ -512,6 +515,9 @@ include\bitcoin\explorer\commands + + include\bitcoin\explorer\commands + include\bitcoin\explorer\commands diff --git a/data/bx b/data/bx index 9f084e023..d224cbf47 100644 --- a/data/bx +++ b/data/bx @@ -43,6 +43,7 @@ _bx() electrum-new electrum-to-seed fetch-balance + fetch-block fetch-header fetch-height fetch-history diff --git a/include/bitcoin/explorer.hpp b/include/bitcoin/explorer.hpp index 360499fe3..fe349c252 100644 --- a/include/bitcoin/explorer.hpp +++ b/include/bitcoin/explorer.hpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include diff --git a/include/bitcoin/explorer/commands/fetch-block.hpp b/include/bitcoin/explorer/commands/fetch-block.hpp new file mode 100644 index 000000000..b4efd6aa3 --- /dev/null +++ b/include/bitcoin/explorer/commands/fetch-block.hpp @@ -0,0 +1,263 @@ +/** + * Copyright (c) 2011-2017 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef BX_FETCH_BLOCK_HPP +#define BX_FETCH_BLOCK_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/********* GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY **********/ + +namespace libbitcoin { +namespace explorer { +namespace commands { + +/** + * Class to implement the fetch-block command. + */ +class BCX_API fetch_block + : public command +{ +public: + + /** + * The symbolic (not localizable) command name, lower case. + */ + static const char* symbol() + { + return "fetch-block"; + } + + + /** + * The member symbolic (not localizable) command name, lower case. + */ + virtual const char* name() + { + return fetch_block::symbol(); + } + + /** + * The localizable command category name, upper case. + */ + virtual const char* category() + { + return "ONLINE"; + } + + /** + * The localizable command description. + */ + virtual const char* description() + { + return "Get the block from the specified hash or height. Height is ignored if both are specified. Requires a Libbitcoin server connection."; + } + + /** + * Load program argument definitions. + * A value of -1 indicates that the number of instances is unlimited. + * @return The loaded program argument definitions. + */ + virtual arguments_metadata& load_arguments() + { + return get_argument_metadata(); + } + + /** + * Load parameter fallbacks from file or input as appropriate. + * @param[in] input The input stream for loading the parameters. + * @param[in] The loaded variables. + */ + virtual void load_fallbacks(std::istream& input, + po::variables_map& variables) + { + } + + /** + * Load program option definitions. + * BUGBUG: see boost bug/fix: svn.boost.org/trac/boost/ticket/8009 + * @return The loaded program option definitions. + */ + virtual options_metadata& load_options() + { + using namespace po; + options_description& options = get_option_metadata(); + options.add_options() + ( + BX_HELP_VARIABLE ",h", + value()->zero_tokens(), + "Get a description and instructions for this command." + ) + ( + BX_CONFIG_VARIABLE ",c", + value(), + "The path to the configuration settings file." + ) + ( + "format,f", + value(&option_.format), + "The output format. Options are 'info', 'json' and 'xml', defaults to 'info'." + ) + ( + "hash,s", + value(&option_.hash), + "The Base16 block hash." + ) + ( + "height,t", + value(&option_.height), + "The block height." + ); + + return options; + } + + /** + * Set variable defaults from configuration variable values. + * @param[in] variables The loaded variables. + */ + virtual void set_defaults_from_config(po::variables_map& variables) + { + } + + /** + * Invoke the command. + * @param[out] output The input stream for the command execution. + * @param[out] error The input stream for the command execution. + * @return The appropriate console return code { -1, 0, 1 }. + */ + virtual console_result invoke(std::ostream& output, + std::ostream& cerr); + + /* Properties */ + + /** + * Get the value of the format option. + */ + virtual explorer::config::encoding& get_format_option() + { + return option_.format; + } + + /** + * Set the value of the format option. + */ + virtual void set_format_option( + const explorer::config::encoding& value) + { + option_.format = value; + } + + /** + * Get the value of the hash option. + */ + virtual bc::config::hash256& get_hash_option() + { + return option_.hash; + } + + /** + * Set the value of the hash option. + */ + virtual void set_hash_option( + const bc::config::hash256& value) + { + option_.hash = value; + } + + /** + * Get the value of the height option. + */ + virtual uint32_t& get_height_option() + { + return option_.height; + } + + /** + * Set the value of the height option. + */ + virtual void set_height_option( + const uint32_t& value) + { + option_.height = value; + } + +private: + + /** + * Command line argument bound variables. + * Uses cross-compiler safe constructor-based zeroize. + * Zeroize for unit test consistency with program_options initialization. + */ + struct argument + { + argument() + { + } + + } argument_; + + /** + * Command line option bound variables. + * Uses cross-compiler safe constructor-based zeroize. + * Zeroize for unit test consistency with program_options initialization. + */ + struct option + { + option() + : format(), + hash(), + height() + { + } + + explorer::config::encoding format; + bc::config::hash256 hash; + uint32_t height; + } option_; +}; + +} // namespace commands +} // namespace explorer +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/explorer/generated.hpp b/include/bitcoin/explorer/generated.hpp index deb3be05c..06587aaf6 100644 --- a/include/bitcoin/explorer/generated.hpp +++ b/include/bitcoin/explorer/generated.hpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include diff --git a/model/generate.xml b/model/generate.xml index 6b40ab1f3..b4aecc47f 100644 --- a/model/generate.xml +++ b/model/generate.xml @@ -283,6 +283,12 @@ + + +