eosnetworkfoundation / eos-system-contracts

Other
28 stars 20 forks source link

Implement STATIC methods for `rex_system_initialized` & `rex_available` #130

Closed DenisCarriere closed 4 months ago

DenisCarriere commented 5 months ago

Methods to expose if REX is available or not.

Needed for contracts that want to implement donatetorex action which require REX to be active.

static bool rex_system_initialized() {
   eosiosystem::rex_pool_table _rexpool( "eosio"_n, "eosio"_n.value );
   return _rexpool.begin() != _rexpool.end();
}

static bool rex_available() {
   eosiosystem::rex_pool_table _rexpool( "eosio"_n, "eosio"_n.value );
   return rex_system_initialized() && _rexpool.begin()->total_rex.amount > 0;
}

Example code

if (rex_available()) {
  eosiosystem::system_contract::donatetorex_action donatetorex( "eosio"_n, { get_self(), "active"_n });
  donatetorex.send(get_self(), quantity, memo);
}
DenisCarriere commented 4 months ago

Implemented via https://github.com/AntelopeIO/reference-contracts/pull/70