Reputation: 85
I am creating a smart contract that aims to provide a trustworthy way of getting paid on completion of project, but I am having some issues.
So far, there are three major functions: createProject(), joinProject() and submitProject()
My project struct is as follows:
//Project Model
struct project{
uint pid;
address clientAddr;
string name;
uint bidAmount;
string description;
uint deadline; //record unix timestamp
address freelancerAddr;
bool isOpen;
bool isSubmitted;
bool isAccepted;
}
Now I create a project with the client address:
function createProject( uint _pid, string memory _name,
string memory _description,
uint _deadline) OnlyClient public payable{
require(msg.value >= 50,"insufficient funds");
project storage prj = projects[_pid];
prj.pid = _pid;
prj.clientAddr = msg.sender;
prj.name = _name;
prj.bidAmount = msg.value;
prj.description = _description;
prj.deadline = _deadline;
prj.isOpen = true;
prj.isSubmitted = false;
prj.isAccepted = false;
projectIDs.push(_pid) -1;
listProjects.push(_name) -1;
emit LogRegisterProject(_pid, prj.clientAddr, _name, prj.bidAmount, _description, _deadline, prj.isOpen);
}
But the freelanceAddr field is still empty. It's value is only initialized by the following function when a freelancer joins the project:
function joinProject (uint _pid, address _freelancerAddr) OnlyFreelancer public {
require(projects[_pid].isOpen=true,"Project is not open yet");
projects[_pid].isOpen = false;
projects[_pid].freelancerAddr = _freelancerAddr;
emit LogJoinProject(msg.sender, _pid);
}
Now, I want to submit the project. But before I do that, I want to check that the person who called the joinProject and the one trying to call submitProject is the same one. So I try doing the following:
function submitProject(uint _pid, address _freelancerAddr) OnlyFreelancer public{
require(projects[_pid].freelancerAddr = msg.sender, "You haven't joined the project");
projects[_pid].isSubmitted = true;
}
But it gives me a TypeError: No matching declaration after argument-dependent lookup.
I can however see that the changes have been saved when I run the getProjectDetails() function after joining a project, and all the states have been saved as well. But it's having problems transferring that value to the associated call in submitProject().
I have seen that Solidity does not allow "null" initialization, so what can I do to resolve this error, or is there any alternative to doing this for the verification?
Upvotes: 2
Views: 445
Reputation: 85
Looks like it was a minor syntax error.
I'd been doing:
require(projects[_pid].freelancerAddr = msg.sender, "You haven't joined the project");
But, there should have been "==".:
require(projects[_pid].freelancerAddr = msg.sender, "You haven't joined the project");
I'm very new to Solidity, and had seen single "=" being used in other similar comparisons, so had just been doing the same.
Upvotes: 0