|
| 1 | +#include <golos/api/account_api_object.hpp> |
| 2 | + |
| 3 | +namespace golos { namespace api { |
| 4 | + |
| 5 | +using golos::chain::by_account; |
| 6 | +using golos::chain::by_account_bandwidth_type; |
| 7 | +using golos::chain::account_bandwidth_object; |
| 8 | +using golos::chain::account_authority_object; |
| 9 | +using golos::chain::account_metadata_object; |
| 10 | +using golos::chain::bandwidth_type; |
| 11 | + |
| 12 | +account_api_object::account_api_object(const account_object& a, const golos::chain::database& db) |
| 13 | + : id(a.id), name(a.name), memo_key(a.memo_key), proxy(a.proxy), |
| 14 | + last_account_update(a.last_account_update), created(a.created), mined(a.mined), |
| 15 | + owner_challenged(a.owner_challenged), active_challenged(a.active_challenged), |
| 16 | + last_owner_proved(a.last_owner_proved), last_active_proved(a.last_active_proved), |
| 17 | + recovery_account(a.recovery_account), reset_account(a.reset_account), |
| 18 | + last_account_recovery(a.last_account_recovery), comment_count(a.comment_count), |
| 19 | + lifetime_vote_count(a.lifetime_vote_count), post_count(a.post_count), can_vote(a.can_vote), |
| 20 | + voting_power(a.voting_power), last_vote_time(a.last_vote_time), |
| 21 | + balance(a.balance), savings_balance(a.savings_balance), |
| 22 | + sbd_balance(a.sbd_balance), sbd_seconds(a.sbd_seconds), |
| 23 | + sbd_seconds_last_update(a.sbd_seconds_last_update), |
| 24 | + sbd_last_interest_payment(a.sbd_last_interest_payment), |
| 25 | + savings_sbd_balance(a.savings_sbd_balance), savings_sbd_seconds(a.savings_sbd_seconds), |
| 26 | + savings_sbd_seconds_last_update(a.savings_sbd_seconds_last_update), |
| 27 | + savings_sbd_last_interest_payment(a.savings_sbd_last_interest_payment), |
| 28 | + savings_withdraw_requests(a.savings_withdraw_requests), |
| 29 | + curation_rewards(a.curation_rewards), posting_rewards(a.posting_rewards), |
| 30 | + vesting_shares(a.vesting_shares), |
| 31 | + delegated_vesting_shares(a.delegated_vesting_shares), received_vesting_shares(a.received_vesting_shares), |
| 32 | + vesting_withdraw_rate(a.vesting_withdraw_rate), next_vesting_withdrawal(a.next_vesting_withdrawal), |
| 33 | + withdrawn(a.withdrawn), to_withdraw(a.to_withdraw), withdraw_routes(a.withdraw_routes), |
| 34 | + witnesses_voted_for(a.witnesses_voted_for), last_post(a.last_post) { |
| 35 | + size_t n = a.proxied_vsf_votes.size(); |
| 36 | + proxied_vsf_votes.reserve(n); |
| 37 | + for (size_t i = 0; i < n; i++) { |
| 38 | + proxied_vsf_votes.push_back(a.proxied_vsf_votes[i]); |
| 39 | + } |
| 40 | + |
| 41 | + const auto& auth = db.get<account_authority_object, by_account>(name); |
| 42 | + owner = authority(auth.owner); |
| 43 | + active = authority(auth.active); |
| 44 | + posting = authority(auth.posting); |
| 45 | + last_owner_update = auth.last_owner_update; |
| 46 | + |
| 47 | +#ifndef IS_LOW_MEM |
| 48 | + const auto& meta = db.get<account_metadata_object, by_account>(name); |
| 49 | + json_metadata = golos::chain::to_string(meta.json_metadata); |
| 50 | +#endif |
| 51 | + |
| 52 | + auto old_forum = db.find<account_bandwidth_object, by_account_bandwidth_type>( |
| 53 | + std::make_tuple(name, bandwidth_type::old_forum)); |
| 54 | + if (old_forum != nullptr) { |
| 55 | + average_bandwidth = old_forum->average_bandwidth; |
| 56 | + lifetime_bandwidth = old_forum->lifetime_bandwidth; |
| 57 | + last_bandwidth_update = old_forum->last_bandwidth_update; |
| 58 | + } |
| 59 | + |
| 60 | + auto old_market = db.find<account_bandwidth_object, by_account_bandwidth_type>( |
| 61 | + std::make_tuple(name, bandwidth_type::old_market)); |
| 62 | + if (old_market != nullptr) { |
| 63 | + average_market_bandwidth = old_market->average_bandwidth; |
| 64 | + last_market_bandwidth_update = old_market->last_bandwidth_update; |
| 65 | + } |
| 66 | + |
| 67 | + auto post = db.find<account_bandwidth_object, by_account_bandwidth_type>( |
| 68 | + std::make_tuple(name, bandwidth_type::post)); |
| 69 | + if (post != nullptr) { |
| 70 | + last_root_post = post->last_bandwidth_update; |
| 71 | + post_bandwidth = post->average_bandwidth; |
| 72 | + } |
| 73 | + |
| 74 | + auto forum = db.find<account_bandwidth_object, by_account_bandwidth_type>( |
| 75 | + std::make_tuple(name, bandwidth_type::forum)); |
| 76 | + if (forum != nullptr) { |
| 77 | + new_average_bandwidth = forum->average_bandwidth; |
| 78 | + } |
| 79 | + |
| 80 | + auto market = db.find<account_bandwidth_object, by_account_bandwidth_type>( |
| 81 | + std::make_tuple(name, bandwidth_type::market)); |
| 82 | + if (market != nullptr) { |
| 83 | + new_average_market_bandwidth = market->average_bandwidth; |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +account_api_object::account_api_object() {} |
| 88 | + |
| 89 | +} } // golos::api |
0 commit comments