-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolved conflict num of blocks to produce for test
- Loading branch information
Showing
16 changed files
with
522 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_contract(eosio.bpay eosio.bpay ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.bpay.cpp) | ||
|
||
target_include_directories(eosio.bpay PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../eosio.system/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../eosio.token/include) | ||
|
||
set_target_properties(eosio.bpay | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | ||
|
||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/ricardian/eosio.bpay.contracts.md.in ${CMAKE_CURRENT_BINARY_DIR}/ricardian/eosio.bpay.contracts.md @ONLY ) | ||
|
||
target_compile_options( eosio.bpay PUBLIC -R${CMAKE_CURRENT_SOURCE_DIR}/ricardian -R${CMAKE_CURRENT_BINARY_DIR}/ricardian ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <eosio/eosio.hpp> | ||
#include <eosio.system/eosio.system.hpp> | ||
#include <eosio.token/eosio.token.hpp> | ||
|
||
using namespace std; | ||
|
||
namespace eosio { | ||
/** | ||
* The `eosio.bpay` contract handles system bpay distribution. | ||
*/ | ||
class [[eosio::contract("eosio.bpay")]] bpay : public contract { | ||
public: | ||
using contract::contract; | ||
|
||
/** | ||
* ## TABLE `rewards` | ||
* | ||
* @param owner - block producer owner account | ||
* @param quantity - reward quantity in EOS | ||
* | ||
* ### example | ||
* | ||
* ```json | ||
* [ | ||
* { | ||
* "owner": "alice", | ||
* "quantity": "8.800 EOS" | ||
* } | ||
* ] | ||
* ``` | ||
*/ | ||
struct [[eosio::table("rewards")]] rewards_row { | ||
name owner; | ||
asset quantity; | ||
|
||
uint64_t primary_key() const { return owner.value; } | ||
}; | ||
typedef eosio::multi_index< "rewards"_n, rewards_row > rewards_table; | ||
|
||
/** | ||
* Claim rewards for a block producer. | ||
* | ||
* @param owner - block producer owner account | ||
*/ | ||
[[eosio::action]] | ||
void claimrewards( const name owner); | ||
|
||
[[eosio::on_notify("eosio.token::transfer")]] | ||
void on_transfer( const name from, const name to, const asset quantity, const string memo ); | ||
|
||
private: | ||
}; | ||
} /// namespace eosio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1 class="contract">claimrewards</h1> | ||
|
||
--- | ||
spec_version: "0.2.0" | ||
title: Claim Rewards | ||
summary: '{{nowrap owner}} claims block production rewards' | ||
icon: @ICON_BASE_URL@/@MULTISIG_ICON_URI@ | ||
--- | ||
|
||
{{owner}} claims block production rewards accumulated through network fees. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <eosio.bpay/eosio.bpay.hpp> | ||
|
||
namespace eosio { | ||
|
||
void bpay::claimrewards( const name owner ) { | ||
require_auth( owner ); | ||
|
||
rewards_table _rewards( get_self(), get_self().value ); | ||
|
||
const auto& row = _rewards.get( owner.value, "no rewards to claim" ); | ||
|
||
eosio::token::transfer_action transfer( "eosio.token"_n, { get_self(), "active"_n }); | ||
transfer.send( get_self(), owner, row.quantity, "producer block pay" ); | ||
|
||
_rewards.erase(row); | ||
} | ||
|
||
void bpay::on_transfer( const name from, const name to, const asset quantity, const string memo ) { | ||
if (from == get_self() || to != get_self()) { | ||
return; | ||
} | ||
|
||
// ignore eosio system incoming transfers (caused by bpay income transfers eosio => eosio.bpay => producer) | ||
if ( from == "eosio"_n) return; | ||
|
||
symbol system_symbol = eosiosystem::system_contract::get_core_symbol(); | ||
|
||
check( quantity.symbol == system_symbol, "only core token allowed" ); | ||
|
||
rewards_table _rewards( get_self(), get_self().value ); | ||
eosiosystem::producers_table _producers( "eosio"_n, "eosio"_n.value ); | ||
|
||
eosiosystem::global_state_singleton _global("eosio"_n, "eosio"_n.value); | ||
check( _global.exists(), "global state does not exist"); | ||
uint16_t producer_count = _global.get().last_producer_schedule_size; | ||
|
||
asset reward = quantity / producer_count; | ||
|
||
// get producer with the most votes | ||
// using `by_votes` secondary index | ||
auto idx = _producers.get_index<"prototalvote"_n>(); | ||
auto prod = idx.begin(); | ||
|
||
// get top n producers by vote, excluding inactive | ||
std::vector<name> top_producers; | ||
while (true) { | ||
if (prod == idx.end()) break; | ||
if (prod->is_active == false) continue; | ||
|
||
top_producers.push_back(prod->owner); | ||
|
||
if (top_producers.size() == producer_count) break; | ||
|
||
prod++; | ||
} | ||
|
||
// distribute rewards to top producers | ||
for (auto producer : top_producers) { | ||
auto row = _rewards.find( producer.value ); | ||
if (row == _rewards.end()) { | ||
_rewards.emplace( get_self(), [&](auto& row) { | ||
row.owner = producer; | ||
row.quantity = reward; | ||
}); | ||
} else { | ||
_rewards.modify(row, get_self(), [&](auto& row) { | ||
row.quantity += reward; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
} /// namespace eosio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.