-
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.
raffle source for FLOAT events (#13)
* raffle source for FLOAT events * add some missing methods to the float raffle source * add comments
- Loading branch information
1 parent
791cf14
commit 2758355
Showing
3 changed files
with
75 additions
and
9 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,53 @@ | ||
import "FlowtyRaffles" | ||
import "FLOAT" | ||
|
||
/* | ||
FLOATRaffleSource - A Raffle source implementation which uses the claims on a FLOAT as the source of a drawing. | ||
*/ | ||
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 addEntry(_ v: AnyStruct) { | ||
panic("addEntry is not supported on FLOATRaffleSource") | ||
} | ||
|
||
pub fun addEntries(_ v: [AnyStruct]) { | ||
panic("addEntries is not supported on FLOATRaffleSource") | ||
} | ||
|
||
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) | ||
} | ||
} |
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
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