Merge branch 'master' of github.com:cryptonomex/graphene
This commit is contained in:
commit
70746b82ad
6 changed files with 77 additions and 16 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,
|
||||
|
|
|
|||
|
|
@ -331,13 +331,13 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
// Create more special assets
|
||||
while( true )
|
||||
{
|
||||
uint64_t id = get_index<asset_object>().get_next_id().instance();
|
||||
if( id >= genesis_state.immutable_parameters.num_special_assets )
|
||||
break;
|
||||
const asset_dynamic_data_object& dyn_asset =
|
||||
create<asset_dynamic_data_object>([&](asset_dynamic_data_object& a) {
|
||||
a.current_supply = 0;
|
||||
});
|
||||
uint64_t id = get_index<asset_object>().get_next_id().instance();
|
||||
if( id >= genesis_state.immutable_parameters.num_special_assets )
|
||||
break;
|
||||
const asset_object& asset_obj = create<asset_object>( [&]( asset_object& a ) {
|
||||
a.symbol = "SPECIAL" + std::to_string( id );
|
||||
a.options.max_supply = 0;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ private:
|
|||
bool _production_enabled = false;
|
||||
bool _consecutive_production_enabled = false;
|
||||
uint32_t _required_witness_participation = 33 * GRAPHENE_1_PERCENT;
|
||||
uint32_t _production_skip_flags = graphene::chain::database::skip_nothing;
|
||||
|
||||
std::map<chain::public_key_type, fc::ecc::private_key> _private_keys;
|
||||
std::set<chain::witness_id_type> _witnesses;
|
||||
|
|
|
|||
|
|
@ -123,8 +123,12 @@ void witness_plugin::plugin_startup()
|
|||
{
|
||||
ilog("Launching block production for ${n} witnesses.", ("n", _witnesses.size()));
|
||||
app().set_block_production(true);
|
||||
if( _production_enabled && (d.head_block_num() == 0) )
|
||||
new_chain_banner(d);
|
||||
if( _production_enabled )
|
||||
{
|
||||
if( d.head_block_num() == 0 )
|
||||
new_chain_banner(d);
|
||||
_production_skip_flags |= graphene::chain::database::skip_undo_history_check;
|
||||
}
|
||||
schedule_production_loop();
|
||||
} else
|
||||
elog("No witnesses configured! Please add witness IDs and private keys to configuration.");
|
||||
|
|
@ -278,7 +282,7 @@ block_production_condition::block_production_condition_enum witness_plugin::mayb
|
|||
scheduled_time,
|
||||
scheduled_witness,
|
||||
private_key_itr->second,
|
||||
graphene::chain::database::skip_nothing
|
||||
_production_skip_flags
|
||||
);
|
||||
capture("n", block.block_num())("t", block.timestamp)("c", now);
|
||||
p2p_node().broadcast(net::block_message(block));
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -649,15 +660,49 @@ public:
|
|||
("wallet.chain_id", _wallet.chain_id)
|
||||
("chain_id", _chain_id) );
|
||||
|
||||
vector< account_id_type > my_account_ids;
|
||||
my_account_ids.reserve( _wallet.my_accounts.size() );
|
||||
for( const account_object& acct : _wallet.my_accounts )
|
||||
my_account_ids.push_back( acct.id );
|
||||
// TODO: Batch requests using _remote_db->get_accounts()
|
||||
// to reduce number of round-trips. Remember get_accounts() has
|
||||
// a limit of 100 results per call!
|
||||
for( const account_id_type& acct_id : my_account_ids )
|
||||
_wallet.update_account( get_account( acct_id ) );
|
||||
size_t account_pagination = 100;
|
||||
vector< account_id_type > account_ids_to_send;
|
||||
size_t n = _wallet.my_accounts.size();
|
||||
account_ids_to_send.reserve( std::min( account_pagination, n ) );
|
||||
auto it = _wallet.my_accounts.begin();
|
||||
|
||||
for( size_t start=0; start<n; start+=account_pagination )
|
||||
{
|
||||
size_t end = std::min( start+account_pagination, n );
|
||||
assert( end > start );
|
||||
account_ids_to_send.clear();
|
||||
std::vector< account_object > old_accounts;
|
||||
for( size_t i=start; i<end; i++ )
|
||||
{
|
||||
assert( it != _wallet.my_accounts.end() );
|
||||
old_accounts.push_back( *it );
|
||||
account_ids_to_send.push_back( old_accounts.back().id );
|
||||
++it;
|
||||
}
|
||||
std::vector< optional< account_object > > accounts = _remote_db->get_accounts(account_ids_to_send);
|
||||
// server response should be same length as request
|
||||
FC_ASSERT( accounts.size() == account_ids_to_send.size() );
|
||||
size_t i = 0;
|
||||
for( const optional< account_object >& acct : accounts )
|
||||
{
|
||||
account_object& old_acct = old_accounts[i];
|
||||
if( !acct.valid() )
|
||||
{
|
||||
elog( "Could not find account ${id} : \"${name}\" does not exist on the chain!", ("id", old_acct.id)("name", old_acct.name) );
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
// this check makes sure the server didn't send results
|
||||
// in a different order, or accounts we didn't request
|
||||
FC_ASSERT( acct->id == old_acct.id );
|
||||
if( fc::json::to_string(*acct) != fc::json::to_string(old_acct) )
|
||||
{
|
||||
wlog( "Account ${id} : \"${name}\" updated on chain", ("id", acct->id)("name", acct->name) );
|
||||
}
|
||||
_wallet.update_account( *acct );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue