| 1482 | } |
| 1483 | |
| 1484 | void database_api_impl::on_objects_changed(const vector<object_id_type>& ids) |
| 1485 | { |
| 1486 | vector<variant> updates; |
| 1487 | map< pair<asset_id_type, asset_id_type>, vector<variant> > market_broadcast_queue; |
| 1488 | |
| 1489 | for(auto id : ids) |
| 1490 | { |
| 1491 | const object* obj = nullptr; |
| 1492 | if( _subscribe_callback ) |
| 1493 | { |
| 1494 | obj = _db.find_object( id ); |
| 1495 | if( obj ) |
| 1496 | { |
| 1497 | updates.emplace_back( obj->to_variant() ); |
| 1498 | } |
| 1499 | else |
| 1500 | { |
| 1501 | updates.emplace_back(id); // send just the id to indicate removal |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | if( _market_subscriptions.size() ) |
| 1506 | { |
| 1507 | if( !_subscribe_callback ) |
| 1508 | obj = _db.find_object( id ); |
| 1509 | if( obj ) |
| 1510 | { |
| 1511 | const limit_order_object* order = dynamic_cast<const limit_order_object*>(obj); |
| 1512 | if( order ) |
| 1513 | { |
| 1514 | auto sub = _market_subscriptions.find( order->get_market() ); |
| 1515 | if( sub != _market_subscriptions.end() ) |
| 1516 | market_broadcast_queue[order->get_market()].emplace_back( order->id ); |
| 1517 | } |
| 1518 | } |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | auto capture_this = shared_from_this(); |
| 1523 | |
| 1524 | /// pushing the future back / popping the prior future if it is complete. |
| 1525 | /// if a connection hangs then this could get backed up and result in |
| 1526 | /// a failure to exit cleanly. |
| 1527 | fc::async([capture_this,this,updates,market_broadcast_queue](){ |
| 1528 | if( _subscribe_callback ) _subscribe_callback( updates ); |
| 1529 | |
| 1530 | for( const auto& item : market_broadcast_queue ) |
| 1531 | { |
| 1532 | auto sub = _market_subscriptions.find(item.first); |
| 1533 | if( sub != _market_subscriptions.end() ) |
| 1534 | sub->second( fc::variant(item.second ) ); |
| 1535 | } |
| 1536 | }); |
| 1537 | } |
| 1538 | |
| 1539 | /** note: this method cannot yield because it is called in the middle of |
| 1540 | * apply a block. |
nothing calls this directly
no test coverage detected