[Marketplace] Extract Request struct into separate file

This commit is contained in:
Mark Spanbroek 2023-01-09 13:56:29 +01:00 committed by markspanbroek
parent ac98689892
commit 27ccb1e2bc
2 changed files with 39 additions and 36 deletions

View File

@ -4,15 +4,13 @@ pragma solidity ^0.8.8;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./Requests.sol";
import "./Collateral.sol"; import "./Collateral.sol";
import "./Proofs.sol"; import "./Proofs.sol";
contract Marketplace is Collateral, Proofs { contract Marketplace is Collateral, Proofs {
using EnumerableSet for EnumerableSet.Bytes32Set; using EnumerableSet for EnumerableSet.Bytes32Set;
type RequestId is bytes32;
type SlotId is bytes32;
uint256 public immutable collateral; uint256 public immutable collateral;
MarketplaceFunds private funds; MarketplaceFunds private funds;
mapping(RequestId => Request) private requests; mapping(RequestId => Request) private requests;
@ -433,39 +431,6 @@ contract Marketplace is Collateral, Proofs {
return RequestId.unwrap(a) != bytes32(b); return RequestId.unwrap(a) != bytes32(b);
} }
struct Request {
address client;
Ask ask;
Content content;
uint256 expiry; // time at which this request expires
bytes32 nonce; // random nonce to differentiate between similar requests
}
struct Ask {
uint64 slots; // the number of requested slots
uint256 slotSize; // amount of storage per slot (in number of bytes)
uint256 duration; // how long content should be stored (in seconds)
uint256 proofProbability; // how often storage proofs are required
uint256 reward; // amount of tokens paid per second per slot to hosts
uint64 maxSlotLoss; // Max slots that can be lost without data considered to be lost
}
struct Content {
string cid; // content id (if part of a larger set, the chunk cid)
Erasure erasure; // Erasure coding attributes
PoR por; // Proof of Retrievability parameters
}
struct Erasure {
uint64 totalChunks; // the total number of chunks in the larger data set
}
struct PoR {
bytes u; // parameters u_1..u_s
bytes publicKey; // public key
bytes name; // random name
}
enum RequestState { enum RequestState {
New, // [default] waiting to fill slots New, // [default] waiting to fill slots
Started, // all slots filled, accepting regular proofs Started, // all slots filled, accepting regular proofs

38
contracts/Requests.sol Normal file
View File

@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
type RequestId is bytes32;
type SlotId is bytes32;
struct Request {
address client;
Ask ask;
Content content;
uint256 expiry; // time at which this request expires
bytes32 nonce; // random nonce to differentiate between similar requests
}
struct Ask {
uint64 slots; // the number of requested slots
uint256 slotSize; // amount of storage per slot (in number of bytes)
uint256 duration; // how long content should be stored (in seconds)
uint256 proofProbability; // how often storage proofs are required
uint256 reward; // amount of tokens paid per second per slot to hosts
uint64 maxSlotLoss; // Max slots that can be lost without data considered to be lost
}
struct Content {
string cid; // content id (if part of a larger set, the chunk cid)
Erasure erasure; // Erasure coding attributes
PoR por; // Proof of Retrievability parameters
}
struct Erasure {
uint64 totalChunks; // the total number of chunks in the larger data set
}
struct PoR {
bytes u; // parameters u_1..u_s
bytes publicKey; // public key
bytes name; // random name
}