I’m building a smart contract marketplace system which generates multiple other smart contracts (offers, products, seller, etc…).
For the sake of my issue I will briefly introduce one of them which is the Offer Contract.
This contract has variables : clientAddress, sellerAddress, price, productAddress, etc …
And some methods : Pay (for client), updatePrice (for auditor), etc…
As of today only my centralized database can keep track of the contracts actors. The actors are the ones that can interact with it, in the offer contract for example they are two actors the client which can pay and the seller which can updatePrice.
What i would like is to find an elegant/efficient solution which would allow me to decentrally retrieve all contracts from an actor’s address. For example to be able to find all the offers contracts of a seller/client based on the variables sellerAddress and clientAddress.
Right now I have a factory contracts which holds every generated contracts address in a corresponding variable, offers contract’s addresses are stored within a
offers variable for example. These variables allow me to check if an offer is real factory is my source of truth for the rest of my system.
So let’s get back to the main problem.
There are two things that my factory contract should be able to do.
Verify if a contract is “real”/approved/generated within my system which it is already doing with my variable offers (EnumerableSet).
And Sending me all contract’s addresses for an actor, which it doesn’t do as of now.
The only solution I found would be to have a
mapping(address => address) offers but this seems a bit heavy. To check if an offer is real I would have to make a function which takes two arguments, first the offer contract’s address and in second an actor address, then iterate through all the address to finally confirm its existence, as you can guess it’s not scalable at all and in the case where lots of offers would be made (which can happen pretty fast) it would take tremendous time.
One would propose to go with an EnumerableSet (from OpenZeppelin) which allow me to check efficiently if a contract exists but I cannot simply return the list.
Another solution would be to have two variable
EnumerableSet.AddressSet offers to simply check if a contract exists in my factory and is therefore “real”, and a second variable
mapping(address => address) offersList which simply allow me to return the list of offers for an actor, but once again it seems pretty heavy for a contract.
As you can see the problem is a bit complex…
So I was wondering if there were some ways from a list of contract’s address to fast search amongst multiple contracts, like some sort of public indexed variable or so ?
As you see this topic is pretty specific and finding help by searching was not good enough so if you have any ideas or leads i could follow I would be extremely thankful