Skip to content

Commit

Permalink
Loading of delegations, rex, and msig proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Jan 22, 2025
1 parent 4bfb3e7 commit e786dbc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
8 changes: 7 additions & 1 deletion contracts/api/include/api/api.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <eosio.msig/eosio.msig.hpp>
#include <eosio.system/eosio.system.hpp>
#include <eosio/contract.hpp>
#include <eosio/singleton.hpp>

Expand All @@ -10,7 +12,11 @@ namespace api {

struct get_account_response
{
name account;
name account;
std::vector<eosiosystem::delegated_bandwidth> delegations;
std::vector<eosio::multisig::proposal> proposals;
std::optional<eosiosystem::rex_balance> rexbal;
std::optional<eosiosystem::rex_fund> rexfund;
};

class [[eosio::contract("api")]] api : public contract
Expand Down
37 changes: 36 additions & 1 deletion contracts/api/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,42 @@ namespace api {

[[eosio::action, eosio::read_only]] get_account_response api::getaccount(const name account)
{
return get_account_response{.account = account};
// get all delegated balances for the account
std::vector<eosiosystem::delegated_bandwidth> dbw_rows;
eosiosystem::del_bandwidth_table dbw_table("eosio"_n, account.value);
auto dbw_itr = dbw_table.begin();
while (dbw_itr != dbw_table.end()) {
dbw_rows.push_back(*dbw_itr);
dbw_itr++;
}

// get all msig proposals from the account
std::vector<eosio::multisig::proposal> msig_rows;
eosio::multisig::proposals msig_table("eosio.msig"_n, account.value);
auto msig_itr = msig_table.begin();
while (msig_itr != msig_table.end()) {
msig_rows.push_back(*msig_itr);
msig_itr++;
}

// get rexbal entry for the account
eosiosystem::rex_balance_table rexbal_table("eosio"_n, "eosio"_n.value);
auto rex_itr = rexbal_table.find(account.value);
eosiosystem::rex_balance rexbal;
if (rex_itr != rexbal_table.end()) {
rexbal = *rex_itr;
}

// get rexfund entry for the account
eosiosystem::rex_fund_table rexfund_table("eosio"_n, "eosio"_n.value);
auto rexfund_itr = rexfund_table.find(account.value);
eosiosystem::rex_fund rexfund;
if (rexfund_itr != rexfund_table.end()) {
rexfund = *rexfund_itr;
}

return get_account_response{
.account = account, .delegations = dbw_rows, .proposals = msig_rows, .rexbal = rexbal, .rexfund = rexfund};
}

} // namespace api
Expand Down

0 comments on commit e786dbc

Please sign in to comment.