Skip to content

Commit

Permalink
Merge pull request EOSIO#147 from winlin/release/3.0.x
Browse files Browse the repository at this point in the history
add /v1/producer/create_acts_snapshot
  • Loading branch information
Thaipanda authored Mar 7, 2020
2 parents 14db844 + 5df6936 commit 1ad50c3
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 3 deletions.
56 changes: 56 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,62 @@ read_only::get_account_results read_only::get_account( const get_account_params&
return result;
}

read_only::get_act_token_result read_only::get_act_token( const name& account_name )const {
get_act_token_result token_result{0.0, 0.0, 0.0, 0.0, 0.0};

get_account_params params{account_name};
get_account_results res = get_account(params);

if( res.core_liquid_balance.valid() ) {
token_result.liquid_balance = res.core_liquid_balance->to_real();
}

double cpu_own = 0.0, net_own = 0.0, cpu_total = 0.0, net_total = 0.0;
if ( res.total_resources.is_object() ) {
net_total = asset::from_string(res.total_resources.get_object()["net_weight"].as_string()).to_real();
cpu_total = asset::from_string(res.total_resources.get_object()["cpu_weight"].as_string()).to_real();
}
if( res.self_delegated_bandwidth.is_object() ) {
cpu_own = asset::from_string( res.self_delegated_bandwidth.get_object()["cpu_weight"].as_string() ).to_real();
net_own = asset::from_string( res.self_delegated_bandwidth.get_object()["net_weight"].as_string() ).to_real();
}
token_result.self_staked = cpu_own + net_own;
token_result.other_staked = net_total + cpu_total - token_result.self_staked;
if( res.refund_request.is_object() ) {
auto obj = res.refund_request.get_object();
token_result.unstaking = asset::from_string( obj["net_amount"].as_string() ).to_real() + asset::from_string( obj["cpu_amount"].as_string() ).to_real();
}
// REX
const auto& d = db.db();
const auto& code_account = db.db().get<account_object,by_name>( config::system_account_name );
abi_def abi;
if( abi_serializer::to_abi(code_account.abi, abi) ) {
abi_serializer abis( abi, abi_serializer_max_time );

const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, N(rexfund) ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, account_name ));
if ( it != idx.end() ) {
vector<char> data;
copy_inline_row(*it, data);
token_result.rex_deposit = abis.binary_to_variant( "rex_fund", data, abi_serializer_max_time, shorten_abi_errors ).get_object()["balance"].as<asset>().to_real();
}
}
t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, N(rexbal) ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, account_name ));
if ( it != idx.end() ) {
vector<char> data;
copy_inline_row(*it, data);
token_result.rex_deposit += abis.binary_to_variant( "rex_balance", data, abi_serializer_max_time, shorten_abi_errors ).get_object()["vote_stake"].as<asset>().to_real();
}
}
}
return token_result;
}

static variant action_abi_to_variant( const abi_def& abi, type_name action_type ) {
variant v;
auto it = std::find_if(abi.structs.begin(), abi.structs.end(), [&](auto& x){return x.name == action_type;});
Expand Down
13 changes: 13 additions & 0 deletions plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ class read_only {

using account_resource_limit = chain::resource_limits::account_resource_limit;

struct get_act_token_result {
double liquid_balance;
double self_staked;
double other_staked;
double unstaking;
double rex_deposit; // rexfund.balance + rexbal.vote_stake
};

struct get_account_results {
name account_name;
uint32_t head_block_num = 0;
Expand Down Expand Up @@ -151,6 +159,8 @@ class read_only {
};
get_account_results get_account( const get_account_params& params )const;

get_act_token_result get_act_token( const name& account_name )const;


struct get_code_results {
name account_name;
Expand Down Expand Up @@ -745,6 +755,9 @@ FC_REFLECT( eosio::chain_apis::read_only::get_account_results,
(account_name)(head_block_num)(head_block_time)(privileged)(last_code_update)(created)
(core_liquid_balance)(ram_quota)(net_weight)(cpu_weight)(net_limit)(cpu_limit)(ram_usage)(permissions)
(total_resources)(self_delegated_bandwidth)(refund_request)(voter_info)(homepage) )
FC_REFLECT( eosio::chain_apis::read_only::get_act_token_result,
(liquid_balance)(self_staked)(other_staked)(unstaking)(rex_deposit) )

FC_REFLECT( eosio::chain_apis::read_only::get_code_results, (account_name)(code_hash)(wast)(wasm)(abi) )
FC_REFLECT( eosio::chain_apis::read_only::get_code_hash_results, (account_name)(code_hash) )
FC_REFLECT( eosio::chain_apis::read_only::get_abi_results, (account_name)(abi) )
Expand Down
2 changes: 2 additions & 0 deletions plugins/producer_api_plugin/producer_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void producer_api_plugin::plugin_startup() {
INVOKE_R_V(producer, get_integrity_hash), 201),
CALL(producer, producer, create_snapshot,
INVOKE_R_V(producer, create_snapshot), 201),
CALL(producer, producer, create_acts_snapshot,
INVOKE_R_V(producer, create_acts_snapshot), 201),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class producer_plugin : public appbase::plugin<producer_plugin> {

integrity_hash_information get_integrity_hash() const;
snapshot_information create_snapshot() const;
snapshot_information create_acts_snapshot() const;

signal<void(const chain::producer_confirmation&)> confirmed_block;
private:
Expand Down
42 changes: 42 additions & 0 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace eosio {
static appbase::abstract_plugin& _producer_plugin = app().register_plugin<producer_plugin>();

using namespace eosio::chain;
using namespace eosio::chain_apis;
using namespace eosio::chain::plugin_interface;

namespace {
Expand Down Expand Up @@ -985,6 +986,47 @@ producer_plugin::snapshot_information producer_plugin::create_snapshot() const {
return {head_id, snapshot_path};
}

producer_plugin::snapshot_information producer_plugin::create_acts_snapshot() const {

chain::controller& chain = my->chain_plug->chain();

auto reschedule = fc::make_scoped_exit([this](){
my->schedule_production_loop();
});

if (chain.pending_block_state()) {
// abort the pending block
chain.abort_block();
} else {
reschedule.cancel();
}

auto head_id = chain.head_block_id();
std::string acts_snapshot_path = (my->_snapshots_dir / fc::format_string("acts-snapshot-${id}.txt", fc::mutable_variant_object()("id", head_id))).generic_string();

EOS_ASSERT( !fc::is_regular_file(acts_snapshot_path), snapshot_exists_exception,
"acts-snapshot named ${name} already exists", ("name", acts_snapshot_path));

auto acts_stream = std::ofstream(acts_snapshot_path, (std::ios::out));
acts_stream << "name,liquid,self_staked,other_staked,unstaking,rex_deposit" << std::endl;

const auto& idx = chain.db().get_index<account_sequence_index,by_name>();
auto lower = idx.lower_bound( N(1) );
auto upper = idx.upper_bound( N(zzzzzzzzzzzz) );

for (auto itr = lower; itr != upper; ++itr ){
chain_apis::read_only::get_act_token_result result = my->chain_plug->get_read_only_api().get_act_token( itr->name );
acts_stream << itr->name.to_string() << "," << result.liquid_balance << ","
<< result.self_staked << "," << result.other_staked << ","
<< result.unstaking << "," << result.rex_deposit << std::endl;
}

acts_stream.flush();
acts_stream.close();

return {head_id, acts_snapshot_path};
}

optional<fc::time_point> producer_plugin_impl::calculate_next_block_time(const account_name& producer_name, const block_timestamp_type& current_block_time) const {
chain::controller& chain = chain_plug->chain();
const auto& hbs = chain.head_block_state();
Expand Down
16 changes: 13 additions & 3 deletions scripts/eosio_build_darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
printf "\\tChecking Home Brew installation\\n"
if ! BREW=$( command -v brew )
then
printf "\\tHomebrew must be installed to compile EOS.IO\\n\\n"
printf "\\tHomebrew must be installed to compile EOSIO\\n\\n"
printf "\\tDo you wish to install Home Brew?\\n"
if is_noninteractive; then exec <<< "1"; fi
select yn in "Yes" "No"; do
Expand Down Expand Up @@ -177,13 +177,23 @@
printf "\\n\\tNo required Home Brew dependencies to install.\\n"
fi


printf "\\n\\tChecking clang in CommandLineTools for MacOS.\\n"
which clang | grep CommandLineTools 1> /dev/null
ISCMDCLANG=$?
if [ ${ISCMDCLANG} -ne 0 ]; then
print "\\tPlease use the Apple clang version 11.0.0 at least.\\n"
print "\\tIf installed, please change the PATH to use it\\n"
print "\\tOr download v11.3.1 from: https://developer.apple.com/download/more/. \\n"
printf "\\tExiting now.\\n\\n"
exit 1;
fi

printf "\\n\\tChecking boost library installation.\\n"
BVERSION=$( grep "#define BOOST_VERSION" "/usr/local/include/boost/version.hpp" 2>/dev/null | tail -1 | tr -s ' ' | cut -d\ -f3 )
if [ "${BVERSION}" != "107100" ]; then
if [ ! -z "${BVERSION}" ]; then
printf "\\tFound Boost Version %s.\\n" "${BVERSION}"
printf "\\tEOS.IO requires Boost version 1.71.\\n"
printf "\\tEOSIO requires Boost version 1.71.\\n"
printf "\\tWould you like to uninstall version %s and install Boost version 1.71.\\n" "${BVERSION}"
if is_noninteractive; then exec <<< "1"; fi
select yn in "Yes" "No"; do
Expand Down

0 comments on commit 1ad50c3

Please sign in to comment.