WIP: Some Bitcoin transaction processing

This commit is contained in:
Srdjan Obucina 2019-12-04 14:31:26 +01:00
parent 61e58cb62a
commit e42e4f1061
7 changed files with 548 additions and 60 deletions

View file

@ -0,0 +1,391 @@
2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J
{
"address": "2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J",
"scriptPubKey": "a914873aad1ecf7510c80b83d8ca94d21432dc71b88787",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/2']0368dc31b2b547c74f52abfc67c7fc768c68115d8ab96430d9bb4996fa660121cd))#7s0qfnvz",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "00141d30ac0c47f7b32460265daf49c5925236f5882d",
"pubkey": "0368dc31b2b547c74f52abfc67c7fc768c68115d8ab96430d9bb4996fa660121cd",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "1d30ac0c47f7b32460265daf49c5925236f5882d",
"pubkey": "0368dc31b2b547c74f52abfc67c7fc768c68115d8ab96430d9bb4996fa660121cd",
"address": "bcrt1qr5c2crz877ejgcpxtkh5n3vj2gm0tzpdqrw3n0",
"scriptPubKey": "00141d30ac0c47f7b32460265daf49c5925236f5882d"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/2'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2MxAnE469fhhdvUqUB7daU997VSearb2mn7
{
"address": "2MxAnE469fhhdvUqUB7daU997VSearb2mn7",
"scriptPubKey": "a914360175a50918495a20573aed68d506a790420fe587",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/3']02b510a452d6e80f943e4cc85af5cad6c528bda87fc92b821dd246a1a76c175b0d))#p3st4e4e",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "00146c1c0571f3132eb0702f487123d2026495592830",
"pubkey": "02b510a452d6e80f943e4cc85af5cad6c528bda87fc92b821dd246a1a76c175b0d",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "6c1c0571f3132eb0702f487123d2026495592830",
"pubkey": "02b510a452d6e80f943e4cc85af5cad6c528bda87fc92b821dd246a1a76c175b0d",
"address": "bcrt1qdswq2u0nzvhtqup0fpcj85szvj24j2psgfwy6w",
"scriptPubKey": "00146c1c0571f3132eb0702f487123d2026495592830"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/3'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL
{
"address": "2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL",
"scriptPubKey": "a914bdce56e7f2fc04614c0f6f4d1d59fff63b0b73f187",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/4']020d771492947feb54abbcbc5f5e86ef26df3747c377573c709507a47f10636462))#3r63c8fu",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "00146abd0d5f055df80b41bc6449328eda09f61a2be3",
"pubkey": "020d771492947feb54abbcbc5f5e86ef26df3747c377573c709507a47f10636462",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "6abd0d5f055df80b41bc6449328eda09f61a2be3",
"pubkey": "020d771492947feb54abbcbc5f5e86ef26df3747c377573c709507a47f10636462",
"address": "bcrt1qd27s6hc9thuqksduv3yn9rk6p8mp52lr2e846e",
"scriptPubKey": "00146abd0d5f055df80b41bc6449328eda09f61a2be3"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/4'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2N9zPaLDfaJazUmVfr3wgn8BK75tid2kkzR
{
"address": "2N9zPaLDfaJazUmVfr3wgn8BK75tid2kkzR",
"scriptPubKey": "a914b7abe6d957106da3a21782eea1164f4964b521ba87",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/5']03585ae695cfbbc8e1a93feeb6438c62d744b2581ba36a1e5ca780edd35aedb8ce))#e3sfze3l",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "00147a4fd72ff8e192004c70d8139b4ca53e1467d8c8",
"pubkey": "03585ae695cfbbc8e1a93feeb6438c62d744b2581ba36a1e5ca780edd35aedb8ce",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "7a4fd72ff8e192004c70d8139b4ca53e1467d8c8",
"pubkey": "03585ae695cfbbc8e1a93feeb6438c62d744b2581ba36a1e5ca780edd35aedb8ce",
"address": "bcrt1q0f8awtlcuxfqqnrsmqfekn998c2x0kxgf4t7dm",
"scriptPubKey": "00147a4fd72ff8e192004c70d8139b4ca53e1467d8c8"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/5'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2NDN7cDH3E57E1B8TwTYvBgF7CndL4FTBPL
{
"address": "2NDN7cDH3E57E1B8TwTYvBgF7CndL4FTBPL",
"scriptPubKey": "a914dcb019e8330b4fffc50ba22bbf90215922a1379787",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/6']028c78c069d3d6eeb73373eb54edfa61f2e974c01c21b979b0b3f7058805b95013))#3326m2za",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "0014ccd3dee026a1d641352f5b8c7d72805d75fd0652",
"pubkey": "028c78c069d3d6eeb73373eb54edfa61f2e974c01c21b979b0b3f7058805b95013",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "ccd3dee026a1d641352f5b8c7d72805d75fd0652",
"pubkey": "028c78c069d3d6eeb73373eb54edfa61f2e974c01c21b979b0b3f7058805b95013",
"address": "bcrt1qenfaacpx58tyzdf0twx86u5qt46l6pjjef5y7u",
"scriptPubKey": "0014ccd3dee026a1d641352f5b8c7d72805d75fd0652"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/6'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2MzEmSiwrRzozxE6gfZ14LAyDHZ4DYP1zVG
{
"address": "2MzEmSiwrRzozxE6gfZ14LAyDHZ4DYP1zVG",
"scriptPubKey": "a9144cb2b8f97d8e7ad5bfb81afd611394387f374ab887",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/7']02f7d952e00d9c262c20c3526d4029245ab890a28dbdcbadfec964578c47719f7b))#7gvhakzu",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "0014e3607a0f745e2fb8b04fe1fa7f078c35009a77c1",
"pubkey": "02f7d952e00d9c262c20c3526d4029245ab890a28dbdcbadfec964578c47719f7b",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "e3607a0f745e2fb8b04fe1fa7f078c35009a77c1",
"pubkey": "02f7d952e00d9c262c20c3526d4029245ab890a28dbdcbadfec964578c47719f7b",
"address": "bcrt1quds85rm5tchm3vz0u8a87puvx5qf5a7pqw8u7l",
"scriptPubKey": "0014e3607a0f745e2fb8b04fe1fa7f078c35009a77c1"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/7'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2NDCdm1WVJVCMWJzRaSSy9NDvpNKiqkbrMg
{
"address": "2NDCdm1WVJVCMWJzRaSSy9NDvpNKiqkbrMg",
"scriptPubKey": "a914dae51c6601ef4e05817f67d57d3ac0c8cb64948e87",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/8']03b358000050ffc6318a44d08ee9da9484d5a7d95f509241adf8a52555a0fdde6b))#ckuy6v83",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "001460c1c7776b1f92cd36fe6138b99212ebe6381fe7",
"pubkey": "03b358000050ffc6318a44d08ee9da9484d5a7d95f509241adf8a52555a0fdde6b",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "60c1c7776b1f92cd36fe6138b99212ebe6381fe7",
"pubkey": "03b358000050ffc6318a44d08ee9da9484d5a7d95f509241adf8a52555a0fdde6b",
"address": "bcrt1qvrquwamtr7fv6dh7vyutnysja0nrs8l8vzcnwj",
"scriptPubKey": "001460c1c7776b1f92cd36fe6138b99212ebe6381fe7"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/8'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2Mu2iz3Jfqjyv3hBQGQZSGmZGZxhJp91TNX
{
"address": "2Mu2iz3Jfqjyv3hBQGQZSGmZGZxhJp91TNX",
"scriptPubKey": "a91413930c6d40f5f01b169f2fc7884c2b3984ff8a3087",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/9']022752cd513f04f68074bd90a96a82b523a197171376382dedf3413bbdccae0dac))#f8cdpnn9",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "001435b75b7c34a7f908955b8b93aaa677aa47fab2c4",
"pubkey": "022752cd513f04f68074bd90a96a82b523a197171376382dedf3413bbdccae0dac",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "35b75b7c34a7f908955b8b93aaa677aa47fab2c4",
"pubkey": "022752cd513f04f68074bd90a96a82b523a197171376382dedf3413bbdccae0dac",
"address": "bcrt1qxkm4klp55lus392m3wf64fnh4frl4vkyng4ffg",
"scriptPubKey": "001435b75b7c34a7f908955b8b93aaa677aa47fab2c4"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/9'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2N1sFbwcn4QVbvjp7yRsN4mg4mBFbvC8gKM
{
"address": "2N1sFbwcn4QVbvjp7yRsN4mg4mBFbvC8gKM",
"scriptPubKey": "a9145e91543069ae37d8bace2f59aade945f5916dc3287",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/10']03114bf9794439221c0f7e910d7b64f242847184381a5ef238cef8d70f8868b4af))#x7xpvc0y",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "0014ceb35b8198b58c76fcc78a70d1d3a2ed1d4325f2",
"pubkey": "03114bf9794439221c0f7e910d7b64f242847184381a5ef238cef8d70f8868b4af",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "ceb35b8198b58c76fcc78a70d1d3a2ed1d4325f2",
"pubkey": "03114bf9794439221c0f7e910d7b64f242847184381a5ef238cef8d70f8868b4af",
"address": "bcrt1qe6e4hqvckkx8dlx83fcdr5aza5w5xf0jd22xet",
"scriptPubKey": "0014ceb35b8198b58c76fcc78a70d1d3a2ed1d4325f2"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/10'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}
2NDmxr6ufBE7Zgdgq9hShF2grx2YPEiTyNy
{
"address": "2NDmxr6ufBE7Zgdgq9hShF2grx2YPEiTyNy",
"scriptPubKey": "a914e132c578bd294a01a472d42b376b29e5ef6678c987",
"ismine": true,
"solvable": true,
"desc": "sh(wpkh([153472fd/0'/0'/11']02eb6e43fb6ad9f1bf23bf821a25d5a1e84550380e0973ea5b00b087b3e9059c7b))#2janhauz",
"iswatchonly": false,
"isscript": true,
"iswitness": false,
"script": "witness_v0_keyhash",
"hex": "0014831d63f8d99be71f9b385f2ccc92ab2783da3762",
"pubkey": "02eb6e43fb6ad9f1bf23bf821a25d5a1e84550380e0973ea5b00b087b3e9059c7b",
"embedded": {
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "831d63f8d99be71f9b385f2ccc92ab2783da3762",
"pubkey": "02eb6e43fb6ad9f1bf23bf821a25d5a1e84550380e0973ea5b00b087b3e9059c7b",
"address": "bcrt1qsvwk87xen0n3lxectukvey4ty7pa5dmz0yanuv",
"scriptPubKey": "0014831d63f8d99be71f9b385f2ccc92ab2783da3762"
},
"label": "",
"ischange": false,
"timestamp": 1571845292,
"hdkeypath": "m/0'/0'/11'",
"hdseedid": "7fc94a298c785719434c63458bb41bc1995a270d",
"hdmasterfingerprint": "153472fd",
"labels": [
{
"name": "",
"purpose": "receive"
}
]
}

View file

@ -0,0 +1,70 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <fc/crypto/sha256.hpp>
namespace graphene { namespace peerplays_sidechain {
enum network {
bitcoin,
//ethereum
};
using bytes = std::vector<char>;
struct prev_out
{
bool operator!=( const prev_out& obj ) const
{
if( this->hash_tx != obj.hash_tx ||
this->n_vout != obj.n_vout ||
this->amount != obj.amount )
{
return true;
}
return false;
}
std::string hash_tx;
uint32_t n_vout;
uint64_t amount;
};
struct info_for_vin
{
info_for_vin() = default;
info_for_vin( const prev_out& _out, const std::string& _address, bytes _script = bytes(), bool _resend = false );
bool operator!=( const info_for_vin& obj ) const;
struct comparer {
bool operator() ( const info_for_vin& lhs, const info_for_vin& rhs ) const;
};
static uint64_t count_id_info_for_vin;
uint64_t id;
fc::sha256 identifier;
prev_out out;
std::string address;
bytes script;
bool used = false;
bool resend = false;
};
struct sidechain_event_data {
network sidechain;
std::string transaction_id;
std::string from;
std::string to;
int64_t amount;
};
} } // graphene::peerplays_sidechain

View file

@ -1,5 +1,9 @@
#pragma once
#include <graphene/peerplays_sidechain/defs.hpp>
#include <vector>
#include <boost/program_options.hpp>
namespace graphene { namespace peerplays_sidechain {
@ -9,12 +13,16 @@ public:
sidechain_net_handler(const boost::program_options::variables_map& options);
virtual ~sidechain_net_handler();
std::vector<std::string> get_user_sidechain_address_mapping();
protected:
graphene::peerplays_sidechain::network network;
virtual std::string create_multisignature_wallet( const std::vector<std::string> public_keys ) = 0;
virtual std::string transfer( const std::string& from, const std::string& to, const uint64_t amount ) = 0;
virtual std::string sign_transaction( const std::string& transaction ) = 0;
virtual std::string send_transaction( const std::string& transaction ) = 0;
protected:
virtual void handle_event( const std::string& event_data ) = 0;
private:

View file

@ -59,7 +59,7 @@ public:
sidechain_net_handler_bitcoin(const boost::program_options::variables_map& options);
virtual ~sidechain_net_handler_bitcoin();
//void update_tx_infos( const std::string& block_hash );
void update_tx_infos( const std::string& block_hash );
//void update_tx_approvals();
@ -87,7 +87,7 @@ private:
void handle_event( const std::string& event_data);
//std::vector<info_for_vin> extract_info_from_block( const std::string& _block );
std::vector<info_for_vin> extract_info_from_block( const std::string& _block );
void update_transaction_status( std::vector<fc::sha256> trx_for_check );

View file

@ -1,5 +1,6 @@
#pragma once
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
#include <vector>
@ -8,19 +9,6 @@
namespace graphene { namespace peerplays_sidechain {
enum network {
bitcoin,
//ethereum
};
struct sidechain_event_data {
network sidechain;
std::string transaction_id;
std::string from;
std::string to;
int64_t amount;
};
class sidechain_net_manager {
public:
sidechain_net_manager();

View file

@ -8,5 +8,28 @@ sidechain_net_handler::sidechain_net_handler(const boost::program_options::varia
sidechain_net_handler::~sidechain_net_handler() {
}
std::vector<std::string> sidechain_net_handler::get_user_sidechain_address_mapping() {
std::vector<std::string> result;
switch (network) {
case network::bitcoin:
result.push_back("2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J");
result.push_back("2MxAnE469fhhdvUqUB7daU997VSearb2mn7");
result.push_back("2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL");
result.push_back("2N9zPaLDfaJazUmVfr3wgn8BK75tid2kkzR");
result.push_back("2NDN7cDH3E57E1B8TwTYvBgF7CndL4FTBPL");
//result.push_back("2MzEmSiwrRzozxE6gfZ14LAyDHZ4DYP1zVG");
//result.push_back("2NDCdm1WVJVCMWJzRaSSy9NDvpNKiqkbrMg");
//result.push_back("2Mu2iz3Jfqjyv3hBQGQZSGmZGZxhJp91TNX");
//result.push_back("2N1sFbwcn4QVbvjp7yRsN4mg4mBFbvC8gKM");
//result.push_back("2NDmxr6ufBE7Zgdgq9hShF2grx2YPEiTyNy");
default:
assert(false);
}
return result;
}
} } // graphene::peerplays_sidechain

View file

@ -1,5 +1,6 @@
#include <graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp>
#include <algorithm>
#include <thread>
#include <boost/algorithm/hex.hpp>
@ -10,6 +11,8 @@
#include <fc/log/logger.hpp>
#include <fc/network/ip.hpp>
#include "graphene/peerplays_sidechain/sidechain_net_manager.hpp"
namespace graphene { namespace peerplays_sidechain {
// =============================================================================
@ -166,8 +169,10 @@ std::vector<zmq::message_t> zmq_listener::receive_multipart() {
}
void zmq_listener::handle_zmq() {
socket.setsockopt( ZMQ_SUBSCRIBE, "hashblock", 0 );
//socket.setsockopt( ZMQ_SUBSCRIBE, "hashtx", 0 );
socket.setsockopt( ZMQ_SUBSCRIBE, "hashblock", 9 );
//socket.setsockopt( ZMQ_SUBSCRIBE, "hashtx", 6 );
//socket.setsockopt( ZMQ_SUBSCRIBE, "rawblock", 8 );
//socket.setsockopt( ZMQ_SUBSCRIBE, "rawtx", 5 );
socket.connect( "tcp://" + ip + ":" + std::to_string( zmq_port ) );
while ( true ) {
@ -183,6 +188,8 @@ void zmq_listener::handle_zmq() {
sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(const boost::program_options::variables_map& options) :
sidechain_net_handler(options) {
network = peerplays_sidechain::network::bitcoin;
ip = options.at("bitcoin-node-ip").as<std::string>();
zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();
rpc_port = options.at("bitcoin-node-rpc-port").as<uint32_t>();
@ -213,19 +220,19 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(const boost::progra
sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
}
//void sidechain_net_handler_bitcoin::update_tx_infos( const std::string& block_hash )
//{
// std::string block = bitcoin_client->receive_full_block( block_hash );
// if( block != "" ) {
// const auto& vins = extract_info_from_block( block );
void sidechain_net_handler_bitcoin::update_tx_infos( const std::string& block_hash )
{
std::string block = bitcoin_client->receive_full_block( block_hash );
if( block != "" ) {
const auto& vins = extract_info_from_block( block );
// const auto& addr_idx = db->get_index_type<bitcoin_address_index>().indices().get<by_address>();
// for( const auto& v : vins ) {
// const auto& addr_itr = addr_idx.find( v.address );
// FC_ASSERT( addr_itr != addr_idx.end() );
// db->i_w_info.insert_info_for_vin( prev_out{ v.out.hash_tx, v.out.n_vout, v.out.amount }, v.address, addr_itr->address.get_witness_script() );
// }
// }
//}
}
}
//void sidechain_net_handler_bitcoin::update_tx_approvals()
//{
@ -300,41 +307,42 @@ void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data
//update_tx_infos( block_hash );
}
//std::vector<info_for_vin> sidechain_net_handler_bitcoin::extract_info_from_block( const std::string& _block )
//{
// std::stringstream ss( _block );
// boost::property_tree::ptree block;
// boost::property_tree::read_json( ss, block );
//
// std::vector<info_for_vin> result;
//
// const auto& addr_idx = db->get_index_type<bitcoin_address_index>().indices().get<by_address>();
//
// for (const auto& tx_child : block.get_child("tx")) {
// const auto& tx = tx_child.second;
//
// for ( const auto& o : tx.get_child("vout") ) {
// const auto script = o.second.get_child("scriptPubKey");
//
// if( !script.count("addresses") ) continue;
//
// for (const auto& addr : script.get_child("addresses")) { // in which cases there can be more addresses?
// const auto address_base58 = addr.second.get_value<std::string>();
//
// if( !addr_idx.count( address_base58 ) ) continue;
//
// info_for_vin vin;
// vin.out.hash_tx = tx.get_child("txid").get_value<std::string>();
// vin.out.amount = parse_amount( o.second.get_child( "value" ).get_value<std::string>() );
// vin.out.n_vout = o.second.get_child( "n" ).get_value<uint32_t>();
// vin.address = address_base58;
// result.push_back( vin );
// }
// }
// }
//
// return result;
//}
std::vector<info_for_vin> sidechain_net_handler_bitcoin::extract_info_from_block( const std::string& _block )
{
std::stringstream ss( _block );
boost::property_tree::ptree block;
boost::property_tree::read_json( ss, block );
std::vector<info_for_vin> result;
const auto& addr_idx = get_user_sidechain_address_mapping();// db->get_index_type<bitcoin_address_index>().indices().get<by_address>();
for (const auto& tx_child : block.get_child("tx")) {
const auto& tx = tx_child.second;
for ( const auto& o : tx.get_child("vout") ) {
const auto script = o.second.get_child("scriptPubKey");
if( !script.count("addresses") ) continue;
for (const auto& addr : script.get_child("addresses")) { // in which cases there can be more addresses?
const auto address_base58 = addr.second.get_value<std::string>();
auto it = find(addr_idx.begin(), addr_idx.end(), address_base58);
if (it == addr_idx.end()) continue;
info_for_vin vin;
vin.out.hash_tx = tx.get_child("txid").get_value<std::string>();
vin.out.amount = parse_amount( o.second.get_child( "value" ).get_value<std::string>() );
vin.out.n_vout = o.second.get_child( "n" ).get_value<uint32_t>();
vin.address = address_base58;
result.push_back( vin );
}
}
}
return result;
}
//void sidechain_net_handler_bitcoin::update_transaction_status( std::vector<fc::sha256> trx_for_check )
//{