Reputation: 21
I'm new to Solidity.I've got an error from compiling the above code.
browser/EHRs.sol:18:9 :Error:Undeclared identifier.require(msg.sender = dotor);
Hopefully someone can give some guidance
pragma solidity ^0.4.0;
contract postRecord {
bytes32 public patientRecords;
address public doctor;
function Person() private{
doctor = msg.sender;
}
struct patient {
address client;
bool consent;
bytes32 name;
}
function setPatientRecords(bytes32 _patientRecords) public {
patientRecords = _patientRecords;
}
event Post(bytes32 patientRecords, address doctor);
modifier rightPerson {
require (msg.sender = doctor);
_;
}
function getRecords()public payable{
Post(patientRecords, doctor);
}}
Upvotes: 2
Views: 2347
Reputation: 81
The problem is that inside the require statement, you are performing an assignment
instead of a comparision
.
require (msg.sender = doctor);
This assigns doctor
to msg.sender
which is incorrect.
Instead, you should use the equality comparison operator ==
to perform the comparision.
require (msg.sender == doctor);
And as an answer above suggested, use a revert string for better user and dev experience.
require (msg.sender = doctor, "PostRecord: Caller must be a doctor.");
Also, write the contract name with a capital first letter: PostRecord
instead of postRecord
.
Upvotes: 0
Reputation: 316
Firstly use ==
to compare values, and secondly pass exception message as second parameter in require
(you can pass empty string)
modifier rightPerson {
require (msg.sender == doctor, "");
_;
}
Upvotes: 1
Reputation: 53
Have a look at this solution
modifier rightPerson {
require (doctor == msg.sender);
_;
}
Upvotes: 0