diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index 42022efd05fac57ef24e84ad1ebc0df5a6c45cb2..655a4c7ff86b9aad42ce966fe2c6e0777eec6d4f 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace eosiosystem { @@ -21,12 +22,15 @@ namespace eosiosystem { static const account_name system_account = SystemAccount; typedef eosio::generic_currency< eosio::token > currency; - struct total_bandwidth { + struct total_resources { account_name owner; typename currency::token_type total_net_weight; typename currency::token_type total_cpu_weight; + uint32_t total_ram = 0; uint64_t primary_key()const { return owner; } + + EOSLIB_SERIALIZE( total_resources, (owner)(total_net_weight)(total_cpu_weight)(total_ram) ); }; @@ -50,10 +54,15 @@ namespace eosiosystem { uint64_t primary_key()const { return to; } + + EOSLIB_SERIALIZE( delegated_bandwidth, (from)(to)(net_weight)(cpu_weight) + (start_pending_net_withdraw)(pending_net_withdraw)(deferred_net_withdraw_handler) + (start_pending_cpu_withdraw)(pending_cpu_withdraw)(deferred_cpu_withdraw_handler) ); + }; - typedef eosio::multi_index< N(totalband), total_bandwidth > total_bandwidth_index_type; + typedef eosio::multi_index< N(totalband), total_resources> total_resources_index_type; typedef eosio::multi_index< N(delband), delegated_bandwidth> del_bandwidth_index_type; @@ -80,7 +89,7 @@ namespace eosiosystem { typename currency::token_type stake_quantity; - EOSLIB_SERIALIZE( delnetbw, (delegator)(receiver)(stake_quantity) ) + EOSLIB_SERIALIZE( delnetbw, (from)(receiver)(stake_quantity) ) }; ACTION( SystemAccount, undelnetbw ) { @@ -105,14 +114,15 @@ namespace eosiosystem { require_auth( del.from ); del_bandwidth_index_type del_index( SystemAccount, del.from ); - total_bandwidth_index_type total_index( SystemAccount, del.to ); - // require_account( receiver ); + total_resources_index_type total_index( SystemAccount, del.receiver ); + + //eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" ); - auto itr = del_index.find( del.to ); - if( itr == del_index.end() ) { + auto itr = del_index.find( del.receiver); + if( itr != nullptr ) { del_index.emplace( del.from, [&]( auto& dbo ){ dbo.from = del.from; - dbo.to = del.to; + dbo.to = del.receiver; dbo.net_weight = del.stake_quantity; }); } @@ -122,10 +132,10 @@ namespace eosiosystem { }); } - auto tot_itr = total_index.find( del.to ); - if( tot_itr == total_index.end() ) { - total_index.emplace( del.from, [&]( auto& tot ) { - tot.owner = del.to; + auto tot_itr = total_index.find( del.receiver ); + if( tot_itr == nullptr ) { + tot_itr = &total_index.emplace( del.from, [&]( auto& tot ) { + tot.owner = del.receiver; tot.total_net_weight += del.stake_quantity; }); } else { @@ -134,6 +144,8 @@ namespace eosiosystem { }); } + set_resource_limits( tot_itr->owner, tot_itr->total_ram, tot_itr->total_net_weight.quantity, tot_itr->total_cpu_weight.quantity, 0 ); + currency::inline_transfer( del.from, SystemAccount, del.stake_quantity, "stake bandwidth" ); } // delnetbw @@ -150,7 +162,7 @@ namespace eosiosystem { static void apply( account_name code, action_name act ) { - if( !eosio::dispatch( code, act) ) { + if( !eosio::dispatch( code, act) ) { if ( !eosio::dispatch( code, act ) ) { eosio::print("Unexpected action: ", eosio::name(act), "\n"); eosio_assert( false, "received unexpected action"); diff --git a/contracts/eosiolib/multi_index.hpp b/contracts/eosiolib/multi_index.hpp index 6cfa1e253e98de0ebf04c094847938284397ec87..f6098cba5673c4882d68322927b642d68fb403f0 100644 --- a/contracts/eosiolib/multi_index.hpp +++ b/contracts/eosiolib/multi_index.hpp @@ -436,7 +436,6 @@ class multi_index auto secondary_keys = boost::hana::transform( _indicies, [&]( auto& idx ) { return idx.extract_secondary_key( obj ); }); - boost::hana::at_c<0>(secondary_keys); auto mutableobj = const_cast(obj); updater( mutableobj ); diff --git a/contracts/eosiolib/privileged.h b/contracts/eosiolib/privileged.h new file mode 100644 index 0000000000000000000000000000000000000000..990da41c81a76fc68594f3cbbd659387454adf62 --- /dev/null +++ b/contracts/eosiolib/privileged.h @@ -0,0 +1,24 @@ +#pragma once + +extern "C" { + + /** + * @defgroup privilegedapi Privileged API + * @ingroup systemapi + * @brief Defines an API for accessing configuration of the chain that can only be done by privileged accounts + */ + + /** + * @defgroup privilegedcapi Privileged C API + * @ingroup privilegedapi + * @brief Define C Privileged API + * + * @{ + */ + + void set_resource_limits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight, int64_t ignored); + + void set_active_producers( char *producer_data, size_t producer_data_size ); + + ///@ } privilegedcapi +} diff --git a/contracts/eosiolib/system.h b/contracts/eosiolib/system.h index b3d72b7d004dd7cf020a3ef29b796b153ef3abd1..dca3af7f30cfb1e4042d931ff0180a72a03d6db8 100644 --- a/contracts/eosiolib/system.h +++ b/contracts/eosiolib/system.h @@ -39,25 +39,6 @@ extern "C" { time now(); ///@ } systemcapi - /** - * @defgroup privilegedapi Privileged API - * @ingroup systemapi - * @brief Defines an API for accessing configuration of the chain that can only be done by privileged accounts - */ - - /** - * @defgroup privilegedcapi Privileged C API - * @ingroup privilegedapi - * @brief Define C Privileged API - * - * @{ - */ - - void set_resource_limits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight, int64_t ignored); - - void set_active_producers( char *producer_data, size_t producer_data_size ); - - ///@ } privilegedcapi } diff --git a/contracts/test.system/test.system.cpp b/contracts/test.system/test.system.cpp index e03b83cfeb112c93544183fa61b38ba4f6abd104..488f1919c921593857910295bc0f512aece31d9b 100644 --- a/contracts/test.system/test.system.cpp +++ b/contracts/test.system/test.system.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace eosio;