I have a contract which acts as an auction house. Each Auction is a struct. Therefore, each time a user wants to sell an item, a new Auction struct is created in storage.
This wouldn't be a problem if I stored all the Auctions in one storage
array. However, due to different query reasons, I need to have the same Auction reference, stored within multiple arrays.
I come from a Java/C# background, so in that sense, what makes sense to me is:
- Create an object on heap
- Get the reference to that object
- Add the reference to N arrays
- Changing the object from any of these arrays changes the data on the heap, thus effectively changing it for every array which holds a reference to it
The problem is, I have no idea how to pull this off in Solidity. Here is what my code does:
mapping(uint256 => Auction) allAuctions
keeps track of all auctionsmapping(address => Auction[]) userAuctions
keeps track of all auctions made by a wallet
What I tried to do is the following:
allAuctions[n] = Auction(); // I thought this would make an object "on the heap" and add a reference to the map
userAuctions[wallet].push(allAuctions[n]); // Push the reference from the map into the array
However, when I execute this, it doesn't work. It seems to me that 2 separate structs are being made in the storage, because changing 1 doesn't change the other.
Is there a way to make this work or is my paradigm completely incorrect? Thanks in advance.