draffle-io / draffle

dRaffle is a decentralized raffle protocol on Solana
83 stars 82 forks source link

General Query #3

Open Vipulsin13 opened 2 years ago

Vipulsin13 commented 2 years ago

Hello, I just want to know how exactly the winner accounts are being fetched from among the entrants in Raffle account.. I am working on a similar yet simple implementation.. I have a vector of pubkeys in the data field of the RaffleAccount account.. For now I just want 3 random elements based on random indexing of the vector.. Now if I do this: const winnerOne = await program.account.raffleAccount.all(); I can get all the data in the account but I just want a few random ones and that too the selection logic (which for now is as simple as getting the elements at 2nd, 3rd and 5th index, or any indexes for that matter) should be on-chain.. So initially what I thought of was assigning the values to three variables in the function and fetching those variables on to the frontend.. But got to know that returning values is not supported by Anchor at present.. So I made that account a PDA as suggested by a few on discord but I don't think it solves my issue because it still has the data field which is a vector of pubkeys and I still need to fetch only 3 elements on those indexes which can't be written inside the function body as I cannot simply get those variables to the frontend.. What can I do to resolve this.. I'm hoping that this question makes sense.. If not, please tell me and I would frame it again but don't close the issue.. I really need to solve this.. It is a very urgent work..