encointer / pallets

all application-specific pallets for encointer
GNU General Public License v3.0
19 stars 3 forks source link

[bazaar] improve `delete_offering` function. #57

Open clangenb opened 3 years ago

clangenb commented 3 years ago

The offering registry is a double map with the second key being the OfferingId, a strict monotonic counter for the number of offerings per business.

We don't have an inverse mapping that can somehow retrieve the OfferingID for a given offering. However, this is not necessarily needed for the current use cases because we usually want to retrieve all offerings for a given business. Then we can simply iterate from 1 to the number of offerings registered on said business while map the OfferingId -> Offering client side.

However, we can't simply iterate after we have deleted an offering because we have 'holes' in our map, i.e., certain keys < number of offerings that don't yield a value. Hence, we should employ the 'swap and pop' method when we delete keys the same way as we did it in the pallet-teerex.

https://github.com/integritee-network/pallet-teerex/blob/fab14a05744034c7a29fd6dc6f4437cb2272a7aa/src/lib.rs#L267

EDIT: The problem with iteration only exists when iterating via the storage rpc. The custom rpc iterates via the storage maps interface. There it poses no problem. Regardless, I think it makes sense to employ to swap and pop method.

clangenb commented 3 years ago

Hmm, I just realize that we probably need somehow an extra mapping Offering -> OfferingId because the custom rpc's that return an offering make no guarantee about the order in which offerings are returned. Hence, I don't see a way to get an offering's OfferingsId currently.