Created
December 9, 2021 22:42
-
-
Save teezzan/fd907557127c71763f597d5f60e6d9b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: Unlicense | |
pragma solidity ^0.8.0; | |
contract AdviceContract { | |
address owner; | |
mapping(address => bool) public Doctors; | |
struct Message { | |
uint256 time; | |
address doctor; | |
string message; | |
} | |
mapping(address => Message[]) Patients; | |
constructor() { | |
owner = msg.sender; | |
} | |
function addDoctor(address _address) public { | |
require(msg.sender == owner, "Unauthorized"); | |
Doctors[_address] = true; | |
} | |
function removeDoctor(address _address) public { | |
require(msg.sender == owner, "Unauthorized"); | |
delete Doctors[_address]; | |
} | |
function getOwner() public view returns ( address) { | |
return owner; | |
} | |
function createPatient(address _address) public { | |
require(msg.sender == owner, "UnAuthorized"); | |
Patients[_address].push(Message(block.timestamp, owner, "Created")); | |
} | |
function sendMessage(address _address, string memory _message) public { | |
// require(Doctors[msg.sender], "UnAuthorized"); | |
Patients[_address].push(Message(block.timestamp, msg.sender, _message)); | |
} | |
function getAllMessages() public view returns (Message[] memory) { | |
return Patients[msg.sender]; | |
} | |
function getLastMessage() public view returns (string memory) { | |
return Patients[msg.sender][0].message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment