Skip to main content
. 2025 Jul 28;25(15):4663. doi: 10.3390/s25154663
Algorithm 2 Data management contracts
  •   1:

    Data Structure:  𝒟(data,hash,τ,addr)

  •   2:

    State Variables:

    •     R:B32𝒟         ▹ Mapping from record ID to data record

    •     A:A{0,1}                  ▹ Authorized devices

    •     αA                       ▹ Admin address

  •   3:

    αmsg.sender                      ▹ Contract constructor

  •   4:

    function uploadData(d, h)

  •   5:

        Require: onlyAuthorized

  •   6:

        rH(dτblock)

  •   7:

        R[r](d,h,τblock,msg.sender)

  •   8:

        Emit EventUpload(r,msg.sender)

  •   9:

    end function

  • 10:

    function verifyData(r, d)

  • 11:

        if R[r].τ=0 then

  • 12:

            Revert: “Record invalid”

  • 13:

        end if

  • 14:

        hH(d)

  • 15:

        if hR[r].hash then

  • 16:

            Emit EventHashMismatch(r)

  • 17:

        end if

  • 18:

    end function

  • 19:

    function checkAnomaly(r, p)

  • 20:

        if p>95 then

  • 21:

            Emit EventAnomaly(r,p)

  • 22:

        end if

  • 23:

    end function

  • 24:

    function manageDeviceAccess(a, mode)

  • 25:

        if mode = admin then

  • 26:

            if msg.senderα then

  • 27:

               Revert: “Access denied”

  • 28:

            end if

  • 29:

        else if mode = authorize then

  • 30:

            Require: msg.sender=α

  • 31:

            A[a]1

  • 32:

        else if mode = revoke then

  • 33:

            Require: msg.sender=α

  • 34:

            A[a]0

  • 35:

        else if mode = check then

  • 36:

            if A[a]1 then

  • 37:

               Revert: “Device unauthorized”

  • 38:

            end if

  • 39:

        end if

  • 40:

    end function