Skip to content

Commit

Permalink
raffle source for FLOAT events
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Dec 18, 2023
1 parent 791cf14 commit 6ade393
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions contracts/FLOATRaffleSource.cdc
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 6ade393

Please sign in to comment.