forked from ethereum-optimism/optimism-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
28,053 additions
and
7,990 deletions.
There are no files selected for viewing
77 changes: 65 additions & 12 deletions
77
ecosystem/attestation-station/contract-access/contracts/AttestationStation.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,85 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
pragma solidity 0.8.15; | ||
|
||
contract AttestationStation { | ||
mapping(address => mapping(address => mapping(bytes32 => bytes))) public attestations; | ||
import { Semver } from "@eth-optimism/contracts-bedrock/contracts/universal/Semver.sol"; | ||
|
||
/** | ||
* @title AttestationStation | ||
* @author Optimism Collective | ||
* @author Gitcoin | ||
* @notice Where attestations live. | ||
*/ | ||
contract AttestationStation is Semver { | ||
/** | ||
* @notice Struct representing data that is being attested. | ||
* | ||
* @custom:field about Address for which the attestation is about. | ||
* @custom:field key A bytes32 key for the attestation. | ||
* @custom:field val The attestation as arbitrary bytes. | ||
*/ | ||
struct AttestationData { | ||
address about; | ||
bytes32 key; | ||
bytes val; | ||
} | ||
|
||
/** | ||
* @notice Maps addresses to attestations. Creator => About => Key => Value. | ||
*/ | ||
mapping(address => mapping(address => mapping(bytes32 => bytes))) public attestations; | ||
|
||
/** | ||
* @notice Emitted when Attestation is created. | ||
* | ||
* @param creator Address that made the attestation. | ||
* @param about Address attestation is about. | ||
* @param key Key of the attestation. | ||
* @param val Value of the attestation. | ||
*/ | ||
event AttestationCreated( | ||
address indexed creator, | ||
address indexed about, | ||
bytes32 indexed key, | ||
bytes val | ||
); | ||
|
||
function attest(AttestationData[] memory _attestations) public { | ||
for (uint256 i = 0; i < _attestations.length; ++i) { | ||
/** | ||
* @custom:semver 1.1.0 | ||
*/ | ||
constructor() Semver(1, 1, 0) {} | ||
|
||
/** | ||
* @notice Allows anyone to create an attestation. | ||
* | ||
* @param _about Address that the attestation is about. | ||
* @param _key A key used to namespace the attestation. | ||
* @param _val An arbitrary value stored as part of the attestation. | ||
*/ | ||
function attest( | ||
address _about, | ||
bytes32 _key, | ||
bytes memory _val | ||
) public { | ||
attestations[msg.sender][_about][_key] = _val; | ||
|
||
emit AttestationCreated(msg.sender, _about, _key, _val); | ||
} | ||
|
||
/** | ||
* @notice Allows anyone to create attestations. | ||
* | ||
* @param _attestations An array of AttestationData structs. | ||
*/ | ||
function attest(AttestationData[] calldata _attestations) external { | ||
uint256 length = _attestations.length; | ||
for (uint256 i = 0; i < length; ) { | ||
AttestationData memory attestation = _attestations[i]; | ||
attestations[msg.sender][attestation.about][attestation.key] = attestation.val; | ||
emit AttestationCreated( | ||
msg.sender, | ||
attestation.about, | ||
attestation.key, | ||
attestation.val | ||
); | ||
|
||
attest(attestation.about, attestation.key, attestation.val); | ||
|
||
unchecked { | ||
++i; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.