github.com/Blockdaemon/celo-blockchain@v0.0.0-20200129231733-e667f6b08419/contract_comm/epoch_rewards/epoch_rewards.go (about)

     1  // Copyright 2017 The Celo Authors
     2  // This file is part of the celo library.
     3  //
     4  // The celo library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The celo library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the celo library. If not, see <http://www.gnu.org/licenses/>.
    16  package epoch_rewards
    17  
    18  import (
    19  	"math/big"
    20  	"strings"
    21  
    22  	"github.com/ethereum/go-ethereum/accounts/abi"
    23  	"github.com/ethereum/go-ethereum/common"
    24  	"github.com/ethereum/go-ethereum/contract_comm"
    25  	"github.com/ethereum/go-ethereum/core/types"
    26  	"github.com/ethereum/go-ethereum/core/vm"
    27  	"github.com/ethereum/go-ethereum/params"
    28  )
    29  
    30  // This is taken from celo-monorepo/packages/protocol/build/<env>/contracts/Election.json
    31  const epochRewardsABIString string = `[
    32      {
    33        "constant": true,
    34        "inputs": [],
    35        "name": "calculateTargetEpochPaymentAndRewards",
    36        "outputs": [
    37          {
    38            "name": "",
    39            "type": "uint256"
    40          },
    41          {
    42            "name": "",
    43            "type": "uint256"
    44          }
    45        ],
    46        "payable": false,
    47        "stateMutability": "view",
    48        "type": "function"
    49      },
    50      {
    51        "constant": false,
    52        "inputs": [],
    53        "name": "updateTargetVotingYield",
    54        "outputs": [],
    55        "payable": false,
    56        "stateMutability": "nonpayable",
    57        "type": "function"
    58      }
    59  ]
    60  `
    61  
    62  var epochRewardsABI, _ = abi.JSON(strings.NewReader(epochRewardsABIString))
    63  
    64  func UpdateTargetVotingYield(header *types.Header, state vm.StateDB) error {
    65  	_, err := contract_comm.MakeCall(params.EpochRewardsRegistryId, epochRewardsABI, "updateTargetVotingYield", []interface{}{}, nil, params.MaxGasForUpdateTargetVotingYield, common.Big0, header, state, false)
    66  	return err
    67  }
    68  
    69  func CalculateTargetEpochPaymentAndRewards(header *types.Header, state vm.StateDB) (*big.Int, *big.Int, error) {
    70  	var validatorEpochPayment *big.Int
    71  	var totalVoterRewards *big.Int
    72  	_, err := contract_comm.MakeStaticCall(params.EpochRewardsRegistryId, epochRewardsABI, "calculateTargetEpochPaymentAndRewards", []interface{}{}, &[]interface{}{&validatorEpochPayment, &totalVoterRewards}, params.MaxGasForCalculateTargetEpochPaymentAndRewards, header, state)
    73  	if err != nil {
    74  		return nil, nil, err
    75  	}
    76  	return validatorEpochPayment, totalVoterRewards, nil
    77  }