From 6ade393c2bbb1e71d7766122755cfd3491d679eb Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Sun, 17 Dec 2023 18:52:29 -0800 Subject: [PATCH] raffle source for FLOAT events --- contracts/FLOATRaffleSource.cdc | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 contracts/FLOATRaffleSource.cdc diff --git a/contracts/FLOATRaffleSource.cdc b/contracts/FLOATRaffleSource.cdc new file mode 100644 index 0000000..f2eac4a --- /dev/null +++ b/contracts/FLOATRaffleSource.cdc @@ -0,0 +1,42 @@ +import "FlowtyRaffles" +import "FLOAT" + +pub contract FLOATRaffleSource { + pub resource RaffleSource { + pub let eventCap: Capability<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic}> + pub let eventId: UInt64 + + pub fun getEntries(): [AnyStruct] { + return self.borrowEvent().getClaims().values + } + + pub fun getEntryCount(): Int { + return self.borrowEvent().getClaims().length + } + + pub fun getEntryAt(index: Int): AnyStruct { + return self.borrowEvent().getClaims()[UInt64(index)] + } + + pub fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) { + return + } + + pub fun borrowEvent(): &FLOAT.FLOATEvent{FLOAT.FLOATEventPublic} { + let cap = self.eventCap.borrow() ?? panic("eventCap is not valid") + return cap.borrowPublicEventRef(eventId: self.eventId) ?? panic("invalid event id") + } + + init(eventCap: Capability<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic}>, eventId: UInt64) { + self.eventCap = eventCap + self.eventId = eventId + + // ensure we can borrow the event. This will panic if the we aren't able to + self.borrowEvent() + } + } + + pub fun createRaffleSource(eventCap: Capability<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic}>, eventId: UInt64): @RaffleSource { + return <- create RaffleSource(eventCap: eventCap, eventId: eventId) + } +} \ No newline at end of file