I've deployed my smart contract to Rinkeby test net. The "addProject" function works fine.
But when I try the "addProjectFile" function I got error.
"Error: gas required exceeds allowance or always failing transaction"
The code:
pragma solidity ^0.4.18;
contract MyProjectManger {
address public owner;
mapping (uint => MyProject) public myProjects;
uint projectIndex;
mapping (uint => uint) public projectFileIndexes;
struct File {
string url;
string fileHash;
}
struct MyProject {
bytes32 id;
string name;
mapping (uint => File) projectFiles;
}
function MyProjectManger() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function addProject(bytes32 id, string name) public onlyOwner returns(uint projectId) {
projectId = projectIndex;
myProjects[projectIndex] = MyProject(id, name);
projectIndex++;
}
function addProjectFile(string url, string fileHash, uint projectKey) public onlyOwner returns(uint fileId) {
uint projectFileIndex = projectFileIndexes[projectKey];
MyProject storage project = myProjects[projectIndex];
require(project.id[0] != 0);
fileId = projectFileIndex;
project.projectFiles[projectFileIndex] = File(url, fileHash);
projectFileIndex++;
}
function remove() onlyOwner public {
selfdestruct(msg.sender);
}
// to receive ether
function() payable public { }
}
I did get "Gas requirement of functions" warnings for those two addXXX
functions. But I don't understand, I don't have loops in those two functions, why gas requirement should be an issue?