Permalink
Switch branches/tags
1771-QA 1972-QA 2032 2153-QA 4064 4254-snapshots 4971-enable-stale-production-fix 4986-alternative-fix-2 5674-test-of-free-port 5674-under-min-avail DAWN-551-Contract-Debugging-Merge DAWN-551-Contract-Debugging april-26-workshop ben-demo-docs bft-dpos binaryen-recursion bios-boot-tutorial-block-age2 bitshares-fc-variant-fixes block_summaries bnet2 build-containers-on-commit buildkite-mojave cleos-R cleos-keos cleos-pretty-get-account-cleos-keos cleos-pretty-get-account cleos_warn_on_nonwasm cmake_boost_dep_cleanup constitution contextfree contract-refactor contracts-use-new-dbapi dan-slim dan-slim2 dan2 dawn-2.x dawn-617-genesis-claim dawn-690-gh#1844-enable-tests deferred-transactions deferred_transaction_fix develop dhaneshvb-malicious-contract diffie-hellman-key-exchange-545 docker-eosiocpp-fix docker-mongodb docs-112318 docs-pull-3991 doxygen-cpp-sdk ecc-r1 eos-noon-network eos-noon eos-repo-contract-refactor eos2 eosbios-gcc-compatibility eosio.system exchange2 feature/backport-docker-eosiocpp-fix feature/binary_release feature/bump-version-to-1.1.6 feature/bump-version-to-1.2.1 feature/bump-version-to-1.2.4 feature/bump-version-to-1.5.0-rc2 feature/logging-changes-for-testing feature/logging-changes feature/port-6222 feature/revert-6222 feature/1.0.8-security-omnibus feature/5057-subjectively-fail-ambiguous-dtrx-case final_keosd_unix_socket_changes fix_unused_lambda_captures fix/wasm_call_depth_limit fork-db-refactor gh#3612-bnet history-plugin-fix identity issue1760 issue2898 issue3187 jit-schedule-512 json-forever-loop-fix june-28-workshop keosd_daemon long-running-test-branch master merge/1.5.0-to-develop metric metric2 mongo-filter mongo-shard moxygen multisig native-contract-debugging network-buffer networkv2 new-checktime-injection new-ci-image-testing p2p-always-send p2p-connection-refactor p2p-issue-3017-fix paul port-1.1.4 producer-txns read-mode-irreversible regularize-replay-logging release/1.0.x release/1.1.x release/1.2.x release/1.3.x release/1.4.x release/1.5.x remove-docker-nodeos-wallet-plugin-settings replay-irreversible-mode sdk sigabrt-net-plugin sim skip_skip_trx_checks slim snapshot-plugin staging superhero-01-25 system-contract-deferred-unstaking system-contract-upgrade system-test-fix-draft system systemcontract taokayan-abiarray token-refactor trivial_wallet_dir_lock txn_gen_modified txn_test_plugin_wasm_mt update-block-num vote-max-transaction-delay-2 vote-max-transaction-delay wasm32
Nothing to show
Find file Copy path
199 lines (167 sloc) 7.67 KB
#include "eosio.system.hpp"
#include <eosiolib/dispatcher.hpp>
#include "producer_pay.cpp"
#include "delegate_bandwidth.cpp"
#include "voting.cpp"
#include "exchange_state.cpp"
namespace eosiosystem {
system_contract::system_contract( account_name s )
:native(s),
_voters(_self,_self),
_producers(_self,_self),
_global(_self,_self),
_rammarket(_self,_self)
{
//print( "construct system\n" );
_gstate = _global.exists() ? _global.get() : get_default_parameters();
auto itr = _rammarket.find(S(4,RAMCORE));
if( itr == _rammarket.end() ) {
auto system_token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount;
if( system_token_supply > 0 ) {
itr = _rammarket.emplace( _self, [&]( auto& m ) {
m.supply.amount = 100000000000000ll;
m.supply.symbol = S(4,RAMCORE);
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 = CORE_SYMBOL;
});
}
} else {
//print( "ram market already created" );
}
}
eosio_global_state system_contract::get_default_parameters() {
eosio_global_state dp;
get_blockchain_parameters(dp);
return dp;
}
system_contract::~system_contract() {
//print( "destruct system\n" );
_global.set( _gstate, _self );
//eosio_exit(0);
}
void system_contract::setram( uint64_t max_ram_size ) {
require_auth( _self );
eosio_assert( _gstate.max_ram_size < max_ram_size, "ram may only be increased" ); /// decreasing ram might result market maker issues
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,RAMCORE));
/**
* 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 );
}
void system_contract::setparams( const eosio::blockchain_parameters& params ) {
require_auth( N(eosio) );
(eosio::blockchain_parameters&)(_gstate) = params;
eosio_assert( 3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3" );
set_blockchain_parameters( params );
}
void system_contract::setpriv( account_name account, uint8_t ispriv ) {
require_auth( _self );
set_privileged( account, ispriv );
}
void system_contract::rmvproducer( account_name producer ) {
require_auth( _self );
auto prod = _producers.find( producer );
eosio_assert( prod != _producers.end(), "producer not found" );
_producers.modify( prod, 0, [&](auto& p) {
p.deactivate();
});
}
void system_contract::bidname( account_name bidder, account_name newname, asset bid ) {
require_auth( bidder );
eosio_assert( eosio::name_suffix(newname) == newname, "you can only bid on top-level suffix" );
eosio_assert( newname != 0, "the empty name is not a valid account name to bid on" );
eosio_assert( (newname & 0xFull) == 0, "13 character names are not valid account names to bid on" );
eosio_assert( (newname & 0x1F0ull) == 0, "accounts with 12 character names and no dots can be created without bidding required" );
eosio_assert( !is_account( newname ), "account already exists" );
eosio_assert( bid.symbol == asset().symbol, "asset must be system token" );
eosio_assert( bid.amount > 0, "insufficient bid" );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {bidder,N(active)},
{ bidder, N(eosio.names), bid, std::string("bid name ")+(name{newname}).to_string() } );
name_bid_table bids(_self,_self);
print( name{bidder}, " bid ", bid, " on ", name{newname}, "\n" );
auto current = bids.find( newname );
if( current == bids.end() ) {
bids.emplace( bidder, [&]( auto& b ) {
b.newname = newname;
b.high_bidder = bidder;
b.high_bid = bid.amount;
b.last_bid_time = current_time();
});
} else {
eosio_assert( current->high_bid > 0, "this auction has already closed" );
eosio_assert( bid.amount - current->high_bid > (current->high_bid / 10), "must increase bid by 10%" );
eosio_assert( current->high_bidder != bidder, "account is already highest bidder" );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.names),N(active)},
{ N(eosio.names), current->high_bidder, asset(current->high_bid),
std::string("refund bid on name ")+(name{newname}).to_string() } );
bids.modify( current, bidder, [&]( auto& b ) {
b.high_bidder = bidder;
b.high_bid = bid.amount;
b.last_bid_time = current_time();
});
}
}
/**
* Called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
*
* Account names containing '.' symbols must have a suffix equal to the name of the creator.
* This allows users who buy a premium name (shorter than 12 characters with no dots) to be the only ones
* who can create accounts with the creator's name as a suffix.
*
*/
void native::newaccount( account_name creator,
account_name newact
/* no need to parse authorities
const authority& owner,
const authority& active*/ ) {
if( creator != _self ) {
auto tmp = newact >> 4;
bool has_dot = false;
for( uint32_t i = 0; i < 12; ++i ) {
has_dot |= !(tmp & 0x1f);
tmp >>= 5;
}
if( has_dot ) { // or is less than 12 characters
auto suffix = eosio::name_suffix(newact);
if( suffix == newact ) {
name_bid_table bids(_self,_self);
auto current = bids.find( newact );
eosio_assert( current != bids.end(), "no active bid for name" );
eosio_assert( current->high_bidder == creator, "only highest bidder can claim" );
eosio_assert( current->high_bid < 0, "auction for name is not closed yet" );
bids.erase( current );
} else {
eosio_assert( creator == suffix, "only suffix may create this account" );
}
}
}
user_resources_table userres( _self, newact);
userres.emplace( newact, [&]( auto& res ) {
res.owner = newact;
});
set_resource_limits( newact, 0, 0, 0 );
}
} /// eosio.system
EOSIO_ABI( eosiosystem::system_contract,
// native.hpp (newaccount definition is actually in eosio.system.cpp)
(newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(canceldelay)(onerror)
// eosio.system.cpp
(setram)(setparams)(setpriv)(rmvproducer)(bidname)
// delegate_bandwidth.cpp
(buyrambytes)(buyram)(sellram)(delegatebw)(undelegatebw)(refund)
// voting.cpp
(regproducer)(unregprod)(voteproducer)(regproxy)
// producer_pay.cpp
(onblock)(claimrewards)
)