Skip to content

Commit

Permalink
change contract
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Sep 6, 2023
1 parent 2554144 commit 71fcf7c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions e2e/chains/bsc/Dockerfile.bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RUN apk add --d --no-cache ca-certificates npm nodejs bash alpine-sdk expect jq
RUN git clone https://github.com/binance-chain/bsc-genesis-contract.git -b v1.1.9 /root/genesis \
&& cd /root/genesis && npm ci

COPY scripts/contracts/SystemReward.template /root/genesis/contracts/SystemReward.template
COPY scripts/contracts/BSCValidatorSet.template /root/genesis/contracts/BSCValidatorSet.template
COPY scripts/generate-validator.js /root/genesis/generate-validator.js
COPY scripts/genesis-template.template /root/genesis/genesis-template.template
Expand Down
4 changes: 2 additions & 2 deletions e2e/chains/bsc/docker-compose.bsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ services:
context: .
dockerfile: Dockerfile.bsc
args:
GIT_SOURCE: https://github.com/yoshidan/bsc.git
GIT_CHECKOUT_BRANCH: v1.2.10_test
GIT_SOURCE: https://github.com/binance-chain/bsc.git
GIT_CHECKOUT_BRANCH: v1.2.10
image: bsc-geth:docker-local
86 changes: 86 additions & 0 deletions e2e/chains/bsc/scripts/contracts/SystemReward.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
pragma solidity 0.6.4;

import "./System.sol";
import "./lib/Memory.sol";
import "./interface/IParamSubscriber.sol";
import "./interface/ISystemReward.sol";

contract SystemReward is System, IParamSubscriber, ISystemReward {
uint256 public constant MAX_REWARDS = 1e18;

uint public numOperator;
mapping(address => bool) operators;

modifier doInit() {
if (!alreadyInit) {
operators[LIGHT_CLIENT_ADDR] = true;
operators[INCENTIVIZE_ADDR] = true;
numOperator = 2;
alreadyInit = true;
}
_;
}

modifier onlyOperator() {
// start mod
// require(operators[msg.sender],"only operator is allowed to call the method");
// end mod
_;
}

event rewardTo(address indexed to, uint256 amount);
event rewardEmpty();
event receiveDeposit(address indexed from, uint256 amount);
event addOperator(address indexed operator);
event deleteOperator(address indexed operator);
event paramChange(string key, bytes value);

receive() external payable{
if (msg.value>0) {
emit receiveDeposit(msg.sender, msg.value);
}
}

function claimRewards(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns (uint256) {
uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance;
if (actualAmount > MAX_REWARDS) {
actualAmount = MAX_REWARDS;
}
if (actualAmount != 0) {
to.transfer(actualAmount);
emit rewardTo(to, actualAmount);
} else {
emit rewardEmpty();
}
return actualAmount;
}

function isOperator(address addr) external view returns (bool) {
return operators[addr];
}

function updateParam(string calldata key, bytes calldata value) onlyGov external override {
if (Memory.compareStrings(key, "addOperator")) {
bytes memory valueLocal = value;
require(valueLocal.length == 20, "length of value for addOperator should be 20");
address operatorAddr;
assembly {
operatorAddr := mload(add(valueLocal, 20))
}
operators[operatorAddr] = true;
emit addOperator(operatorAddr);
} else if (Memory.compareStrings(key, "deleteOperator")) {
bytes memory valueLocal = value;
require(valueLocal.length == 20, "length of value for deleteOperator should be 20");
address operatorAddr;
assembly {
operatorAddr := mload(add(valueLocal, 20))
}
delete operators[operatorAddr];
emit deleteOperator(operatorAddr);
} else {
require(false, "unknown param");
}
emit paramChange(key, value);
}
}

0 comments on commit 71fcf7c

Please sign in to comment.