【发布时间】:2018-08-18 16:34:31
【问题描述】:
下面是我的智能合约。当我把它混音时,我会收到以下每个功能的警告。
函数 MedicalRecord.addNote(bytes32,bytes32) 的 Gas 需求 high: 无限。
函数 MedicalRecord.getDoctorsNames() 的 Gas 需求高:无限。
函数 MedicalRecord.getNotes() 的 Gas 需求高:无限。
函数 MedicalRecord.giveDoctorAccess(address,bytes32) 的 gas 需求高:无限。
pragma solidity ^0.4.17;
contract MedicalRecord {
struct Doctor {
bytes32 name;
uint id;
}
struct Note {
bytes32 title;
bytes32 note;
}
address public patient;
uint private doctorId;
bytes32[] public doctorsNames;
Note[] notes;
mapping (address => Doctor) private doctors;
modifier onlypatient {
require(msg.sender == patient);
_;
}
modifier isCurrentDoctor {
require(!(doctors[msg.sender].id < doctorId));
_;
}
function MedicalRecord() public {
patient = msg.sender;
doctorId = 0;
}
function giveDoctorAccess(address drAddress, bytes32 name)
public
onlypatient
returns (bytes32)
{
doctors[drAddress] = Doctor (name, doctorId);
doctorId++;
doctorsNames.push(name);
return (name);
}
function getNotes()
view
public
isCurrentDoctor
returns (bytes32[], bytes32[])
{
bytes32[] memory titles = new bytes32[](notes.length);
bytes32[] memory noteTexts = new bytes32[](notes.length);
for (uint i = 0; i < notes.length; i++) {
Note storage snote = notes[i];
titles[i] = snote.title;
noteTexts[i] = snote.note;
}
return (titles, noteTexts);
}
function getDoctorsNames() view public returns (bytes32[]) {
return doctorsNames;
}
function addNote(bytes32 title, bytes32 note) public isCurrentDoctor
{
notes.push(Note({title: title, note:note}));
}
}
谁能告诉我如何改进这一点?
【问题讨论】:
标签: ethereum solidity web3js web3