eosio.system.cpp 2.7 KB
Newer Older
1 2
#include "eosio.system.hpp"
#include <eosiolib/dispatcher.hpp>
3

4 5 6
#include "delegate_bandwidth.cpp"
#include "producer_pay.cpp"
#include "voting.cpp"
D
Daniel Larimer 已提交
7
#include "exchange_state.cpp"
8

D
Daniel Larimer 已提交
9

10
namespace eosiosystem {
D
Daniel Larimer 已提交
11

12 13 14 15
   system_contract::system_contract( account_name s )
   :native(s),
    _voters(_self,_self),
    _producers(_self,_self),
D
Daniel Larimer 已提交
16 17
    _global(_self,_self),
    _rammarket(_self,_self)
18
   {
19
      //print( "construct system\n" );
20
      _gstate = _global.exists() ? _global.get() : get_default_parameters();
D
Daniel Larimer 已提交
21 22 23 24 25

      auto itr = _rammarket.find(S(4,RAMEOS));

      if( itr == _rammarket.end() ) {
         auto system_token_supply   = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount;
26 27 28 29 30 31 32 33 34 35
         if( system_token_supply > 0 ) {
            itr = _rammarket.emplace( _self, [&]( auto& m ) {
               m.supply.amount = 100000000000000ll;
               m.supply.symbol = S(4,RAMEOS);
               m.base.balance.amount = int64_t(_gstate.free_ram());
               m.base.balance.symbol = S(0,RAM);
               m.quote.balance.amount = system_token_supply / 1000;
               m.quote.balance.symbol = S(4,EOS);
            });
         }
D
Daniel Larimer 已提交
36
      } else {
37
         //print( "ram market already created" );
D
Daniel Larimer 已提交
38
      }
39 40 41 42 43 44 45 46 47 48
   }

   eosio_global_state system_contract::get_default_parameters() {
      eosio_global_state dp;
      get_blockchain_parameters(dp);
      return dp;
   }


   system_contract::~system_contract() {
49
      //print( "destruct system\n" );
50
      _global.set( _gstate, _self );
51
      //eosio_exit(0);
52 53
   }

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
   void system_contract::setram( uint64_t max_ram_size ) {
      require_auth( _self );

      eosio_assert( max_ram_size < 1024ll*1024*1024*1024*1024, "ram size is unrealistic" );
      eosio_assert( max_ram_size > _gstate.total_ram_bytes_reserved, "attempt to set max below reserved" );

      auto delta = int64_t(max_ram_size) - int64_t(_gstate.max_ram_size);
      auto itr = _rammarket.find(S(4,RAMEOS));

      /**
       *  Increase or decrease the amount of ram for sale based upon the change in max
       *  ram size.
       */
      _rammarket.modify( itr, 0, [&]( auto& m ) {
         m.base.balance.amount += delta;
      });

      _gstate.max_ram_size = max_ram_size;
      _global.set( _gstate, _self );
   }

75 76
} /// eosio.system
 
D
Daniel Larimer 已提交
77

78
EOSIO_ABI( eosiosystem::system_contract,
79
     (setram)
D
Daniel Larimer 已提交
80 81
     // delegate_bandwith.cpp
     (delegatebw)(undelegatebw)(refund)
82
     (buyram)(buyrambytes)(sellram)
D
Daniel Larimer 已提交
83 84
     // voting.cpp
     // producer_pay.cpp
85
     (regproxy)(regproducer)(unregprod)(voteproducer)
D
Daniel Larimer 已提交
86 87 88 89 90
     (claimrewards)
     // native.hpp
     //XXX
     (onblock)
     (newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(postrecovery)(passrecovery)(vetorecovery)(onerror)(canceldelay)
91
)