Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #56 from EOSIO/release/1.2.x
Browse files Browse the repository at this point in the history
version 1.2.1
  • Loading branch information
b1bart authored Aug 24, 2018
2 parents 7f1aae0 + 160ef93 commit aa965d0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(eosio_contracts VERSION 1.2.0)
project(eosio_contracts VERSION 1.2.1)

set(EOSIO_DEPENDENCY "1.1")
set(EOSIO_WASMSDK_DEPENDENCY "1.1")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# eosio.contracts

## Version : 1.2.0
## Version : 1.2.1

The design of the EOSIO blockchain calls for a number of smart contracts that are run at a privileged permission level in order to support functions such as block producer registration and voting, token staking for CPU and network bandwidth, RAM purchasing, multi-sig, etc. These smart contracts are referred to as the system, token, msig and sudo contracts.

Expand Down
32 changes: 28 additions & 4 deletions eosio.system/abi/eosio.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
{"name":"newname", "type":"account_name"},
{"name":"bid", "type":"asset"}
]
},{
"name": "bidrefund",
"base": "",
"fields": [
{"name":"bidder", "type":"account_name"},
{"name":"newname", "type":"account_name"}
]
},{
"name": "permission_level_weight",
"base": "",
Expand Down Expand Up @@ -410,15 +417,22 @@
{"name":"quote", "type":"connector"}
]
}, {
"name": "namebid_info",
"name": "name_bid",
"base": "",
"fields": [
{"name":"newname", "type":"account_name"},
{"name":"high_bidder", "type":"account_name"},
{"name":"high_bid", "type":"int64"},
{"name":"last_bid_time", "type":"uint64"}
]
}
}, {
"name": "bid_refund",
"base": "",
"fields": [
{"name":"bidder", "type":"account_name"},
{"name":"amount", "type":"asset"}
]
}
],
"actions": [{
"name": "newaccount",
Expand Down Expand Up @@ -496,6 +510,10 @@
"name": "bidname",
"type": "bidname",
"ricardian_contract": ""
},{
"name": "bidrefund",
"type": "bidrefund",
"ricardian_contract": ""
},{
"name": "unregprod",
"type": "unregprod",
Expand Down Expand Up @@ -591,11 +609,17 @@
"key_types" : ["uint64"]
},{
"name": "namebids",
"type": "namebid_info",
"type": "name_bid",
"index_type": "i64",
"key_names" : ["newname"],
"key_types" : ["account_name"]
}
},{
"name": "bidrefunds",
"type": "bid_refund",
"index_type": "i64",
"key_names" : ["bidder"],
"key_types" : ["account_name"]
}
],
"ricardian_clauses": [],
"abi_extensions": []
Expand Down
12 changes: 12 additions & 0 deletions eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ namespace eosiosystem {
uint64_t by_high_bid()const { return static_cast<uint64_t>(-high_bid); }
};

struct bid_refund {
account_name bidder;
asset amount;

auto primary_key() const { return bidder; }
};

typedef eosio::multi_index< N(namebids), name_bid,
indexed_by<N(highbid), const_mem_fun<name_bid, uint64_t, &name_bid::by_high_bid> >
> name_bid_table;

typedef eosio::multi_index< N(bidrefunds), bid_refund> bid_refund_table;

struct eosio_global_state : eosio::blockchain_parameters {
uint64_t free_ram()const { return max_ram_size - total_ram_bytes_reserved; }
Expand Down Expand Up @@ -161,6 +169,7 @@ namespace eosiosystem {
void onblock( block_timestamp timestamp, account_name producer );
// const block_header& header ); /// only parse first 3 fields of block header

void setalimits( account_name act, int64_t ram, int64_t net, int64_t cpu );
// functions defined in delegate_bandwidth.cpp

/**
Expand Down Expand Up @@ -235,6 +244,9 @@ namespace eosiosystem {
void rmvproducer( account_name producer );

void bidname( account_name bidder, account_name newname, asset bid );

void bidrefund( account_name bidder, account_name newname );

private:
// Implementation details:

Expand Down
3 changes: 1 addition & 2 deletions eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ namespace eosiosystem {
set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
}


/**
* The system contract now buys and sells RAM allocations at prevailing market prices.
* This may result in traders buying RAM today in anticipation of potential shortages
Expand Down Expand Up @@ -422,7 +421,7 @@ namespace eosiosystem {
// allow people to get their tokens earlier than the 3 day delay if the unstake happened immediately after many
// consecutive missed blocks.

INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.stake),N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{N(eosio.stake),N(active)},{req->owner,N(active)}},
{ N(eosio.stake), req->owner, req->net_amount + req->cpu_amount, std::string("unstake") } );

refunds_tbl.erase( req );
Expand Down
44 changes: 40 additions & 4 deletions eosio.system/src/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ namespace eosiosystem {
require_auth( _self );
set_privileged( account, ispriv );
}

void system_contract::setalimits( account_name account, int64_t ram, int64_t net, int64_t cpu ) {
require_auth( N(eosio) );
user_resources_table userres( _self, account );
auto ritr = userres.find( account );
eosio_assert( ritr == userres.end(), "only supports unlimited accounts" );
set_resource_limits(account, ram, net, cpu);
}

void system_contract::rmvproducer( account_name producer ) {
require_auth( _self );
Expand Down Expand Up @@ -158,9 +166,27 @@ namespace eosiosystem {
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() } );
bid_refund_table refunds_table(_self, newname);

auto it = refunds_table.find( current->high_bidder );
if ( it != refunds_table.end() ) {
refunds_table.modify( it, 0, [&](auto& r) {
r.amount += asset( current->high_bid, system_token_symbol );
});
} else {
refunds_table.emplace( bidder, [&](auto& r) {
r.bidder = current->high_bidder;
r.amount = asset( current->high_bid, system_token_symbol );
});
}

action a( {N(eosio),N(active)}, N(eosio), N(bidrefund), std::make_tuple( current->high_bidder, newname ) );
transaction t;
t.actions.push_back( std::move(a) );
t.delay_sec = 0;
uint128_t deferred_id = (uint128_t(newname) << 64) | current->high_bidder;
cancel_deferred( deferred_id );
t.send( deferred_id, bidder );

bids.modify( current, bidder, [&]( auto& b ) {
b.high_bidder = bidder;
Expand All @@ -170,6 +196,16 @@ namespace eosiosystem {
}
}

void system_contract::bidrefund( account_name bidder, account_name newname ) {
bid_refund_table refunds_table(_self, newname);
auto it = refunds_table.find( bidder );
eosio_assert( it != refunds_table.end(), "refund not found" );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{N(eosio.names),N(active)},{bidder,N(active)}},
{ N(eosio.names), bidder, asset(it->amount),
std::string("refund bid on name ")+(name{newname}).to_string() } );
refunds_table.erase( it );
}

/**
* Called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
Expand Down Expand Up @@ -224,7 +260,7 @@ 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)(setramrate)(setparams)(setpriv)(rmvproducer)(bidname)
(setram)(setramrate)(setparams)(setpriv)(setalimits)(rmvproducer)(bidname)(bidrefund)
// delegate_bandwidth.cpp
(buyrambytes)(buyram)(sellram)(delegatebw)(undelegatebw)(refund)
// voting.cpp
Expand Down
4 changes: 2 additions & 2 deletions eosio.system/src/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ namespace eosiosystem {
});

if( producer_per_block_pay > 0 ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.bpay),N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{N(eosio.bpay),N(active)},{owner,N(active)}},
{ N(eosio.bpay), owner, asset(producer_per_block_pay), std::string("producer block pay") } );
}
if( producer_per_vote_pay > 0 ) {
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.vpay),N(active)},
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{N(eosio.vpay),N(active)},{owner,N(active)}},
{ N(eosio.vpay), owner, asset(producer_per_vote_pay), std::string("producer vote pay") } );
}
}
Expand Down

0 comments on commit aa965d0

Please sign in to comment.