dagger-contracts/contracts/Storage.sol

86 lines
2.2 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./Marketplace.sol";
import "./Proofs.sol";
import "./Collateral.sol";
contract Storage is Collateral, Marketplace, Proofs {
uint256 public collateralAmount;
2022-02-09 13:17:23 +00:00
uint256 public slashMisses;
uint256 public slashPercentage;
2022-02-09 13:17:23 +00:00
mapping(bytes32 => bool) private finished;
constructor(
IERC20 token,
uint256 _collateralAmount,
2022-02-09 13:17:23 +00:00
uint256 _slashMisses,
uint256 _slashPercentage
) Marketplace(token, _collateralAmount) {
collateralAmount = _collateralAmount;
slashMisses = _slashMisses;
slashPercentage = _slashPercentage;
2021-11-02 11:45:09 +00:00
}
function startContract(bytes32 id) public {
Offer storage offer = _offer(id);
require(msg.sender == offer.host, "Only host can call this function");
Request storage request = _request(offer.requestId);
_expectProofs(
id,
request.proofPeriod,
request.proofTimeout,
request.duration
);
}
2021-11-04 09:19:23 +00:00
function finishContract(bytes32 id) public {
require(block.number > proofEnd(id), "Contract has not ended yet");
require(!finished[id], "Contract already finished");
finished[id] = true;
Offer storage offer = _offer(id);
require(token.transfer(offer.host, offer.price), "Payment failed");
}
2022-02-09 13:17:23 +00:00
function proofEnd(bytes32 contractId) public view returns (uint256) {
return _end(contractId);
}
2022-02-09 13:17:23 +00:00
function missingProofs(bytes32 contractId) public view returns (uint256) {
return _missed(contractId);
}
2022-02-09 13:17:23 +00:00
function isProofRequired(bytes32 contractId, uint256 blocknumber)
public
view
returns (bool)
{
return _isProofRequired(contractId, blocknumber);
}
2021-10-18 12:55:59 +00:00
2022-02-09 13:17:23 +00:00
function isProofTimedOut(bytes32 contractId, uint256 blocknumber)
public
view
returns (bool)
{
return _isProofTimedOut(contractId, blocknumber);
2021-10-19 07:37:03 +00:00
}
function submitProof(
bytes32 contractId,
2022-02-09 13:17:23 +00:00
uint256 blocknumber,
bool proof
2022-02-09 13:17:23 +00:00
) public {
_submitProof(contractId, blocknumber, proof);
2021-10-18 12:55:59 +00:00
}
2021-10-19 07:37:03 +00:00
2022-02-09 13:17:23 +00:00
function markProofAsMissing(bytes32 contractId, uint256 blocknumber) public {
_markProofAsMissing(contractId, blocknumber);
if (_missed(contractId) % slashMisses == 0) {
Offer storage offer = _offer(contractId);
_slash(offer.host, slashPercentage);
}
2021-10-19 07:37:03 +00:00
}
}