Fix syntax errors in DioneDispute smart-contract

This commit is contained in:
ChronosX88 2021-03-04 21:22:05 +03:00
parent ebc29c2078
commit 06122ccd82
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
4 changed files with 24 additions and 34 deletions

View File

@ -10,13 +10,13 @@ contract DioneDispute {
struct Dispute {
bytes32 dhash; // id of dispute - keccak256(_miner,_requestId,_timestamp)
int256 sum; // vote measure (for/against this dispute)
uint256 sum; // vote measure (for/against this dispute)
bool finished; // dispute was finished (closed) or not
bool disputeResult; // true - dispute had basis, false - dispute was false
address miner; // the miner against whom the dispute
address disputeInitiator; // the miner who started the dispute
uint256 timestamp; // dispute creation timestamp
mapping(address => bool) voted; // map of miners who vote for/against
address[] voted; // map of miners who vote for/against
}
mapping(bytes32 => Dispute) disputes;
@ -30,19 +30,16 @@ contract DioneDispute {
}
function beginDispute(address miner, uint256 requestID) public {
require(!disputes[dhash], "dispute already exists");
bytes32 dhash = keccak256(miner, requestID, now);
Dispute dispute = Dispute(
{
dhash: dhash,
sum: 0,
finished: false,
disputeResult: true,
miner: miner,
timesyamp: now,
disputeInitiator: msg.sender,
}
);
bytes32 dhash = keccak256(abi.encodePacked(miner, requestID, now));
require(disputes[dhash].dhash.length != 0, "dispute already exists");
Dispute storage dispute = disputes[dhash];
dispute.dhash = dhash;
dispute.sum = 0;
dispute.finished = false;
dispute.disputeResult = false;
dispute.miner = miner;
dispute.timestamp = now;
dispute.disputeInitiator = msg.sender;
disputes[dhash] = dispute;
@ -50,32 +47,33 @@ contract DioneDispute {
}
function vote(bytes32 dhash, bool voteStatus) public {
require(disputes[dhash], "dispute doesn't exist");
require(disputes[dhash].dhash.length == 0, "dispute doesn't exist");
Dispute storage dispute = disputes[dhash];
require(dispute.finished == false, "dispute already finished");
require(dioneStaking.isMiner(msg.sender), "caller isn't dione miner");
int256 stake = dioneStaking.minerStake(msg.sender);
uint256 stake = dioneStaking.minerStake(msg.sender);
if (voteStatus) {
dispute.sum.sub(stake);
} else {
dispute.sum.add(stake);
}
dispute.voted[msg.sender] = voteStatus;
dispute.voted.push(msg.sender);
emit NewVote(dhash, msg.sender);
}
function finishDispute(bytes32 dhash) public {
require(disputes[dhash], "dispute doesn't exist");
require(disputes[dhash].dhash.length == 0, "dispute doesn't exist");
Dispute storage dispute = disputes[dhash];
require((now - dispute[dhash].timestamp) >= 2 hours, "vote window must be two hours");
require((now - dispute.timestamp) >= 2 hours, "vote window must be two hours");
require(dispute.finished == false, "dispute already finished");
require(dispute.disputeInitiator == msg.sender, "only dispute initiator can call this function");
if (dispute.sum < 0) {
dispute.disputeResult = false;
} else {
dispute.disputeResult = true;
dioneStaking.slashMiner(dispute.miner);
dispute.voted.push(msg.sender);
dioneStaking.slashMiner(dispute.miner, dispute.voted);
}
dispute.finished = true;

View File

@ -59,11 +59,6 @@ contract DioneOracle is Ownable {
_;
}
modifier onlyActiveNode() {
require(activeNodes[msg.sender], "Not an active miner");
_;
}
constructor(IDioneStaking _dioneStaking) public {
dioneStaking = _dioneStaking;
}
@ -87,7 +82,7 @@ contract DioneOracle is Ownable {
emit CancelOracleRequest(_reqID);
}
function submitOracleRequest(string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline, bytes memory _data) public onlyPendingRequest(_reqID) onlyActiveNode returns (bool) {
function submitOracleRequest(string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline, bytes memory _data) public onlyPendingRequest(_reqID) returns (bool) {
bytes32 requestHash = keccak256(abi.encodePacked(_requestParams, _callbackAddress, _callbackMethodID, _reqID, _requestDeadline));
require(pendingRequests[_reqID] == requestHash, "Params do not match request ID");
delete pendingRequests[_reqID];

View File

@ -47,11 +47,6 @@ contract DioneStaking is Ownable, ReentrancyGuard {
_;
}
modifier onlyDispute(address addr) {
require(addr == disputeContractAddr, "Exception: caller is not the dispute contract");
_;
}
constructor(
DioneToken _dione,
uint256 _minerReward,
@ -140,10 +135,11 @@ contract DioneStaking is Ownable, ReentrancyGuard {
aggregatorAddr = _aggregatorAddr;
}
function slashMiner(address miner, address[] receipentMiners) public onlyDispute {
function slashMiner(address miner, address[] memory receipentMiners) public {
require(msg.sender == disputeContractAddr, "Exception: caller is not the dispute contract");
uint256 share = minerInfo[miner].amount.div(receipentMiners.length);
for (var i = 0; i < receipentMiners.length; i++) {
for (uint8 i = 0; i < receipentMiners.length; i++) {
minerInfo[miner].amount.sub(share);
minerInfo[receipentMiners[i]].amount += share;
}

View File

@ -13,4 +13,5 @@ interface IDioneStaking {
function isMiner(address _minerAddr) external view returns (bool);
function setMinimumStake(uint256 _minimumStake) external;
function setAggregator(address _aggregatorAddr) external;
function slashMiner(address miner, address[] memory receipentMiners) external;
}