Blockchain / Global / Address

Contract

0x7e1d861cc85Eb641241e102DA82B2e22D888B94c

Balance
0 SOMI
Transactions sent
1
Type
Contract · 888 bytes of code

DailyCheckIn Verified

Compiler
solc 0.8.28+commit.7893614a
Language
Solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
—
Verified
2026-10-12

DailyCheckIn.sol

Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract DailyCheckIn {
    // Mapping to track check-ins: userId => date => hasCheckedIn
    mapping(uint256 => mapping(uint256 => bool)) public userCheckIns;

    // Mapping to track last check-in date for each user
    mapping(uint256 => uint256) public lastCheckInDate;

    mapping (uint256 => uint256) public totalCheckIn;

    // Event emitted when a user checks in
    event CheckedIn(uint256 indexed userId, uint256 date);

    // Check In Error
    error AlreadyCheckIn();

    /**
     * @dev Check in for the current day
     * Users can only check in once per day
     * @param userId The DID identifier for the user
     */
    function checkIn(uint256 userId) external {
        uint256 today = getCurrentDay();

        // Check if user has already checked in today
        if (userCheckIns[userId][today]) revert AlreadyCheckIn();

        // Mark user as checked in for today
        userCheckIns[userId][today] = true;

        // Update last check-in date
        lastCheckInDate[userId] = today;

        //update total check in
        totalCheckIn[userId] += 1;

        // Emit event
        emit CheckedIn(userId, today);
    }

    /**
     * @dev Check if a user has checked in on a specific date
     * @param userId The DID identifier for the user
     * @param date The date to check (days since Unix epoch)
     * @return bool Whether the user checked in on that date
     */
    function hasCheckedIn(
        uint256 userId,
        uint256 date
    ) external view returns (bool) {
        return userCheckIns[userId][date];
    }

    /**
     * @dev Check if a user has checked in today
     * @param userId The DID identifier for the user
     * @return bool Whether the user checked in today
     */
    function hasCheckedInToday(uint256 userId) external view returns (bool) {
        return userCheckIns[userId][getCurrentDay()];
    }

    /**
     * @dev Get the last check-in date for a user
     * @param userId The DID identifier for the user
     * @return uint256 The last date the user checked in
     */
    function getLastCheckInDate(
        uint256 userId
    ) external view returns (uint256) {
        return lastCheckInDate[userId];
    }

    /**
     * @dev Get current day as days since Unix epoch
     * @return uint256 Current day
     */
    function getCurrentDay() public view returns (uint256) {
        return block.timestamp / 86400; // 86400 seconds = 1 day
    }

    /**
     * @dev Get total check-in count for a user
     * @param userId The DID identifier for the user
     * @return uint256 Total check-in count
     */
    function getTotalCheckIn(uint256 userId) external view returns (uint256) {
        return totalCheckIn[userId];
    }
}
ABI · 11 entries
json
[
  {
    "name": "AlreadyCheckIn",
    "type": "error",
    "inputs": []
  },
  {
    "name": "CheckedIn",
    "type": "event",
    "inputs": [
      {
        "name": "userId",
        "type": "uint256",
        "indexed": true,
        "internalType": "uint256"
      },
      {
        "name": "date",
        "type": "uint256",
        "indexed": false,
        "internalType": "uint256"
      }
    ],
    "anonymous": false
  },
  {
    "name": "checkIn",
    "type": "function",
    "inputs": [
      {
        "name": "userId",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "name": "getCurrentDay",
    "type": "function",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "getLastCheckInDate",
    "type": "function",
    "inputs": [
      {
        "name": "userId",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "getTotalCheckIn",
    "type": "function",
    "inputs": [
      {
        "name": "userId",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "hasCheckedIn",
    "type": "function",
    "inputs": [
      {
        "name": "userId",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "date",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "hasCheckedInToday",
    "type": "function",
    "inputs": [
      {
        "name": "userId",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "lastCheckInDate",
    "type": "function",
    "inputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "totalCheckIn",
    "type": "function",
    "inputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "name": "userCheckIns",
    "type": "function",
    "inputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "view"
  }
]