Skip to content

Commit

Permalink
add methods to borrow an auth version of each phase detail interface
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Apr 7, 2024
1 parent 9bbacbf commit 0a278a8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions contracts/FlowtyDrops.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub contract FlowtyDrops {
// Interface to expose all the components necessary to participate in a drop
// and to ask questions about a drop.
pub resource interface DropPublic {
pub fun borrowPhase(index: Int): &{PhasePublic}
pub fun borrowPhasePublic(index: Int): &{PhasePublic}
pub fun borrowActivePhases(): [&{PhasePublic}]
pub fun borrowAllPhases(): [&{PhasePublic}]
pub fun mint(
Expand Down Expand Up @@ -94,15 +94,20 @@ pub contract FlowtyDrops {
return <- payment
}

pub fun borrowPhase(index: Int): &{PhasePublic} {
pub fun borrowPhase(index: Int): &Phase {
return &self.phases[index] as! &Phase
}


pub fun borrowPhasePublic(index: Int): &{PhasePublic} {
return &self.phases[index] as! &{PhasePublic}
}

pub fun borrowActivePhases(): [&{PhasePublic}] {
let arr: [&{PhasePublic}] = []
var count = 0
while count < self.phases.length {
let ref = self.borrowPhase(index: count)
let ref = self.borrowPhasePublic(index: count)
let switch = ref.getDetails().switch
if switch.hasStarted() && !switch.hasEnded() {
arr.append(ref)
Expand All @@ -118,7 +123,7 @@ pub contract FlowtyDrops {
let arr: [&{PhasePublic}] = []
var count = 0
while count < self.phases.length {
let ref = self.borrowPhase(index: count)
let ref = self.borrowPhasePublic(index: count)
arr.append(ref)
count = count + 1
}
Expand Down Expand Up @@ -212,6 +217,18 @@ pub contract FlowtyDrops {
return self.details
}

pub fun borrowSwitchAuth(): auth &{Switch} {
return &self.details.switch as! auth &{Switch}
}

pub fun borrowPricerAuth(): auth &{Pricer} {
return &self.details.pricer as! auth &{Pricer}
}

pub fun borrowAddressVerifier(): auth &{AddressVerifier} {
return &self.details.addressVerifier as! auth &{AddressVerifier}
}

init(details: PhaseDetails) {
self.details = details
}
Expand Down

0 comments on commit 0a278a8

Please sign in to comment.