Skip to content

Instantly share code, notes, and snippets.

@M4cs
Created June 21, 2023 20:11
Show Gist options
  • Save M4cs/8ab7ad8337ce9571b768ff0d0a235df5 to your computer and use it in GitHub Desktop.
Save M4cs/8ab7ad8337ce9571b768ff0d0a235df5 to your computer and use it in GitHub Desktop.
ESIP-1: Contract functionality for ETHScriptions through Event driven transactions. Indexer must check for topic: `Enscription(address,address,bytes)`
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "./IESIP-1.sol";
contract ESIP1 is IESIP1 {
/**
* @dev Enscribes `data` to `to` address.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `data` cannot be blank.
*
* Emits a {Enscription} event.
*/
function enscribe(address to, bytes memory data) public {
if (to == address(0)) {
revert EnscriptionToZeroAddress();
}
emit Enscription(msg.sender, to, data);
}
/**
* @dev Loops through `to` and `data` arrays to enscribe to
* each respective address.
*
* Requirements:
*
* - `to` addresses cannot be the zero address.
* - `data` values cannot be blank.
*
* Emits {Enscription} events based on number of addresses supplied.
*/
function batchEnscribe(address[] memory to, bytes[] memory data) public {
if (to.length != data.length) {
revert MismatchBatchLengths();
}
unchecked {
for (uint i=0;i<to.length;i++) {
if (to[i] == address(0)) {
revert EnscriptionToZeroAddress();
}
emit Enscription(msg.sender, to[i], data[i]);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
interface IESIP1 {
/**
* In batch enscriptions, the `to` array and `data` array must match in length.
*/
error MismatchBatchLengths();
/**
* Enscriptions cannot be sent to the ZeroAddress.
*/
error EnscriptionToZeroAddress();
/**
* @dev Emitted when `enscriptor` calls
* (`approved`) `operator` to manage all of its assets.
*/
event Enscription(address indexed enscriptor, address indexed to, bytes indexed data);
/**
* @dev Enscribes `data` to `to` address.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `data` cannot be blank.
*
* Emits a {Enscription} event.
*/
function enscribe(
address to,
bytes memory data
) external;
/**
* @dev Loops through `to` and `data` arrays to enscribe to
* each respective address.
*
* Requirements:
*
* - `to` addresses cannot be the zero address.
* - `data` values cannot be blank.
*
* Emits {Enscription} events based on number of addresses supplied.
*/
function batchEnscribe(
address[] memory to,
bytes[] memory data
) external;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment