-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
791cf14
commit 6ade393
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |