diff --git a/contracts/eosio.system/CMakeLists.txt b/contracts/eosio.system/CMakeLists.txt index eb4ff749f77fe230351554f82615434673f1114b..5da2df78f4fe404aeb7b8396494067bc61db630f 100644 --- a/contracts/eosio.system/CMakeLists.txt +++ b/contracts/eosio.system/CMakeLists.txt @@ -3,6 +3,6 @@ configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) add_wast_executable(TARGET eosio.system INCLUDE_FOLDERS ${STANDARD_INCLUDE_FOLDERS} - LIBRARIES libc++ libc eosiolib eosio.token + LIBRARIES libc++ libc eosiolib eosio.token hdddeposit DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index 7c4b223035529229a0bfb89565f57d9c6a9bd1b0..51b9164b209f38bf51cf3782a39d4730cd92029d 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -320,7 +320,8 @@ {"name":"seq_num", "type":"uint16"}, {"name":"out_votes", "type":"int64"}, {"name":"deposit_votes", "type":"int64"}, - {"name":"unpaid_base_cnt", "type":"uint32"} + {"name":"unpaid_base_cnt", "type":"uint32"}, + {"name":"shadow", "type":"account_name"} ] },{ "name": "master_sn_info", @@ -371,6 +372,7 @@ "base": "", "fields": [ {"name":"producer", "type":"account_name"}, + {"name":"shadow", "type":"account_name"}, {"name":"seq", "type":"uint16"}, {"name":"level", "type":"uint8"} ] @@ -406,6 +408,12 @@ {"name":"proxy", "type":"account_name"}, {"name":"producers", "type":"account_name[]"} ] + },{ + "name": "changevotes", + "base": "", + "fields": [ + {"name":"voter_name", "type":"account_name"} + ] },{ "name": "voter_info", "base": "", @@ -607,6 +615,10 @@ "name": "voteproducer", "type": "voteproducer", "ricardian_contract": "" + },{ + "name": "changevotes", + "type": "changevotes", + "ricardian_contract": "" },{ "name": "claimrewards", "type": "claimrewards", diff --git a/contracts/eosio.system/eosio.system.cpp b/contracts/eosio.system/eosio.system.cpp index 38c8eb3b19b3d23d1a9a424d13e7eae591f52fd3..a48b4da16fe5f4829322f3b2c544d16dcfad1723 100644 --- a/contracts/eosio.system/eosio.system.cpp +++ b/contracts/eosio.system/eosio.system.cpp @@ -209,7 +209,7 @@ EOSIO_ABI( eosiosystem::system_contract, // delegate_bandwidth.cpp (buyrambytes)(buyram)(sellram)(delegatebw)(undelegatebw)(refund) // voting.cpp - (regproducer)(unregprod)(voteproducer)(regproxy)(clsprods2)(seqproducer)(testnewelec) + (regproducer)(unregprod)(voteproducer)(changevotes)(regproxy)(clsprods2)(seqproducer)(testnewelec) // producer_pay.cpp (onblock)(claimrewards)(rewardprods) ) diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index 3f7267d887bf9dc74d9b61a9bad4405fca92f8c0..a02691a20a88e6d51ea68e4ca3a65dd233da7d69 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -104,9 +104,10 @@ namespace eosiosystem { int64_t out_votes = 0; int64_t deposit_votes = 0; uint32_t unpaid_base_cnt = 0; + account_name shadow = 0; uint64_t primary_key()const { return owner; } - EOSLIB_SERIALIZE( producer_info_ext, (owner)(seq_num)(out_votes)(deposit_votes)(unpaid_base_cnt)) + EOSLIB_SERIALIZE( producer_info_ext, (owner)(seq_num)(out_votes)(deposit_votes)(unpaid_base_cnt)(shadow)) }; @@ -309,11 +310,13 @@ namespace eosiosystem { //##YTA-Change start: void clsprods2(); - void seqproducer( const account_name producer, uint16_t seq , uint8_t level ); + void seqproducer( const account_name producer, const account_name shadow, uint16_t seq , uint8_t level ); void tmpvotennn( const account_name producer, int64_t tickets ); - void testnewelec(); + void testnewelec(); + + void changevotes( const account_name voter_name ); //##YTA-Change end: void setram( uint64_t max_ram_size ); @@ -367,6 +370,19 @@ namespace eosiosystem { void propagate_weight_change( const voter_info& voter ); }; + bool isActiveVoter( account_name owner ) { + voters_table voters(N(eosio), N(eosio)); + auto voter = voters.find(owner); + if( voter == voters.end() ) { + return false; + } + if( voter->producers.size() == 0 ) { + return false; + } + + return true; + } + uint16_t getProducerSeq(account_name producer){ producers_ext_table _producer_ext(N(eosio), N(eosio)); auto prod = _producer_ext.find(producer); diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index 3b367cdf4861c5978d8c2548e7019097ea56f1ef..b01042a7f776ee5d19d8e90f6f38c3b748ad9a56 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -14,11 +14,13 @@ #include #include #include +#include #include #include const uint64_t useconds_per_day_v = 24 * 3600 * uint64_t(1000000); +const account_name hdd_deposit_account = N(hdddeposit12); namespace eosiosystem { using eosio::indexed_by; @@ -209,7 +211,7 @@ namespace eosiosystem { }); } - void system_contract::seqproducer( const account_name producer, uint16_t seq , uint8_t level ) { + void system_contract::seqproducer( const account_name producer, const account_name shadow, uint16_t seq , uint8_t level ) { require_auth( _self ); //const auto& prod = _producers.get( producer, "producer not found" ); @@ -224,13 +226,15 @@ namespace eosiosystem { if (it == _producersext.end()) { _producersext.emplace(_self, [&](auto &row) { row.owner = producer; - row.seq_num = seq; + row.seq_num = seq; + row.shadow = shadow; }); add_producer_seq(producer, seq, level); } else { uint16_t old_seq = it->seq_num; _producersext.modify(it, _self, [&](auto &row) { row.seq_num = seq; + row.shadow = shadow; }); rm_producer_seq(producer, old_seq); add_producer_seq(producer, seq, level); @@ -377,6 +381,11 @@ namespace eosiosystem { void system_contract::change_producer_seq_info( const account_name producer, const eosio::public_key& producer_key, bool isactive, bool seturl, const std::string& url) { + if(!isactive) { + delproducer(producer); + return; + } + all_prods_singleton _all_prods(_self, _self); all_prods_level _all_prods_state; if (_all_prods.exists()) { @@ -855,6 +864,19 @@ namespace eosiosystem { update_votes( voter_name, proxy, producers, true ); } +//##YTA-Change start: + void system_contract::changevotes( const account_name voter_name ) { + require_auth( voter_name ); + auto from_voter = _voters.find(voter_name); + if( from_voter == _voters.end() ) { + return; + } + if( from_voter->producers.size() || from_voter->proxy ) { + update_votes( voter_name, from_voter->proxy, from_voter->producers, false ); + } + } +//##YTA-Change end: + void system_contract::update_votes( const account_name voter_name, const account_name proxy, const std::vector& producers, bool voting ) { //validate input if ( proxy ) { @@ -889,6 +911,7 @@ namespace eosiosystem { } auto new_vote_weight = stake2vote( voter->staked ); + new_vote_weight += hdddeposit(hdd_deposit_account).get_deposit(voter_name).amount; if( voter->is_proxy ) { new_vote_weight += voter->proxied_vote_weight; } diff --git a/contracts/hdddeposit/hdddeposit.cpp b/contracts/hdddeposit/hdddeposit.cpp index 5146570a344646a619382506f4ffd4184904795f..68b1914bf675fc6aaa4ad82d78ef762f0e075aa1 100644 --- a/contracts/hdddeposit/hdddeposit.cpp +++ b/contracts/hdddeposit/hdddeposit.cpp @@ -63,6 +63,13 @@ void hdddeposit::paydeposit(account_name user, uint64_t minerid, asset quant) { a.dep_total += quant; }); } + + if( eosiosystem::isActiveVoter(user) ) { + action( + permission_level{user, active_permission}, + system_account, N(changevotes), + std::make_tuple(user)).send(); + } } void hdddeposit::undeposit(name user, uint64_t minerid, asset quant) { @@ -87,6 +94,14 @@ void hdddeposit::undeposit(name user, uint64_t minerid, asset quant) { _deposit.modify( acc, 0, [&]( auto& a ) { a.deposit.amount -= quant.amount; }); + + if( eosiosystem::isActiveVoter(user) ) { + action( + permission_level{user, active_permission}, + system_account, N(changevotes), + std::make_tuple(user)).send(); + } + } void hdddeposit::payforfeit(name user, uint64_t minerid, asset quant, uint8_t acc_type, name caller) { @@ -124,6 +139,14 @@ void hdddeposit::payforfeit(name user, uint64_t minerid, asset quant, uint8_t ac token_account, N(transfer), std::make_tuple(user, hdd_deposit_account, quant, std::string("draw forfeit"))) .send(); + + if( eosiosystem::isActiveVoter(user) ) { + action( + permission_level{user, active_permission}, + system_account, N(changevotes), + std::make_tuple(user)).send(); + } + } void hdddeposit::delminer(uint64_t minerid) { @@ -163,6 +186,9 @@ void hdddeposit::setrate(int64_t rate) { void hdddeposit::drawforfeit(name user, uint8_t acc_type, name caller) { + ((void)user); + ((void)acc_type); + ((void)caller); /* if(acc_type == 2) { eosio_assert(is_account(caller), "caller not a account."); @@ -191,6 +217,10 @@ void hdddeposit::drawforfeit(name user, uint8_t acc_type, name caller) { } void hdddeposit::cutvote(name user, uint8_t acc_type, name caller) { + ((void)user); + ((void)acc_type); + ((void)caller); + /* if(acc_type == 2) {