MyWriterTrigger

Description:

Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "myWriterTrigger.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity 0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

/// @title IReceiver - receives keystone reports
/// @notice Implementations must support the IReceiver interface through ERC165.
interface IReceiver is IERC165 {
  /// @notice Handles incoming keystone reports.
  /// @dev If this function call reverts, it can be retried with a higher gas
  /// limit. The receiver is responsible for discarding stale reports.
  /// @param metadata Report's metadata.
  /// @param report Workflow report.
  function onReport(bytes calldata metadata, bytes calldata report) external;
}

contract MyWriterTrigger is IReceiver {
    uint256 public lastTimeStamp;
    
    // Events for better transparency
    event TriggerCanaryEvent(address indexed forwarder, bytes32 indexed workflowId, address indexed workflowOwner, uint256 currentTime, uint256 triggerTime);

    constructor() {
    }

    // ERC165 support - required for IReceiver interface
    function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
        return
            interfaceId == type(IReceiver).interfaceId || // Check if the interface is IReceiver
            interfaceId == type(IERC165).interfaceId;      // Check if the interface is IERC165
    }

    // Implementation of IReceiver.onReport - must be external
    function onReport(bytes calldata metadata, bytes calldata report) external override {
        (bytes32 workflowId, address workflowOwner, bytes10 workflowName) = _decodeMetadata(metadata);
        uint256 reportTimestamp = abi.decode(report, (uint256));
        lastTimeStamp = block.timestamp;
        emit TriggerCanaryEvent(msg.sender, workflowId, workflowOwner, block.timestamp, reportTimestamp);
    }

    function getLastTimeStamp() external view returns (uint256){
        return lastTimeStamp;
    }

    /// @notice Extracts the workflow ID, name, and owner from the metadata parameter of onReport
    /// @param metadata The metadata in bytes format
    /// @return workflowId The ID of the workflow
    /// @return workflowOwner The owner of the workflow
    /// @return workflowName The name of the workflow
    function _decodeMetadata(bytes memory metadata) internal pure returns (bytes32, address, bytes10) {
        bytes32 workflowId;
        address workflowOwner;
        bytes10 workflowName;
        // (first 32 bytes contain length of the byte array)
        // workflow_id             // offset 32, size 32
        // workflow_name           // offset 64, size 10
        // workflow_owner          // offset 74, size 20
        // report_name             // offset 94, size  2
        assembly {
            // load 32 bytes from offset 32 for workflow_id
            workflowId := mload(add(metadata, 32))
            // no shifting needed for bytes10 type
            workflowName := mload(add(metadata, 64))
            // shift right by 12 bytes to get the actual value
            workflowOwner := shr(mul(12, 8), mload(add(metadata, 74)))
        }
        return (workflowId, workflowOwner, workflowName);
    }
}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": []
  }
}}

Tags:
ERC165, Proxy, Upgradeable, Factory|addr:0x218283ecc3c7325671abe2f89b337108f47b14df|verified:true|block:23678381|tx:0xb7772b09e1947a2c29a6b789adcd74e6e8eaf1e8387584bd754b159fd535a172|first_check:1761725959

Submitted on: 2025-10-29 09:19:19

Comments

Log in to comment.

No comments yet.