I am using [email protected] to access my ganache blockchain through localhost. I am new to dapp development and I'm trying to call a function that updates the ganache blockchain through web3 in angular. I have tested my code on the remix ide, as well as truffle console and it's working just fine. My goal is to update the variables in an struct(Evidence) within another struct(Case).
When I call the function from web3 in angular, I get an error: Error: Returned error: VM Exception while processing transaction: revert The error doesn't match with any of the require statements that I have.
My solidity code is as follows:
struct EvidenceDiscovery {
address finder;
uint timeFound;
string fileId;
string fileName;
string title;
string description;
evidenceStatus status; //underReview, approved, rejected
address reviewer;
uint reviewTime;
uint index;
}
struct Case {
uint256 caseNo; //case number
string name; //case name
mapping(uint => EvidenceDiscovery) evidenceList; //evidenceDiscovery list [dFIAddress, name, description, cid, timestamp]
uint edSize;
}
function reviewEvidence(uint256 _caseNo, uint _index, uint _status) public OnlyInvestigators returns(uint){
Case storage c = cases[_caseNo];
uint stat = 2;
require(c.caseNo != 0, "Case does not exist");
EvidenceDiscovery storage e = c.evidenceList[_index];
require(e.finder != msg.sender, "You cannot approve your own evidence");
if(_status == 0){ //Approve
e.status = evidenceStatus.Approved;
e.reviewer = msg.sender;
e.reviewTime = block.timestamp;
str = string.concat(toAsciiString(msg.sender), ": approved evidence for the case");
stat = 0;
}
else if(_status == 1){ //Reject
e.status = evidenceStatus.Rejected;
e.reviewer = msg.sender;
e.reviewTime = block.timestamp;
str = string.concat(toAsciiString(msg.sender), " rejected evidence for the case");
stat = 1;
}
else{
e.status = evidenceStatus.Pending;
}
return stat;
}
I have tried to use .call in the web3Service but it doesn't update the blockchain My web3Service in angular (This is where I get the error message):
public async reviewEvidence(index: number, status: number){
try{
var stat = await this.contract.methods.reviewEvidence(this.caseNumber, index, status).send({from: this.senderAddress});
return stat;
}
catch(error){
console.error('Error reviewing a case: ', error);
}
}
App component code:
public async reviewEvidence(event: Event, index: number, status: number) {
const selectedValue = event as CustomEvent;
console.log('Selected value:', selectedValue.detail.value);
try{
await this.web3.reviewEvidence(index, status)
.then((res: any) => console.log('Review complete', res))
.catch( (error: any) => console.error('Error reviewing evidence in app: ', error));
}
catch(error){
console.error('Error reviewing a case: ', error);
}
try{
this.getEvidenceInfo();
}
catch(error){
console.error("Get evidence error: ", error);
}
}