I have defined struct for saving data to ethereum blockchain. I am using uint to map the data stored with a unique ID. I am using truffle framework to write smart contracts with solidity version: 0.4.24
Here are Structs:
struct Location {
string longitude;
string latitude;
string locationName;
}
struct Farm {
uint farmId;
string farmName;
Location location;
}
struct Grapes {
uint grapesId;
string notes;
uint vintageYear;
address farmOwner;
GrapeState state;
Farm farm;
}
mapping (uint => Farm) farms;
mapping (uint => Location) farmLocation;
mapping (uint => Grapes) grapes;
I am getting an error while writing data to struct:
function harvestGrapes(string _notes, uint _vintageYear, uint farmId) public verifyCaller(deployer) {
previousGrapesId = previousGrapesId + 1;
grapes[previousGrapesId] = Grapes ({
grapesId: previousGrapesId,
notes: _notes,
vintageYear: _vintageYear,
farmOwner: msg.sender,
GrapeState: GrapeState.Harvested,
farm: farms[farmId].farmName
});
emit GrapesHarvested(previousGrapesId);
}
Here is the error log for the function call.
Named argument does not match function declaration.
grapes[previousGrapesId] = Grapes ({
^ (Relevant source part starts here and spans across multiple lines).
,/C/Blockchain/WineSupplyChain/contracts/winebase/SupplyChain.sol:141:19: TypeError: Invalid type for argument in function call. Invalid implicit conversion from string storage ref to struct SupplyChain.Farm memory requested.
farm: farms[farmId].farmName
^--------------------^
farms
???