mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-02-26 21:30:35 +00:00
[Markeplace] Linting
This commit is contained in:
parent
afb89c9233
commit
afad73d588
@ -59,10 +59,9 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
return RequestId.unwrap(a) == RequestId.unwrap(b);
|
return RequestId.unwrap(a) == RequestId.unwrap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestStorage(Request calldata request)
|
function requestStorage(
|
||||||
public
|
Request calldata request
|
||||||
marketplaceInvariant
|
) public marketplaceInvariant {
|
||||||
{
|
|
||||||
require(request.client == msg.sender, "Invalid client address");
|
require(request.client == msg.sender, "Invalid client address");
|
||||||
|
|
||||||
RequestId id = _toRequestId(request);
|
RequestId id = _toRequestId(request);
|
||||||
@ -129,10 +128,10 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function markProofAsMissing(SlotId slotId, uint256 period)
|
function markProofAsMissing(
|
||||||
public
|
SlotId slotId,
|
||||||
slotMustAcceptProofs(slotId)
|
uint256 period
|
||||||
{
|
) public slotMustAcceptProofs(slotId) {
|
||||||
_markProofAsMissing(slotId, period);
|
_markProofAsMissing(slotId, period);
|
||||||
address host = _host(slotId);
|
address host = _host(slotId);
|
||||||
if (missingProofs(slotId) % slashMisses == 0) {
|
if (missingProofs(slotId) % slashMisses == 0) {
|
||||||
@ -147,7 +146,9 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _forciblyFreeSlot(SlotId slotId)
|
function _forciblyFreeSlot(
|
||||||
|
SlotId slotId
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
slotMustAcceptProofs(slotId)
|
slotMustAcceptProofs(slotId)
|
||||||
marketplaceInvariant
|
marketplaceInvariant
|
||||||
@ -188,10 +189,10 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function payoutSlot(RequestId requestId, SlotId slotId)
|
function payoutSlot(
|
||||||
private
|
RequestId requestId,
|
||||||
marketplaceInvariant
|
SlotId slotId
|
||||||
{
|
) private marketplaceInvariant {
|
||||||
require(
|
require(
|
||||||
_isFinished(requestId) || _isCancelled(requestId),
|
_isFinished(requestId) || _isCancelled(requestId),
|
||||||
"Contract not ended"
|
"Contract not ended"
|
||||||
@ -266,11 +267,9 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
/// @dev Returns requestId that is mapped to the slotId
|
/// @dev Returns requestId that is mapped to the slotId
|
||||||
/// @param slotId id of the slot
|
/// @param slotId id of the slot
|
||||||
/// @return if of the request the slot belongs to
|
/// @return if of the request the slot belongs to
|
||||||
function _getRequestIdForSlot(SlotId slotId)
|
function _getRequestIdForSlot(
|
||||||
internal
|
SlotId slotId
|
||||||
view
|
) internal view returns (RequestId) {
|
||||||
returns (RequestId)
|
|
||||||
{
|
|
||||||
Slot memory slot = _slot(slotId);
|
Slot memory slot = _slot(slotId);
|
||||||
require(_notEqual(slot.requestId, 0), "Missing request id");
|
require(_notEqual(slot.requestId, 0), "Missing request id");
|
||||||
return slot.requestId;
|
return slot.requestId;
|
||||||
@ -293,21 +292,17 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
return _host(slotId);
|
return _host(slotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _request(RequestId requestId)
|
function _request(
|
||||||
internal
|
RequestId requestId
|
||||||
view
|
) internal view returns (Request storage) {
|
||||||
returns (Request storage)
|
|
||||||
{
|
|
||||||
Request storage request = requests[requestId];
|
Request storage request = requests[requestId];
|
||||||
require(request.client != address(0), "Unknown request");
|
require(request.client != address(0), "Unknown request");
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRequest(RequestId requestId)
|
function getRequest(
|
||||||
public
|
RequestId requestId
|
||||||
view
|
) public view returns (Request memory) {
|
||||||
returns (Request memory)
|
|
||||||
{
|
|
||||||
return _request(requestId);
|
return _request(requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,11 +312,9 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _context(RequestId requestId)
|
function _context(
|
||||||
internal
|
RequestId requestId
|
||||||
view
|
) internal view returns (RequestContext storage) {
|
||||||
returns (RequestContext storage)
|
|
||||||
{
|
|
||||||
return requestContexts[requestId];
|
return requestContexts[requestId];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,61 +406,50 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
/// @notice returns true when the request is accepting proof submissions from hosts occupying slots.
|
/// @notice returns true when the request is accepting proof submissions from hosts occupying slots.
|
||||||
/// @dev Request state must be new or started, and must not be cancelled, finished, or failed.
|
/// @dev Request state must be new or started, and must not be cancelled, finished, or failed.
|
||||||
/// @param requestId id of the request for which to obtain state info
|
/// @param requestId id of the request for which to obtain state info
|
||||||
function _requestAcceptsProofs(RequestId requestId)
|
function _requestAcceptsProofs(
|
||||||
internal
|
RequestId requestId
|
||||||
view
|
) internal view returns (bool) {
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
RequestState s = state(requestId);
|
RequestState s = state(requestId);
|
||||||
return s == RequestState.New || s == RequestState.Started;
|
return s == RequestState.New || s == RequestState.Started;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _toRequestId(Request memory request)
|
function _toRequestId(
|
||||||
internal
|
Request memory request
|
||||||
pure
|
) internal pure returns (RequestId) {
|
||||||
returns (RequestId)
|
|
||||||
{
|
|
||||||
return RequestId.wrap(keccak256(abi.encode(request)));
|
return RequestId.wrap(keccak256(abi.encode(request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function _toRequestIds(bytes32[] memory array)
|
function _toRequestIds(
|
||||||
private
|
bytes32[] memory array
|
||||||
pure
|
) private pure returns (RequestId[] memory result) {
|
||||||
returns (RequestId[] memory result)
|
|
||||||
{
|
|
||||||
// solhint-disable-next-line no-inline-assembly
|
// solhint-disable-next-line no-inline-assembly
|
||||||
assembly {
|
assembly {
|
||||||
result := array
|
result := array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _toSlotIds(bytes32[] memory array)
|
function _toSlotIds(
|
||||||
private
|
bytes32[] memory array
|
||||||
pure
|
) private pure returns (SlotId[] memory result) {
|
||||||
returns (SlotId[] memory result)
|
|
||||||
{
|
|
||||||
// solhint-disable-next-line no-inline-assembly
|
// solhint-disable-next-line no-inline-assembly
|
||||||
assembly {
|
assembly {
|
||||||
result := array
|
result := array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _toBytes32s(RequestId[] memory array)
|
function _toBytes32s(
|
||||||
private
|
RequestId[] memory array
|
||||||
pure
|
) private pure returns (bytes32[] memory result) {
|
||||||
returns (bytes32[] memory result)
|
|
||||||
{
|
|
||||||
// solhint-disable-next-line no-inline-assembly
|
// solhint-disable-next-line no-inline-assembly
|
||||||
assembly {
|
assembly {
|
||||||
result := array
|
result := array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _toSlotId(RequestId requestId, uint256 slotIndex)
|
function _toSlotId(
|
||||||
internal
|
RequestId requestId,
|
||||||
pure
|
uint256 slotIndex
|
||||||
returns (SlotId)
|
) internal pure returns (SlotId) {
|
||||||
{
|
|
||||||
return SlotId.wrap(keccak256(abi.encode(requestId, slotIndex)));
|
return SlotId.wrap(keccak256(abi.encode(requestId, slotIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,7 @@ contract Proofs {
|
|||||||
uint256 private immutable timeout;
|
uint256 private immutable timeout;
|
||||||
uint8 private immutable downtime;
|
uint8 private immutable downtime;
|
||||||
|
|
||||||
constructor(
|
constructor(uint256 __period, uint256 __timeout, uint8 __downtime) {
|
||||||
uint256 __period,
|
|
||||||
uint256 __timeout,
|
|
||||||
uint8 __downtime
|
|
||||||
) {
|
|
||||||
require(block.number > 256, "Insufficient block height");
|
require(block.number > 256, "Insufficient block height");
|
||||||
period = __period;
|
period = __period;
|
||||||
timeout = __timeout;
|
timeout = __timeout;
|
||||||
@ -87,11 +83,10 @@ contract Proofs {
|
|||||||
ids[id] = false;
|
ids[id] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getPointer(SlotId id, uint256 proofPeriod)
|
function _getPointer(
|
||||||
internal
|
SlotId id,
|
||||||
view
|
uint256 proofPeriod
|
||||||
returns (uint8)
|
) internal view returns (uint8) {
|
||||||
{
|
|
||||||
uint256 blockNumber = block.number % 256;
|
uint256 blockNumber = block.number % 256;
|
||||||
uint256 periodNumber = proofPeriod % 256;
|
uint256 periodNumber = proofPeriod % 256;
|
||||||
uint256 idOffset = uint256(SlotId.unwrap(id)) % 256;
|
uint256 idOffset = uint256(SlotId.unwrap(id)) % 256;
|
||||||
@ -109,11 +104,10 @@ contract Proofs {
|
|||||||
return keccak256(abi.encode(hash));
|
return keccak256(abi.encode(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getChallenge(SlotId id, uint256 proofPeriod)
|
function _getChallenge(
|
||||||
internal
|
SlotId id,
|
||||||
view
|
uint256 proofPeriod
|
||||||
returns (bytes32)
|
) internal view returns (bytes32) {
|
||||||
{
|
|
||||||
return _getChallenge(_getPointer(id, proofPeriod));
|
return _getChallenge(_getPointer(id, proofPeriod));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +115,10 @@ contract Proofs {
|
|||||||
return _getChallenge(id, currentPeriod());
|
return _getChallenge(id, currentPeriod());
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getProofRequirement(SlotId id, uint256 proofPeriod)
|
function _getProofRequirement(
|
||||||
internal
|
SlotId id,
|
||||||
view
|
uint256 proofPeriod
|
||||||
returns (bool isRequired, uint8 pointer)
|
) internal view returns (bool isRequired, uint8 pointer) {
|
||||||
{
|
|
||||||
if (proofPeriod <= periodOf(starts[id])) {
|
if (proofPeriod <= periodOf(starts[id])) {
|
||||||
return (false, 0);
|
return (false, 0);
|
||||||
}
|
}
|
||||||
@ -139,11 +132,10 @@ contract Proofs {
|
|||||||
isRequired = ids[id] && uint256(challenge) % probability == 0;
|
isRequired = ids[id] && uint256(challenge) % probability == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _isProofRequired(SlotId id, uint256 proofPeriod)
|
function _isProofRequired(
|
||||||
internal
|
SlotId id,
|
||||||
view
|
uint256 proofPeriod
|
||||||
returns (bool)
|
) internal view returns (bool) {
|
||||||
{
|
|
||||||
bool isRequired;
|
bool isRequired;
|
||||||
uint8 pointer;
|
uint8 pointer;
|
||||||
(isRequired, pointer) = _getProofRequirement(id, proofPeriod);
|
(isRequired, pointer) = _getProofRequirement(id, proofPeriod);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user