wallet.cpp: Subscribe to block updates, fix #302
This commit is contained in:
parent
77ac6eb689
commit
358a88037c
3 changed files with 23 additions and 1 deletions
|
|
@ -923,10 +923,18 @@ namespace graphene { namespace app {
|
|||
*/
|
||||
void database_api::on_applied_block()
|
||||
{
|
||||
if (_block_applied_callback)
|
||||
{
|
||||
auto capture_this = shared_from_this();
|
||||
block_id_type block_id = _db.head_block_id();
|
||||
fc::async([this,capture_this,block_id](){
|
||||
_block_applied_callback(fc::variant(block_id));
|
||||
});
|
||||
}
|
||||
|
||||
if(_market_subscriptions.size() == 0)
|
||||
return;
|
||||
|
||||
|
||||
const auto& ops = _db.get_applied_operations();
|
||||
map< std::pair<asset_id_type,asset_id_type>, vector<pair<operation, operation_result>> > subscribed_markets_ops;
|
||||
for(const auto& op : ops)
|
||||
|
|
|
|||
|
|
@ -367,6 +367,7 @@ namespace graphene { namespace app {
|
|||
|
||||
void set_subscribe_callback( std::function<void(const variant&)> cb, bool clear_filter );
|
||||
void set_pending_transaction_callback( std::function<void(const variant&)> cb ){ _pending_trx_callback = cb; }
|
||||
void set_block_applied_callback( std::function<void(const variant& block_id)> cb ){ _block_applied_callback = cb; }
|
||||
private:
|
||||
template<typename T>
|
||||
void subscribe_to_item( const T& i )const
|
||||
|
|
@ -398,6 +399,7 @@ namespace graphene { namespace app {
|
|||
mutable fc::bloom_filter _subscribe_filter;
|
||||
std::function<void(const fc::variant&)> _subscribe_callback;
|
||||
std::function<void(const fc::variant&)> _pending_trx_callback;
|
||||
std::function<void(const fc::variant&)> _block_applied_callback;
|
||||
|
||||
boost::signals2::scoped_connection _change_connection;
|
||||
boost::signals2::scoped_connection _removed_connection;
|
||||
|
|
@ -606,6 +608,7 @@ FC_API(graphene::app::database_api,
|
|||
(get_required_fees)
|
||||
(set_subscribe_callback)
|
||||
(set_pending_transaction_callback)
|
||||
(set_block_applied_callback)
|
||||
(validate_transaction)
|
||||
)
|
||||
FC_API(graphene::app::history_api,
|
||||
|
|
|
|||
|
|
@ -375,6 +375,12 @@ public:
|
|||
("chain_id", _chain_id) );
|
||||
}
|
||||
init_prototype_ops();
|
||||
|
||||
_remote_db->set_block_applied_callback( [this](const variant& block_id )
|
||||
{
|
||||
on_block_applied( block_id );
|
||||
} );
|
||||
|
||||
_wallet.chain_id = _chain_id;
|
||||
_wallet.ws_server = initial_data.ws_server;
|
||||
_wallet.ws_user = initial_data.ws_user;
|
||||
|
|
@ -408,6 +414,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void on_block_applied( const variant& block_id )
|
||||
{
|
||||
fc::async([this]{resync();}, "Resync after block");
|
||||
}
|
||||
|
||||
bool copy_wallet_file( string destination_filename )
|
||||
{
|
||||
fc::path src_path = get_wallet_filename();
|
||||
|
|
|
|||
Loading…
Reference in a new issue