87 lines
No EOL
3 KiB
C++
87 lines
No EOL
3 KiB
C++
|
|
#include <graphene/peerplays_sidechain/bitcoin/libbitcoin_client.hpp>
|
|
|
|
#include <system_error>
|
|
|
|
#include <bitcoin/system/config/hash256.hpp>
|
|
|
|
namespace graphene { namespace peerplays_sidechain {
|
|
|
|
libbitcoin_client::libbitcoin_client() :
|
|
obelisk_client(10, 100) {
|
|
libbitcoin::client::connection_type connection;
|
|
connection.retries = 100;
|
|
connection.server = libbitcoin::config::endpoint("tcp://localhost", 9091);
|
|
|
|
if (!obelisk_client.connect(connection)) {
|
|
//display_connection_failure(error, connection.server);
|
|
//return console_result::failure;
|
|
std::cout << "Can't connect" << std::endl;
|
|
}
|
|
}
|
|
|
|
void libbitcoin_client::send_transaction(std::string tx) {
|
|
// std::cout<<"Enter in function"<<std::endl;
|
|
// auto error_handler = [&](const std::error_code &ec) {
|
|
// std::cout << "Error code: " << ec << std::endl;
|
|
// };
|
|
|
|
// auto result_handler = [&](libbitcoin::code result_code) {
|
|
// std::cout << "result is: " << result_code << std::endl;
|
|
// };
|
|
|
|
// std::cout<<"Transaction: "<<tx<<std::endl;
|
|
// libbitcoin::explorer::config::transaction transaction(tx);
|
|
|
|
// // This validates the tx, submits it to local tx pool, and notifies peers.
|
|
// libbitcoin_client.transaction_pool_broadcast(error_handler, result_handler, transaction);
|
|
// libbitcoin_client.wait();
|
|
}
|
|
|
|
void libbitcoin_client::fetch_trx_by_address(std::string address, double amount) {
|
|
auto error_handler = [&](const std::error_code &ec) {
|
|
std::cout << "Error code: " << ec << std::endl;
|
|
};
|
|
|
|
auto history_handler = [&](const libbitcoin::chain::history::list &rows) {
|
|
for (auto &row : rows) {
|
|
std::cout << "LIB Hash: " << libbitcoin::config::hash256(row.output.hash()) << std::endl;
|
|
std::cout << "LIB Amount: " << row.value;
|
|
}
|
|
};
|
|
|
|
libbitcoin::wallet::payment_address payment_address(address);
|
|
|
|
obelisk_client.blockchain_fetch_history3(error_handler,
|
|
history_handler, address);
|
|
|
|
obelisk_client.wait();
|
|
}
|
|
|
|
std::vector<list_unspent_replay> libbitcoin_client::list_unspent(std::string address, double amount) {
|
|
std::vector<list_unspent_replay> result;
|
|
|
|
auto error_handler = [&](const std::error_code &ec) {
|
|
std::cout << "Error code: " << ec << std::endl;
|
|
};
|
|
|
|
auto replay_handler = [&](const libbitcoin::chain::points_value &points) {
|
|
for (auto &point : points.points) {
|
|
list_unspent_replay output;
|
|
output.hash = libbitcoin::config::hash256(point.hash()).to_string();
|
|
output.value = point.value();
|
|
output.index = point.index();
|
|
result.emplace_back(output);
|
|
}
|
|
};
|
|
|
|
libbitcoin::wallet::payment_address payment_address(address);
|
|
|
|
obelisk_client.blockchain_fetch_unspent_outputs(error_handler,
|
|
replay_handler, payment_address, 100000000, libbitcoin::wallet::select_outputs::algorithm::individual);
|
|
|
|
obelisk_client.wait();
|
|
|
|
return result;
|
|
}
|
|
}} // namespace graphene::peerplays_sidechain
|