Git Product home page Git Product logo

mcrequirement_03's Introduction

Certainly! Here's the updated README:

Message Escrow Application

A simple message escrow application that manages the secure sending and receipt confirmation of messages between two parties.

Description

This program is a simple message escrow application that simulates a secure messaging system where a sender can send a message, and the receiver can confirm its receipt.

Getting Started

Executing program

To run the program, you can use Remix, an online Solidity IDE. Here's the step-by-step instruction on how to make this work:

  1. Go to Remix: Remix IDE
  2. Create a new file in Remix and copy the code from the main.sol file (provided below).
  3. Compile the code with the compiler set to version 0.8.4.
  4. Deploy and run the code.

Code (main.sol)

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

contract MessageEscrow {
    enum State { NONE, AWAITING_MESSAGE, AWAITING_CONFIRMATION, COMPLETE }

    address public sender;
    address public receiver;
    State public currentState;
    address public owner;
    string public message;

    modifier onlySender() {
        require(msg.sender == sender, "Only the sender can call this function");
        _;
    }

    modifier onlyReceiver() {
        require(msg.sender == receiver, "Only the receiver can call this function");
        _;
    }

    modifier inState(State expectedState) {
        require(currentState == expectedState, "Invalid state");
        _;
    }

    constructor(address _sender, address _receiver) {
        sender = _sender;
        receiver = _receiver;
        currentState = State.AWAITING_MESSAGE;
        owner = msg.sender;
    }

    function sendMessage(string memory _message) public onlySender inState(State.AWAITING_MESSAGE) {
        require(bytes(_message).length > 0, "Message must be non-empty");
        message = _message;
        currentState = State.AWAITING_CONFIRMATION;

        assert(bytes(message).length > 0);
        assert(currentState == State.AWAITING_CONFIRMATION);
    }

    function confirmReceipt() public onlyReceiver inState(State.AWAITING_CONFIRMATION) {
        currentState = State.COMPLETE;

        assert(currentState == State.COMPLETE);
    }

    function resetEscrow() public {
        if (msg.sender != owner) {
            revert("Only the owner can reset the escrow");
        }
        
        message = "";
        currentState = State.AWAITING_MESSAGE;
    }
}

Authors

Renz Angelo Aguirre

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

mcrequirement_03's People

Contributors

beepboopbit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.