Skip to content

Commit

Permalink
Merge pull request #611 from thecodefactory/property_tree
Browse files Browse the repository at this point in the history
Move additional property_tree code out from explorer.
  • Loading branch information
thecodefactory authored Dec 28, 2018
2 parents fd8b1a6 + 41fa545 commit be786b4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 174 deletions.
63 changes: 0 additions & 63 deletions include/bitcoin/explorer/prop_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <boost/property_tree/ptree.hpp>
#include <bitcoin/system.hpp>
#include <bitcoin/explorer/define.hpp>
#include <bitcoin/explorer/config/wrapper.hpp>

namespace libbitcoin {
namespace explorer {
Expand All @@ -36,7 +35,6 @@ class header;
class input;
class output;
class transaction;
class wrapper;

/**
* A tuple to represent settings and serialized values.
Expand Down Expand Up @@ -254,38 +252,6 @@ BCX_API pt::ptree prop_tree(const transaction& transaction, bool json);
BCX_API pt::ptree prop_tree(const std::vector<transaction>& transactions,
bool json);

/**
* Generate a property list for a wrapper.
* @param[in] wrapper The wrapper instance.
* @return A property list.
*/
BCX_API pt::ptree prop_list(const system::wallet::wrapped_data& wrapper);

/**
* Generate a property tree for a wrapper.
* @param[in] wrapper The wrapper instance.
* @return A property tree.
*/
BCX_API pt::ptree prop_tree(const system::wallet::wrapped_data& wrapper);

/**
* Generate a property list for a stealth address.
* @param[in] stealth_address The stealth address.
* @param[in] json Use json array formatting.
* @return A property list.
*/
BCX_API pt::ptree prop_list(const system::wallet::stealth_address& stealth,
bool json);

/**
* Generate a property tree for a stealth address.
* @param[in] stealth_address The stealth address.
* @param[in] json Use json array formatting.
* @return A property tree.
*/
BCX_API pt::ptree prop_tree(const system::wallet::stealth_address& stealth,
bool json);

/**
* Generate a property list for a stealth metadata row.
* @param[in] rows The stealth row.
Expand All @@ -308,42 +274,13 @@ BCX_API pt::ptree prop_tree(const client::stealth& row);
*/
BCX_API pt::ptree prop_tree(const client::stealth::list& rows, bool json);

/**
* Create a property tree for single hash.
* @param[in] hash The block hash.
* @returns A new property tree containing the hash.
*/
BCX_API pt::ptree prop_list(const system::hash_digest& hash);

/**
* Create a property tree for a single hash.
* @param[in] hash The block hash.
* @returns A new property tree containing the hash.
*/
BCX_API pt::ptree prop_tree(const system::hash_digest& hash);

/**
* Create a property tree for a hash_list.
* @param[in] hashes The list of block hashes.
* @param[in] json Use json array formatting.
* @returns A new property tree containing the list.
*/
BCX_API pt::ptree prop_tree(const system::hash_list& hashes, bool json);

/**
* Create a property tree for the settings command.
* @param[in] settings The list of settings.
* @returns A new property tree containing the settings.
*/
BCX_API pt::ptree prop_tree(const settings_list& settings);

/**
* Create a property tree for a parsed bitcoin uri.
* @param[in] uri The parsed uri.
* @returns A new property tree containing the settings.
*/
BCX_API pt::ptree prop_tree(const system::wallet::bitcoin_uri& uri);

} // namespace config
} // namespace explorer
} // namespace libbitcoin
Expand Down
5 changes: 2 additions & 3 deletions src/commands/address-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <bitcoin/system.hpp>
#include <bitcoin/explorer/define.hpp>
#include <bitcoin/explorer/prop_tree.hpp>
#include <bitcoin/explorer/config/wrapper.hpp>

namespace libbitcoin {
namespace explorer {
Expand All @@ -38,8 +37,8 @@ console_result address_decode::invoke(std::ostream& output,
const auto& address = get_payment_address_argument();
const auto& encoding = get_format_option();

const wrapper wrapped(address);
write_stream(output, prop_tree(wrapped), encoding);
const config::wrapper wrapped(address);
write_stream(output, property_tree(wrapped), encoding);

return console_result::okay;
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/base58check-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <bitcoin/system.hpp>
#include <bitcoin/explorer/define.hpp>
#include <bitcoin/explorer/prop_tree.hpp>
#include <bitcoin/explorer/config/wrapper.hpp>

namespace libbitcoin {
namespace explorer {
Expand All @@ -38,8 +37,8 @@ console_result base58check_decode::invoke(std::ostream& output,
const auto& base58check = get_base58check_argument();
const auto& encoding = get_format_option();

const wrapper wrapped(base58check);
const auto tree = prop_tree(wrapped);
const config::wrapper wrapped(base58check);
const auto tree = property_tree(wrapped);

write_stream(output, tree, encoding);
return console_result::okay;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/fetch-block-hashes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <bitcoin/explorer/define.hpp>
#include <bitcoin/explorer/display.hpp>
#include <bitcoin/explorer/utility.hpp>
#include <bitcoin/explorer/prop_tree.hpp>

namespace libbitcoin {
namespace explorer {
Expand Down Expand Up @@ -61,7 +60,7 @@ system::console_result fetch_block_hashes::invoke(std::ostream& output,
if (!state.succeeded(ec))
return;

state.output(prop_tree(hashes, json));
state.output(property_tree(hashes, json));
};

// Height is ignored if both are specified.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/stealth-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ console_result stealth_decode::invoke(std::ostream& output,
// This enables json-style array formatting.
const auto json = encoding == encoding_engine::json;

write_stream(output, prop_tree(address, json), encoding);
write_stream(output, property_tree(address, json), encoding);
return console_result::okay;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/uri-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace bc::system;
const auto& encoding = get_format_option();
const auto& uri = get_uri_argument();

write_stream(output, prop_tree(uri), encoding);
write_stream(output, property_tree(uri), encoding);
return console_result::okay;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/wrap-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ console_result wrap_decode::invoke(std::ostream& output, std::ostream& error)
const auto& wrapped = get_wrapped_argument();
const auto& encoding = get_format_option();

const auto tree = prop_tree(wrapped);
const auto tree = property_tree(wrapped);

write_stream(output, tree, encoding);
return console_result::okay;
Expand Down
100 changes: 0 additions & 100 deletions src/prop_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,55 +126,6 @@ ptree prop_tree(const client::history::list& rows,
return tree;
}

// wrapper

ptree prop_list(const wallet::wrapped_data& wrapper)
{
ptree tree;
tree.put("checksum", wrapper.checksum);
tree.put("payload", base16(wrapper.payload));
tree.put("version", wrapper.version);
return tree;
}

ptree prop_tree(const wallet::wrapped_data& wrapper)
{
ptree tree;
tree.add_child("wrapper", prop_list(wrapper));
return tree;
}

// stealth_address

ptree prop_list(const stealth_address& stealth, bool json)
{
// We don't serialize a "reuse key" value as this is strictly an
// optimization for the purpose of serialization and otherwise complicates
// understanding of what is actually otherwise very simple behavior.
// So instead we emit the reused key as one of the spend keys.
// This means that it is typical to see the same key in scan and spend.

const auto spends = cast<ec_compressed, ec_public>(
stealth.spend_keys());
const auto spends_values = prop_value_list("public_key", spends, json);

ptree tree;
tree.put("encoded", stealth);
tree.put("filter", stealth.filter());
tree.put("scan_public_key", ec_public(stealth.scan_key()));
tree.put("signatures", stealth.signatures());
tree.add_child("spends", spends_values);
tree.put("version", stealth.version());
return tree;
}

ptree prop_tree(const stealth_address& stealth, bool json)
{
ptree tree;
tree.add_child("stealth_address", prop_list(stealth, json));
return tree;
}

// stealth

ptree prop_list(const client::stealth& row)
Expand All @@ -200,57 +151,6 @@ ptree prop_tree(const client::stealth::list& rows, bool json)
return tree;
}

// hash_list (base16 encoded values)

ptree prop_list(const hash_digest& hash)
{
ptree tree;
tree.put_value(encode_base16(hash));
return tree;
}

ptree prop_tree(const hash_digest& hash)
{
ptree tree;
tree.add_child("hash", prop_list(hash));
return tree;
}

ptree prop_tree(const hash_list& hashes, bool json)
{
ptree tree;
tree.add_child("hashes", prop_tree_list("hash", hashes, json));
return tree;
}

// uri

ptree prop_tree(const bitcoin_uri& uri)
{
ptree uri_props;

if (!uri.address().empty())
uri_props.put("address", uri.address());

if (uri.amount() != 0)
uri_props.put("amount", uri.amount());

if (!uri.label().empty())
uri_props.put("label", uri.label());

if (!uri.message().empty())
uri_props.put("message", uri.message());

if (!uri.r().empty())
uri_props.put("r", uri.r());

uri_props.put("scheme", "bitcoin");

ptree tree;
tree.add_child("uri", uri_props);
return tree;
}

} // namespace config
} // namespace explorer
} // namespace libbitcoin

0 comments on commit be786b4

Please sign in to comment.