pragma solidity ^0.6.0;
contract SupplyChain {
event Added(uint256 index);
struct State{
string description;
address person;
}
struct Product{
address creator;
string productName;
uint256 productId;
string date;
uint256 totalStates;
mapping (uint256 => State) positions;
}
mapping(uint => Product) allProducts;
uint256 items=0;
function concat(string memory _a, string memory _b) public returns (string memory){
bytes memory bytes_a = bytes(_a);
bytes memory bytes_b = bytes(_b);
string memory length_ab = new string(bytes_a.length + bytes_b.length);
bytes memory bytes_c = bytes(length_ab);
uint k = 0;
for (uint i = 0; i < bytes_a.length; i++) bytes_c[k++] = bytes_a[i];
for (uint i = 0; i < bytes_b.length; i++) bytes_c[k++] = bytes_b[i];
return string(bytes_c);
}
function newItem(string memory _text, string memory _date) public returns (bool) {
Product memory newItem = Product({creator: msg.sender, totalStates: 0,productName: _text, productId: items, date: _date});
allProducts[items]=newItem;
items = items+1;
emit Added(items-1);
return true;
}
function addState(uint _productId, string memory info) public returns (string memory) {
require(_productId<=items);
State memory newState = State({person: msg.sender, description: info});
allProducts[_productId].positions[ allProducts[_productId].totalStates ]=newState;
allProducts[_productId].totalStates = allProducts[_productId].totalStates +1;
return info;
}
function searchProduct(uint _productId) public returns (string memory) {
require(_productId<=items);
string memory output="Product Name: ";
output=concat(output, allProducts[_productId].productName);
output=concat(output, "<br>Manufacture Date: ");
output=concat(output, allProducts[_productId].date);
for (uint256 j=0; j<allProducts[_productId].totalStates; j++){
output=concat(output, allProducts[_productId].positions[j].description);
}
return output;
}
}
Errors I am receiving is:-
1.contracts/test.sol:36:9: Warning: This declaration shadows an existing declaration. Product memory newItem = Product({creator: msg.sender, totalStates: 0,productName: _text, productId: items, date: _date}); ^--------------------^ contracts/test.sol:35:5: The shadowed declaration is here: function newItem(string memory _text, string memory _date) public returns (bool) { ^ (Relevant source part starts here and spans across multiple lines).
- contracts/test.sol:24:5: Warning: Function state mutability can be restricted to pure function concat(string memory _a, string memory _b) public returns (string memory){ ^ (Relevant source part starts here and spans across multiple lines).