|
22 | 22 | #include <nano/secure/ledger_set_confirmed.hpp> |
23 | 23 | #include <nano/secure/transaction.hpp> |
24 | 24 | #include <nano/store/ext_ledger/account_delegators_by_weight.hpp> |
| 25 | +#include <nano/store/ext_ledger/account_receivables_by_amount.hpp> |
25 | 26 | #include <nano/store/ext_ledger_store.hpp> |
26 | 27 | #include <nano/store/ledger/account.hpp> |
27 | 28 | #include <nano/store/ledger/confirmation_height.hpp> |
@@ -3269,6 +3270,86 @@ void nano::json_handler::receivable () |
3269 | 3270 | response_errors (); |
3270 | 3271 | } |
3271 | 3272 |
|
| 3273 | +void nano::json_handler::receivable_ext () |
| 3274 | +{ |
| 3275 | + if (!node.store.ext.is_initialized ()) |
| 3276 | + { |
| 3277 | + ec = nano::error_rpc::requires_ext_ledger; |
| 3278 | + } |
| 3279 | + |
| 3280 | + auto account (account_impl ()); |
| 3281 | + auto count (count_optional_impl ()); |
| 3282 | + auto offset (offset_optional_impl (0)); |
| 3283 | + auto threshold (threshold_optional_impl ()); |
| 3284 | + bool const source = request.get<bool> ("source", false); |
| 3285 | + bool const min_version = request.get<bool> ("min_version", false); |
| 3286 | + bool const include_active = request.get<bool> ("include_active", false); |
| 3287 | + bool const include_only_confirmed = request.get<bool> ("include_only_confirmed", true); |
| 3288 | + auto simple (threshold.is_zero () && !source && !min_version); // if simple, response is a list of hashes |
| 3289 | + |
| 3290 | + if (!ec) |
| 3291 | + { |
| 3292 | + auto transaction = node.ledger.tx_begin_read (); |
| 3293 | + boost::property_tree::ptree peers_l; |
| 3294 | + |
| 3295 | + for (auto i = node.store.ext.account_receivables_by_amount.rupper_bound (transaction, account), n = node.store.ext.account_receivables_by_amount.rend (transaction); i != n && peers_l.size () < count; ++i) |
| 3296 | + { |
| 3297 | + nano::account_receivable_by_amount_key const & key = i->first; |
| 3298 | + nano::account_receivable_by_amount_info const & info = i->second; |
| 3299 | + |
| 3300 | + if (key.account != account) |
| 3301 | + { |
| 3302 | + break; |
| 3303 | + } |
| 3304 | + |
| 3305 | + if (key.amount.number () < threshold.number ()) |
| 3306 | + { |
| 3307 | + break; |
| 3308 | + } |
| 3309 | + |
| 3310 | + if (!block_confirmed (node, transaction, key.send_block_hash, include_active, include_only_confirmed)) |
| 3311 | + { |
| 3312 | + continue; |
| 3313 | + } |
| 3314 | + |
| 3315 | + if (offset > 0) |
| 3316 | + { |
| 3317 | + --offset; |
| 3318 | + continue; |
| 3319 | + } |
| 3320 | + |
| 3321 | + if (simple) |
| 3322 | + { |
| 3323 | + boost::property_tree::ptree entry; |
| 3324 | + entry.put ("", key.send_block_hash.to_string ()); |
| 3325 | + peers_l.push_back (std::make_pair ("", entry)); |
| 3326 | + } |
| 3327 | + else if (source || min_version) |
| 3328 | + { |
| 3329 | + boost::property_tree::ptree entry; |
| 3330 | + entry.put ("amount", key.amount.to_string_dec ()); |
| 3331 | + if (source) |
| 3332 | + { |
| 3333 | + entry.put ("source", info.source.to_account ()); |
| 3334 | + } |
| 3335 | + if (min_version) |
| 3336 | + { |
| 3337 | + entry.put ("min_version", epoch_as_string (info.epoch)); |
| 3338 | + } |
| 3339 | + peers_l.add_child (key.send_block_hash.to_string (), entry); |
| 3340 | + } |
| 3341 | + else |
| 3342 | + { |
| 3343 | + peers_l.put (key.send_block_hash.to_string (), key.amount.to_string_dec ()); |
| 3344 | + } |
| 3345 | + } |
| 3346 | + |
| 3347 | + response_l.add_child ("blocks", peers_l); |
| 3348 | + } |
| 3349 | + |
| 3350 | + response_errors (); |
| 3351 | +} |
| 3352 | + |
3272 | 3353 | void nano::json_handler::pending_exists () |
3273 | 3354 | { |
3274 | 3355 | response_l.put ("deprecated", "1"); |
@@ -5468,6 +5549,7 @@ ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map () |
5468 | 5549 | no_arg_funcs.emplace ("pending", &nano::json_handler::pending); |
5469 | 5550 | no_arg_funcs.emplace ("pending_exists", &nano::json_handler::pending_exists); |
5470 | 5551 | no_arg_funcs.emplace ("receivable", &nano::json_handler::receivable); |
| 5552 | + no_arg_funcs.emplace ("receivable_ext", &nano::json_handler::receivable_ext); |
5471 | 5553 | no_arg_funcs.emplace ("receivable_exists", &nano::json_handler::receivable_exists); |
5472 | 5554 | no_arg_funcs.emplace ("process", &nano::json_handler::process); |
5473 | 5555 | no_arg_funcs.emplace ("pruned_exists", &nano::json_handler::pruned_exists); |
|
0 commit comments