2021-10-12 14:59:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
import "./Contracts.sol";
|
2021-11-01 11:30:35 +00:00
|
|
|
import "./Proofs.sol";
|
2021-11-02 10:19:52 +00:00
|
|
|
import "./Stakes.sol";
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-11-02 10:19:52 +00:00
|
|
|
contract Storage is Contracts, Proofs, Stakes {
|
|
|
|
|
2021-11-02 11:45:09 +00:00
|
|
|
uint private stakeAmount;
|
|
|
|
|
|
|
|
constructor(IERC20 token, uint _stakeAmount) Stakes(token) {
|
|
|
|
stakeAmount = _stakeAmount;
|
|
|
|
}
|
2021-10-20 10:07:35 +00:00
|
|
|
|
|
|
|
function newContract(
|
|
|
|
uint _duration,
|
|
|
|
uint _size,
|
|
|
|
bytes32 _contentHash,
|
|
|
|
uint _proofPeriod,
|
|
|
|
uint _proofTimeout,
|
2021-10-20 12:28:05 +00:00
|
|
|
bytes32 _nonce,
|
2021-11-01 15:23:37 +00:00
|
|
|
uint _price,
|
2021-10-20 10:07:35 +00:00
|
|
|
address _host,
|
2021-11-01 15:23:37 +00:00
|
|
|
uint _bidExpiry,
|
2021-10-20 10:07:35 +00:00
|
|
|
bytes memory requestSignature,
|
|
|
|
bytes memory bidSignature
|
|
|
|
)
|
|
|
|
public
|
2021-10-12 14:59:34 +00:00
|
|
|
{
|
2021-11-02 11:45:09 +00:00
|
|
|
require(_stake(_host) >= stakeAmount, "Insufficient stake");
|
2021-11-02 11:50:06 +00:00
|
|
|
_lockStake(_host);
|
2021-11-04 08:49:07 +00:00
|
|
|
_newContract(
|
2021-10-14 12:49:29 +00:00
|
|
|
_duration,
|
|
|
|
_size,
|
|
|
|
_contentHash,
|
|
|
|
_proofPeriod,
|
2021-10-20 12:28:05 +00:00
|
|
|
_proofTimeout,
|
2021-11-01 15:17:42 +00:00
|
|
|
_nonce,
|
2021-11-01 15:23:37 +00:00
|
|
|
_price,
|
2021-11-01 15:17:42 +00:00
|
|
|
_host,
|
2021-11-01 15:23:37 +00:00
|
|
|
_bidExpiry,
|
2021-11-01 15:17:42 +00:00
|
|
|
requestSignature,
|
|
|
|
bidSignature
|
2021-10-14 12:49:29 +00:00
|
|
|
);
|
2021-11-04 08:49:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 08:53:01 +00:00
|
|
|
modifier onlyHost(bytes32 id) {
|
|
|
|
require(msg.sender == host(id), "Only host can call this function");
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
function startContract(bytes32 id) public onlyHost(id) {
|
2021-11-04 08:49:07 +00:00
|
|
|
_expectProofs(id, proofPeriod(id), proofTimeout(id), duration(id));
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 09:19:23 +00:00
|
|
|
function finishContract(bytes32 id) public {
|
|
|
|
require(block.number > proofEnd(id), "Contract has not ended yet");
|
|
|
|
_unlockStake(host(id));
|
|
|
|
}
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
function duration(bytes32 contractId) public view returns (uint) {
|
|
|
|
return _duration(contractId);
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
function size(bytes32 contractId) public view returns (uint) {
|
|
|
|
return _size(contractId);
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
function contentHash(bytes32 contractId) public view returns (bytes32) {
|
|
|
|
return _contentHash(contractId);
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
function price(bytes32 contractId) public view returns (uint) {
|
|
|
|
return _price(contractId);
|
2021-10-18 13:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
function host(bytes32 contractId) public view returns (address) {
|
|
|
|
return _host(contractId);
|
|
|
|
}
|
|
|
|
|
|
|
|
function proofPeriod(bytes32 contractId) public view returns (uint) {
|
2021-11-04 08:49:07 +00:00
|
|
|
return _proofPeriod(contractId);
|
2021-11-01 15:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function proofTimeout(bytes32 contractId) public view returns (uint) {
|
2021-11-04 08:49:07 +00:00
|
|
|
return _proofTimeout(contractId);
|
|
|
|
}
|
|
|
|
|
|
|
|
function proofEnd(bytes32 contractId) public view returns (uint) {
|
|
|
|
return _end(contractId);
|
2021-11-01 15:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function missingProofs(bytes32 contractId) public view returns (uint) {
|
|
|
|
return _missed(contractId);
|
2021-10-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isProofRequired(
|
2021-10-20 12:28:05 +00:00
|
|
|
bytes32 contractId,
|
2021-10-20 10:07:35 +00:00
|
|
|
uint blocknumber
|
|
|
|
)
|
|
|
|
public view
|
|
|
|
returns (bool)
|
|
|
|
{
|
2021-11-01 11:30:35 +00:00
|
|
|
return _isProofRequired(contractId, blocknumber);
|
2021-10-14 10:37:14 +00:00
|
|
|
}
|
2021-10-18 12:55:59 +00:00
|
|
|
|
2021-10-20 10:07:35 +00:00
|
|
|
function isProofTimedOut(
|
2021-10-20 12:28:05 +00:00
|
|
|
bytes32 contractId,
|
2021-10-20 10:07:35 +00:00
|
|
|
uint blocknumber
|
|
|
|
)
|
2021-11-01 11:30:35 +00:00
|
|
|
public view
|
2021-10-20 10:07:35 +00:00
|
|
|
returns (bool)
|
|
|
|
{
|
2021-11-01 11:30:35 +00:00
|
|
|
return _isProofTimedOut(contractId, blocknumber);
|
2021-10-19 07:37:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 10:07:35 +00:00
|
|
|
function submitProof(
|
2021-10-20 12:28:05 +00:00
|
|
|
bytes32 contractId,
|
2021-10-20 10:07:35 +00:00
|
|
|
uint blocknumber,
|
|
|
|
bool proof
|
|
|
|
)
|
|
|
|
public
|
|
|
|
{
|
2021-11-01 11:30:35 +00:00
|
|
|
_submitProof(contractId, blocknumber, proof);
|
2021-10-18 12:55:59 +00:00
|
|
|
}
|
2021-10-19 07:37:03 +00:00
|
|
|
|
2021-10-20 12:28:05 +00:00
|
|
|
function markProofAsMissing(bytes32 contractId, uint blocknumber) public {
|
2021-11-01 11:30:35 +00:00
|
|
|
_markProofAsMissing(contractId, blocknumber);
|
2021-10-19 07:37:03 +00:00
|
|
|
}
|
2021-11-02 10:19:52 +00:00
|
|
|
|
|
|
|
function increaseStake(uint amount) public {
|
|
|
|
_increaseStake(amount);
|
|
|
|
}
|
2021-11-02 11:50:06 +00:00
|
|
|
|
|
|
|
function withdrawStake() public {
|
|
|
|
_withdrawStake();
|
|
|
|
}
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|