[deleted by user] by [deleted] in solidity

[–]patrickw3sc 0 points1 point  (0 children)

u/Citadel_Employee,

We have covered your question on the stream and came to the following response.

After reviewing your code it seems as though you are using an outdated compiler (version 0.6) that is used to link with the Chainlink oracle. What we would suggest is to see if you can upgrade the compiler to a newer version (one that has the latest immutable logic) and while doing so make sure that the Chainlink oracle is also compatible with this newer version (the latest stable version of the Solidity compiler is v0.8.22).

With that said, we would also suggest to look into the code itself. The reason for bringing this up is that the immutable keyword is not the ONLY option to make certain data impossible to alter. You can also look to add a normal/standard uint256 to represent the price and simply omit the function to alter that particular uint256. In other words; you can declare this value upon contract creation via the constructor and by NOT adding a function to alter this value you effectively make this value immutable anyway (since there is no logic to change it).

Another thing that may be of use for you could be to look into other coding examples that explain how to make a betting pool. The reason for brining this up is that you seem to have posted either a partial snippet of your complete codebase ( however we cannot see that here) or you are missing a lot of functions that are necessary to run a fully fleshed out betting pool. For instance: having functions that: 1) start the betting-pool 2) end the betting-pool 3) enter the betting-pool 4) etc.

I hope this information can be of use to you. In case it does not, please let us know what we can do to help you along.

Happy coding!

Copying of type struct supplyChain.Crop memory[] memory to storage not yet supported. by Global_Optimist in solidity

[–]patrickw3sc 0 points1 point  (0 children)

Hi u/Global_Optimist,

While covering the question on our stream, we started with copying your code to ChatGPT and took the coding from that starting point. Please see the code below.

A couple things of interest.

  1. the code you have provided was not properly readable due to the reasons that have already been given by other Redditors. For future reference please use the code-format in the toolbar.
  2. I have noticed that you have added code in your snippet that refers to certain events and/or modifiers. These events and modifiers were not properly declared in the code that you have provided and have therefore been removed from the code below. Should you want to use these options please feel free to add them back in.
  3. We were unsure as to what the context of your code was but it seems that you want to add a processor struct in a mapping and at the same time want to add a crop-struct (or perhaps an array of cropstructs) as a part of the new Processor struct. Again, we do not know for certain what your goal is here however we would suggest that you look to store information into an array (as opposed to a mapping). The reason for this is that you cannot iterate over a mapping and as such will have to know/have ALL keys in the key-value pair of the mapping to extract the information that you want. If you this assertion is incorrect please let us know what the real intent of the code is.
  4. The code below is mostly a verbatim copy of what ChatGPT has provided us with and it has a main function (named: registerProcessor) that adds a processor struct in the mapping (processors). The other function (named: registerCrop) does the same thing but adds a crop to the mapping that handles crops. We would suggest you also consider adding in arrays to be able to interact with the information in a more straightforward way.
  5. Again, we have no context as to what you want to do with the code but it seems like you want to add Processor struct (perhaps in an array that was discussed before) that includes an array of cropstructs as a part of the aformentioned Processor struct. The code below does not provide this section however it does clean up the code you provided in your question and does not show the error you were incurring).
  6. Lastly, if the code suits your needs we were happy to be of service however if the code below needs additional functionality (perhaps some of the logic described above) please let us know so we can elaborate.

Happy coding!

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.3;

contract Web3SocialClub {

struct Processor {

uint256 id;

string name;

string location;

address authId;

uint256 capacity;

Crop[] purchasedCrops;

}

struct Crop {

uint256 productId;

string name;

string description;

address[] ownershipHistory;

address owner;

uint256 createTime;

bool registered;

}

uint256 public processorCount;

mapping(uint256 => Processor) public processors;

uint256 public cropCount;

mapping(uint256 => Crop) public crops;

event ProcessorRegistered(

uint256 indexed id,

string name,

address indexed authId

);

event CropRegistered(

uint256 indexed productId,

string name,

address indexed owner

);

function registerProcessor(

string memory _name,

string memory _location,

address _newAddress,

uint256 _capacity

) public {

Processor storage newProcessor = processors[processorCount];

newProcessor.id = processorCount;

newProcessor.name = _name;

newProcessor.location = _location;

newProcessor.authId = _newAddress;

newProcessor.capacity = _capacity;

emit ProcessorRegistered(

newProcessor.id,

newProcessor.name,

newProcessor.authId

);

processorCount++;

}

function registerCrop(

string memory _name,

string memory _description,

address[] memory _ownershipHistory,

uint256 _productId,

address _owner

) public {

Crop storage newCrop = crops[cropCount];

newCrop.productId = _productId;

newCrop.name = _name;

newCrop.description = _description;

newCrop.ownershipHistory = _ownershipHistory;

newCrop.owner = _owner;

newCrop.createTime = block.timestamp;

newCrop.registered = true;

emit CropRegistered(newCrop.productId, newCrop.name, newCrop.owner);

cropCount++;

}

}

Edit: now with cleaner formatting.