Skip to content

Commit

Permalink
feat: task storage contract
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk committed Dec 27, 2024
1 parent bf4b30a commit ee548c4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/contracts/LayerSDK.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ contract LayerSDK is ILayerSDK {
/// @inheritdoc ILayerSDK
ECDSAStakeRegistry public immutable STAKE_REGISTRY;

/**
* @notice Modifier to ensure a task is valid
* @param _task The task to validate
*/
modifier onlyValidLayerTask(Task memory _task) {
if (!_validateLayerTask(_task)) revert InvalidLayerTask();
_;
}

/**
* @notice Initializer
* @param _stakeRegistry The address of the stake registry contract
Expand Down
29 changes: 29 additions & 0 deletions src/example-contracts/StorageQueryConsumer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {LayerSDK} from 'contracts/LayerSDK.sol';

contract StorageQueryConsumer is LayerSDK {
/// @notice Mapping to store the task hashes
mapping(bytes32 _taskHash => bool _isValid) internal _storedTasks;

/// @notice Initializer
constructor(address _stakeRegistry) LayerSDK(_stakeRegistry) {}

/**
* @notice Stores a layer task
* @param _task The task to store
*/
function storeLayerTask(Task memory _task) external onlyValidLayerTask(_task) {
_storedTasks[_task.dataHash] = true;
}

/**
* @notice Queries a layer task
* @param _taskHash The hash of the task to query
* @return _isValid Whether the task is valid
*/
function queryLayerTask(bytes32 _taskHash) external view returns (bool _isValid) {
_isValid = _storedTasks[_taskHash];
}
}
3 changes: 3 additions & 0 deletions src/interfaces/ILayerSDK.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface ILayerSDK {
bytes signatureData;
}

/// @notice The error thrown when a layer task is invalid
error InvalidLayerTask();

/**
* @notice The stake registry contract
* @return _stakeRegistry The stake registry address
Expand Down

0 comments on commit ee548c4

Please sign in to comment.