Skip to content

Instantly share code, notes, and snippets.

@karthikeyanVK
Last active October 24, 2021 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthikeyanVK/bcce231e7d8659342139afaa2b1b2618 to your computer and use it in GitHub Desktop.
Save karthikeyanVK/bcce231e7d8659342139afaa2b1b2618 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract HelloBlockchain {
enum StateType {Request, Respond}
//List of properties
StateType public State;
address public Requestor;
address public Responder;
string public RequestMessage;
string public ResponseMessage;
event StateChanged(string stateData);
// constructor function
constructor(string memory message) public {
RequestMessage = message;
State = StateType.Request;
emit StateChanged("Request");
}
// call this function to send a request
function SendRequest(string memory requestMessage) public {
Requestor = msg.sender;
RequestMessage = requestMessage;
RequestMessage = string(abi.encodePacked(RequestMessage," Versioned"));
State = StateType.Request;
}
// call this function to send a response
function SendResponse(string memory responseMessage) public {
Responder = msg.sender;
// call ContractUpdated() to record this action
ResponseMessage = responseMessage;
State = StateType.Respond;
emit StateChanged("Response");
}
function getMessage() public view returns (string memory) {
if (State == StateType.Request) return RequestMessage;
else return ResponseMessage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment