Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/bitcoin/server/interface/blockchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ class BCS_API blockchain
static void fetch_block_height(server_node& node,
const message& request, send_handler handler);

/// Fetch the blockchain history of a stealth address by its prefix filter.
/// Fetch the history of a stealth address by its prefix filter.
static void fetch_stealth(server_node& node,
const message& request, send_handler handler);

/// Fetch the transactions of a stealth address by its prefix filter.
static void fetch_stealth2(server_node& node,
const message& request, send_handler handler);

private:
static void last_height_fetched(const code& ec, size_t last_height,
const message& request, send_handler handler);
Expand Down Expand Up @@ -108,6 +112,10 @@ class BCS_API blockchain
static void stealth_fetched(const code& ec,
const chain::stealth_compact::list& stealth_results,
const message& request, send_handler handler);

static void stealth_fetched2(const code& ec,
const chain::stealth_compact::list& stealth_results,
const message& request, send_handler handler);
};

} // namespace server
Expand Down
51 changes: 51 additions & 0 deletions src/interface/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,56 @@ void blockchain::stealth_fetched(const code& ec,
handler(message(request, result));
}

void blockchain::fetch_stealth2(server_node& node, const message& request,
send_handler handler)
{
const auto& data = request.data();

if (data.empty())
{
handler(message(request, error::bad_stream));
return;
}

auto deserial = make_deserializer(data.begin(), data.end());

// number_bits
const auto bitsize = deserial.read_byte();

if (data.size() != sizeof(uint8_t) + binary::blocks_size(bitsize) +
sizeof(uint32_t))
{
handler(message(request, error::bad_stream));
return;
}

// actual bitfield data
const auto blocks = deserial.read_data(binary::blocks_size(bitsize));
const binary prefix(bitsize, blocks);

// from_height
const uint64_t from_height = deserial.read_4_bytes_little_endian();

node.chain().fetch_stealth(prefix, from_height,
std::bind(&blockchain::stealth_fetched2,
_1, _2, request, handler));
}

void blockchain::stealth_fetched2(const code& ec,
const stealth_compact::list& stealth_results, const message& request,
send_handler handler)
{
// [ code:4 ]
// [[ tx_hash:32 ]...]
data_chunk result(code_size + hash_size * stealth_results.size());
auto serial = make_serializer(result.begin());
serial.write_error_code(ec);

for (const auto& row: stealth_results)
serial.write_hash(row.transaction_hash);

handler(message(request, result));
}

} // namespace server
} // namespace libbitcoin
8 changes: 6 additions & 2 deletions src/workers/query_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,11 @@ void query_worker::attach(const std::string& command,
// address.subscribe2 is new in v3, also call for renew.
// address.unsubscribe2 is new in v3 (there was never an address.unsubscribe).
//-----------------------------------------------------------------------------
//// protocol.broadcast_transaction is deprecated in v3 (deferred).
//// transaction_pool.broadcast (with radar) is new in v3 (deferred).
///protocol.fetch_stealth is deprecated in v3.
// protocol.fetch_stealth2 is new in v3.
//-----------------------------------------------------------------------------
// blockchain.broadcast_transaction is deprecated in v3 (deferred).
// transaction_pool.broadcast (with radar) is new in v3 (deferred).
//=============================================================================
// Interface class.method names must match protocol (do not change).
void query_worker::attach_interface()
Expand All @@ -223,6 +226,7 @@ void query_worker::attach_interface()
ATTACH(blockchain, fetch_transaction_index, node_);
ATTACH(blockchain, fetch_spend, node_);
ATTACH(blockchain, fetch_stealth, node_);
ATTACH(blockchain, fetch_stealth2, node_);
ATTACH(transaction_pool, fetch_transaction, node_);
ATTACH(transaction_pool, validate, node_);
////ATTACH(transaction_pool, broadcast, node_);
Expand Down