Skip to content

Commit

Permalink
contract updates for crescendo (#20)
Browse files Browse the repository at this point in the history
* contract updates for crescendo
  • Loading branch information
austinkline authored Jun 9, 2024
1 parent 8258db2 commit 8c119a5
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 207 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ^18
- name: Install Flow dependencies
run: npm i
- name: Install Flow CLI
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.8.0
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
- name: Run tests
run: sh ./run-tests.sh
26 changes: 13 additions & 13 deletions contracts/FLOATRaffleSource.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@ 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
access(all) contract FLOATRaffleSource {
access(all) resource RaffleSource {
access(all) let eventCap: Capability<&FLOAT.FLOATEvents>
access(all) let eventId: UInt64

pub fun getEntries(): [AnyStruct] {
access(all) fun getEntries(): [AnyStruct] {
return self.borrowEvent().getClaims().values
}

pub fun getEntryCount(): Int {
access(all) fun getEntryCount(): Int {
return self.borrowEvent().getClaims().length
}

pub fun getEntryAt(index: Int): AnyStruct {
access(all) fun getEntryAt(index: Int): AnyStruct {
return self.borrowEvent().getClaims()[UInt64(index)]
}

pub fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
access(FlowtyRaffles.Reveal) fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
return
}

pub fun addEntry(_ v: AnyStruct) {
access(FlowtyRaffles.Add) fun addEntry(_ v: AnyStruct) {
panic("addEntry is not supported on FLOATRaffleSource")
}

pub fun addEntries(_ v: [AnyStruct]) {
access(FlowtyRaffles.Add) fun addEntries(_ v: [AnyStruct]) {
panic("addEntries is not supported on FLOATRaffleSource")
}

pub fun borrowEvent(): &FLOAT.FLOATEvent{FLOAT.FLOATEventPublic} {
access(all) fun borrowEvent(): &FLOAT.FLOATEvent {
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) {
init(eventCap: Capability<&FLOAT.FLOATEvents>, eventId: UInt64) {
self.eventCap = eventCap
self.eventId = eventId

Expand All @@ -47,7 +47,7 @@ pub contract FLOATRaffleSource {
}
}

pub fun createRaffleSource(eventCap: Capability<&FLOAT.FLOATEvents{FLOAT.FLOATEventsPublic}>, eventId: UInt64): @RaffleSource {
access(all) fun createRaffleSource(eventCap: Capability<&FLOAT.FLOATEvents>, eventId: UInt64): @RaffleSource {
return <- create RaffleSource(eventCap: eventCap, eventId: eventId)
}
}
26 changes: 13 additions & 13 deletions contracts/FlowtyRaffleSource.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ In addition to entryType, a field called `removeAfterReveal` is also provided, w
from the entries array any time a reveal is performed. This is useful for cases where you don't want the same entry to be able to be drawn
multiple times.
*/
pub contract FlowtyRaffleSource {
pub resource AnyStructRaffleSource: FlowtyRaffles.RaffleSourcePublic, FlowtyRaffles.RaffleSourcePrivate {
pub let entries: [AnyStruct]
pub let entryType: Type
pub let removeAfterReveal: Bool
access(all) contract FlowtyRaffleSource {
access(all) resource AnyStructRaffleSource: FlowtyRaffles.RaffleSourcePublic, FlowtyRaffles.RaffleSourcePrivate {
access(all) let entries: [AnyStruct]
access(all) let entryType: Type
access(all) let removeAfterReveal: Bool

pub fun getEntryType(): Type {
access(all) fun getEntryType(): Type {
return self.entryType
}

pub fun getEntryAt(index: Int): AnyStruct {
access(all) fun getEntryAt(index: Int): AnyStruct {
return self.entries[index]
}

pub fun getEntries(): [AnyStruct] {
access(all) fun getEntries(): [AnyStruct] {
return self.entries
}

pub fun getEntryCount(): Int {
access(all) fun getEntryCount(): Int {
return self.entries.length
}

pub fun addEntry(_ v: AnyStruct) {
access(FlowtyRaffles.Add) fun addEntry(_ v: AnyStruct) {
pre {
v.getType() == self.entryType: "incorrect entry type"
}

self.entries.append(v)
}

pub fun addEntries(_ v: [AnyStruct]) {
access(FlowtyRaffles.Add) fun addEntries(_ v: [AnyStruct]) {
pre {
VariableSizedArrayType(self.entryType) == v.getType(): "incorrect array type"
}

self.entries.appendAll(v)
}

pub fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
access(contract) fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
if !self.removeAfterReveal {
return
}
Expand All @@ -66,7 +66,7 @@ pub contract FlowtyRaffleSource {
}
}

pub fun createRaffleSource(entryType: Type, removeAfterReveal: Bool): @AnyStructRaffleSource {
access(all) fun createRaffleSource(entryType: Type, removeAfterReveal: Bool): @AnyStructRaffleSource {
pre {
entryType.isSubtype(of: Type<AnyStruct>()): "entry type must be a subtype of AnyStruct"
}
Expand Down
Loading

0 comments on commit 8c119a5

Please sign in to comment.