Anish-Agnihotri / MultiRaffle

NFT distribution with (1) randomized, multi-winner raffles and (2) bulk on-chain metadata generation.
GNU Affero General Public License v3.0
269 stars 52 forks source link

How to determine which tickets are owned by each address? #5

Open chrishol opened 3 years ago

chrishol commented 3 years ago

Thanks for sharing this @Anish-Agnihotri - really great ideas and helpful examples.

My question: The design of the claimRaffle function seems to require the caller to know where their entry lies in the raffleEntries array. Is the idea that the results could be indexed once and then provided to customers via a frontend UI?

Ideally you'd have some way of quickly finding the indices by address, but storing that might get expensive quickly.

https://github.com/Anish-Agnihotri/MultiRaffle/blob/a468d0029138ec0166e9e43697c4053c340d7e13/src/MultiRaffle.sol#L195

thomasdurand98 commented 3 years ago

Yeah I'm looking for that to

pauliax commented 3 years ago

Probably you need to find them off-chain but that may be a bit daunting. hardhat test example:

  async function getWinningIndices(address) {
    const indices = [];
    for (let i = 0; i < availableSupply; i++) {
      const entryAddress = await raffleContract.raffleEntries(i);
      if (entryAddress === address) {
        indices.push(i);
      }
    }
    return indices;
  }