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