Skip to content

Commit

Permalink
rename switch -> switcher to avoid reserved word conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Apr 10, 2024
1 parent 6d42346 commit 4d5cf05
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 65 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FlowtyDrops is made up of a few core resources and structs:
3. @Container - Holds Drop resources in it.
4. @{Minter} - A resource interface that creators can implement to be compatible with FlowtyDrops. When constructing a drop, you must
supply a `Capability<&{Minter}>` to it.
5. {Switch} - A struct interface that is responsible for whether a phase is active or not. For example, one implementation could be configured
5. {Switcher} - A struct interface that is responsible for whether a phase is active or not. For example, one implementation could be configured
to start a phase at a time in the future, while another could turn start based on block height.
6. {AddressVerifier} - A struct interface that is responsible for determining if an account is permitted to mint or not. For example,
one implementation might permit any account to mint as many as it wants, while another might check an allow-list.
Expand All @@ -38,7 +38,7 @@ FlowtyDrops is made up of a few core resources and structs:
are responsible for handling how much an attempted mint should cost.
For example, you might make a drop free, or might configure a drop to
be a flat fee regardless of how many are being minted at once.
5. FlowtySwitches - Implementations of the Switch struct interface.
Switch are responsible for flagging if a drop is live or not. For
5. FlowtySwitchers - Implementations of the Switcher struct interface.
Switchers are responsible for flagging if a drop is live or not. For
example, a drop might go live a certain unix timestamp and end at a
future date, or it might be on perpetually until manually turned off.
12 changes: 6 additions & 6 deletions contracts/DropFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "FungibleToken"
import "MetadataViews"

import "FlowtyDrops"
import "FlowtySwitches"
import "FlowtySwitchers"
import "FlowtyAddressVerifiers"
import "FlowtyPricers"

Expand All @@ -21,15 +21,15 @@ pub contract DropFactory {
}

// This drop is always on and never ends.
let switch = FlowtySwitches.AlwaysOn()
let switcher = FlowtySwitchers.AlwaysOn()

// All addresses are allowed to participate
let addressVerifier = FlowtyAddressVerifiers.AllowAll(maxPerMint: 10)

// The cost of each mint is the same, and only permits one token type as payment
let pricer = FlowtyPricers.FlatPrice(price: price, paymentTokenType: paymentTokenType)

let phaseDetails = FlowtyDrops.PhaseDetails(switch: switch, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phaseDetails = FlowtyDrops.PhaseDetails(switcher: switcher, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phase <- FlowtyDrops.createPhase(details: phaseDetails)

let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05)
Expand All @@ -50,16 +50,16 @@ pub contract DropFactory {
paymentTokenType.isSubtype(of: Type<@FungibleToken.Vault>()): "paymentTokenType must be a FungibleToken"
}

// This switch turns on at a set unix timestamp (or is on by default if nil), and ends at the specified end date if provided
let switch = FlowtySwitches.TimestampSwitch(start: startUnix, end: endUnix)
// This switcher turns on at a set unix timestamp (or is on by default if nil), and ends at the specified end date if provided
let switcher = FlowtySwitchers.TimestampSwitch(start: startUnix, end: endUnix)

// All addresses are allowed to participate
let addressVerifier = FlowtyAddressVerifiers.AllowAll(maxPerMint: 10)

// The cost of each mint is the same, and only permits one token type as payment
let pricer = FlowtyPricers.FlatPrice(price: price, paymentTokenType: paymentTokenType)

let phaseDetails = FlowtyDrops.PhaseDetails(switch: switch, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phaseDetails = FlowtyDrops.PhaseDetails(switcher: switcher, display: nil, pricer: pricer, addressVerifier: addressVerifier)
let phase <- FlowtyDrops.createPhase(details: phaseDetails)

let dropDetails = FlowtyDrops.DropDetails(display: dropDisplay, medias: nil, commissionRate: 0.05)
Expand Down
32 changes: 16 additions & 16 deletions contracts/FlowtyDrops.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub contract FlowtyDrops {
var count = 0
while count < self.phases.length {
let ref = self.borrowPhasePublic(index: count)
let switch = ref.getDetails().switch
if switch.hasStarted() && !switch.hasEnded() {
let switcher = ref.getDetails().switcher
if switcher.hasStarted() && !switcher.hasEnded() {
arr.append(ref)
}

Expand Down Expand Up @@ -141,7 +141,7 @@ pub contract FlowtyDrops {
dropAddress: self.owner!.address,
id: phase.uuid,
index: self.phases.length,
switcherType: phase.details.switch.getType().identifier,
switcherType: phase.details.switcher.getType().identifier,
pricerType: phase.details.pricer.getType().identifier,
addressVerifierType: phase.details.addressVerifier.getType().identifier
)
Expand Down Expand Up @@ -203,13 +203,13 @@ pub contract FlowtyDrops {
}
}

// A switch represents a phase being on or off, and holds information
// A switcher represents a phase being on or off, and holds information
// about whether a phase has started or not.
pub struct interface Switch {
// Signal that a phase has started. If the phase has not ended, it means that this switch's phase
pub struct interface Switcher {
// Signal that a phase has started. If the phase has not ended, it means that this switcher's phase
// is active
pub fun hasStarted(): Bool
// Signal that a phase has ended. If a switch has ended, minting will not work. That could mean
// Signal that a phase has ended. If a switcher has ended, minting will not work. That could mean
// the drop is over, or it could mean another phase has begun.
pub fun hasEnded(): Bool

Expand All @@ -225,15 +225,15 @@ pub contract FlowtyDrops {

// returns whether this phase of a drop has started.
pub fun isActive(): Bool {
return self.details.switch.hasStarted() && !self.details.switch.hasEnded()
return self.details.switcher.hasStarted() && !self.details.switcher.hasEnded()

Check warning on line 228 in contracts/FlowtyDrops.cdc

View check run for this annotation

Codecov / codecov/patch

contracts/FlowtyDrops.cdc#L228

Added line #L228 was not covered by tests
}

pub fun getDetails(): PhaseDetails {
return self.details
}

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

pub fun borrowPricerAuth(): auth &{Pricer} {
Expand Down Expand Up @@ -261,7 +261,7 @@ pub contract FlowtyDrops {

pub struct PhaseDetails {
// handles whether a phase is on or not
pub let switch: {Switch}
pub let switcher: {Switcher}

// display information about a phase
pub let display: MetadataViews.Display?
Expand All @@ -275,8 +275,8 @@ pub contract FlowtyDrops {
// placecholder data dictionary to allow new fields to be accessed
pub let data: {String: AnyStruct}

init(switch: {Switch}, display: MetadataViews.Display?, pricer: {Pricer}, addressVerifier: {AddressVerifier}) {
self.switch = switch
init(switcher: {Switcher}, display: MetadataViews.Display?, pricer: {Pricer}, addressVerifier: {AddressVerifier}) {
self.switcher = switcher
self.display = display
self.pricer = pricer
self.addressVerifier = addressVerifier
Expand All @@ -303,7 +303,7 @@ pub contract FlowtyDrops {
pub resource interface Minter {
pub fun mint(payment: @FungibleToken.Vault, amount: Int, phase: &Phase, data: {String: AnyStruct}): @[NonFungibleToken.NFT] {
post {
phase.details.switch.hasStarted() && !phase.details.switch.hasEnded(): "phase is not active"
phase.details.switcher.hasStarted() && !phase.details.switcher.hasEnded(): "phase is not active"
result.length == amount: "incorrect number of items returned"
}
}
Expand Down Expand Up @@ -348,8 +348,8 @@ pub contract FlowtyDrops {
name: details.display.name,
description: details.display.description,
imageUrl: details.display.thumbnail.uri(),
start: firstPhaseDetails.switch.getStart(),
end: firstPhaseDetails.switch.getEnd()
start: firstPhaseDetails.switcher.getStart(),
end: firstPhaseDetails.switcher.getEnd()
)
destroy self.drops.insert(key: drop.uuid, <-drop)
}
Expand Down
18 changes: 9 additions & 9 deletions contracts/FlowtySwitches.cdc → contracts/FlowtySwitchers.cdc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "FlowtyDrops"

/*
This contract contains implementations for the FlowtyDrops.Switch struct interface.
This contract contains implementations for the FlowtyDrops.Switcher struct interface.
You can use these implementations, or your own, for switches when configuring a drop
*/
pub contract FlowtySwitches {
pub contract FlowtySwitchers {
/*
The AlwaysOn Switch is always on and never ends.
The AlwaysOn Switcher is always on and never ends.
*/
pub struct AlwaysOn: FlowtyDrops.Switch {
pub struct AlwaysOn: FlowtyDrops.Switcher {
pub fun hasStarted(): Bool {
return true
}
Expand All @@ -27,10 +27,10 @@ pub contract FlowtySwitches {
}

/*
The manual switch is used to explicitly toggle a drop.
This version of switch allows a creator to turn on or off a drop at will
The manual switcher is used to explicitly toggle a drop.
This version of switcher allows a creator to turn on or off a drop at will
*/
pub struct ManualSwitch: FlowtyDrops.Switch {
pub struct ManualSwitch: FlowtyDrops.Switcher {
access(self) var started: Bool
access(self) var ended: Bool

Expand Down Expand Up @@ -66,9 +66,9 @@ pub contract FlowtySwitches {

/*
TimestampSwitch uses block timestamps to determine if a phase or drop is live or not.
A timestamp switch has a start and an end time.
A timestamp switcher has a start and an end time.
*/
pub struct TimestampSwitch: FlowtyDrops.Switch {
pub struct TimestampSwitch: FlowtyDrops.Switcher {
pub var start: UInt64?
pub var end: UInt64?

Expand Down
2 changes: 1 addition & 1 deletion contracts/nft/OpenEditionNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "FlowToken"
import "ExampleToken"

import "FlowtyDrops"
import "FlowtySwitches"
import "FlowtySwitchers"
import "FlowtyAddressVerifiers"
import "FlowtyPricers"
import "DropFactory"
Expand Down
8 changes: 4 additions & 4 deletions flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"testing": "0x0000000000000006"
}
},
"FlowtySwitches": {
"source": "./contracts/FlowtySwitches.cdc",
"FlowtySwitchers": {
"source": "./contracts/FlowtySwitchers.cdc",
"aliases": {
"testing": "0x0000000000000006"
}
Expand Down Expand Up @@ -144,7 +144,7 @@
"emulator": {
"emulator-account": [
"FlowtyDrops",
"FlowtySwitches",
"FlowtySwitchers",
"FlowtyAddressVerifiers",
"FlowtyPricers",
"DropFactory",
Expand All @@ -165,7 +165,7 @@
"testnet": {
"flowty-drops-testnet": [
"FlowtyDrops",
"FlowtySwitches",
"FlowtySwitchers",
"FlowtyAddressVerifiers",
"FlowtyPricers",
"DropFactory"
Expand Down
2 changes: 1 addition & 1 deletion scripts/has_phase_ended.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, pha

let phase = drop.borrowPhasePublic(index: phaseIndex)

return phase.getDetails().switch.hasEnded()
return phase.getDetails().switcher.hasEnded()
}
2 changes: 1 addition & 1 deletion scripts/has_phase_started.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, pha

let phase = drop.borrowPhasePublic(index: phaseIndex)

return phase.getDetails().switch.hasStarted()
return phase.getDetails().switcher.hasStarted()
}
2 changes: 1 addition & 1 deletion scripts/import_all.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "FlowtyDrops"
import "FlowtyAddressVerifiers"
import "FlowtySwitches"
import "FlowtySwitchers"
import "FlowtyPricers"
import "OpenEditionNFT"

Expand Down
36 changes: 18 additions & 18 deletions tests/FlowtySwitches_tests.cdc
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import Test
import "test_helpers.cdc"
import "FlowtySwitches"
import "FlowtySwitchers"

pub fun setup() {
deployAll()
}

pub fun test_FlowtySwitches_AlwaysOn() {
let s = FlowtySwitches.AlwaysOn()
Test.assert(s.hasStarted(), message: "AlwaysOn switch should always be started")
Test.assert(!s.hasEnded(), message: "AlwaysOn switch never ends")
pub fun test_FlowtySwitchers_AlwaysOn() {
let s = FlowtySwitchers.AlwaysOn()
Test.assert(s.hasStarted(), message: "AlwaysOn switcher should always be started")
Test.assert(!s.hasEnded(), message: "AlwaysOn switcher never ends")

Test.assertEqual(nil, s.getStart())
Test.assertEqual(nil, s.getEnd())
}

pub fun test_FlowtySwitches_ManualSwitch() {
let s = FlowtySwitches.ManualSwitch()
pub fun test_FlowtySwitchers_ManualSwitch() {
let s = FlowtySwitchers.ManualSwitch()

Test.assertEqual(false, s.hasStarted())
Test.assertEqual(false, s.hasEnded())
Test.assertEqual(nil, s.getStart())
Test.assertEqual(nil, s.getEnd())

// now turn the switch on
// now turn the switcher on
s.setStarted(true)
Test.assertEqual(true, s.hasStarted())
Test.assertEqual(false, s.hasEnded())
Expand All @@ -33,9 +33,9 @@ pub fun test_FlowtySwitches_ManualSwitch() {
Test.assertEqual(true, s.hasEnded())
}

pub fun test_FlowtySwitches_TimestampSwitch_StartIsNil() {
pub fun test_FlowtySwitchers_TimestampSwitch_StartIsNil() {
let end = UInt64(getCurrentBlock().timestamp) + 10
let s = FlowtySwitches.TimestampSwitch(start: nil, end: end)
let s = FlowtySwitchers.TimestampSwitch(start: nil, end: end)

Test.assertEqual(true, s.hasStarted())
Test.assertEqual(nil, s.getStart())
Expand All @@ -44,10 +44,10 @@ pub fun test_FlowtySwitches_TimestampSwitch_StartIsNil() {
Test.assertEqual(end, s.getEnd()!)
}

pub fun test_FlowtySwitches_TimestampSwitch_StartAfterNow() {
pub fun test_FlowtySwitchers_TimestampSwitch_StartAfterNow() {
let start = UInt64(getCurrentBlock().timestamp) + 1
let end = UInt64(getCurrentBlock().timestamp) + 10
let s = FlowtySwitches.TimestampSwitch(start: start, end: end)
let s = FlowtySwitchers.TimestampSwitch(start: start, end: end)

Test.assertEqual(false, s.hasStarted())
Test.assertEqual(start, s.getStart()!)
Expand All @@ -56,10 +56,10 @@ pub fun test_FlowtySwitches_TimestampSwitch_StartAfterNow() {
Test.assertEqual(end, s.getEnd()!)
}

pub fun test_FlowtySwitches_TimestampSwitch_StartBeforeNow() {
pub fun test_FlowtySwitchers_TimestampSwitch_StartBeforeNow() {
let start = UInt64(getCurrentBlock().timestamp) - 1
let end = UInt64(getCurrentBlock().timestamp) + 10
let s = FlowtySwitches.TimestampSwitch(start: start, end: end)
let s = FlowtySwitchers.TimestampSwitch(start: start, end: end)

Test.assertEqual(true, s.hasStarted())
Test.assertEqual(start, s.getStart()!)
Expand All @@ -68,20 +68,20 @@ pub fun test_FlowtySwitches_TimestampSwitch_StartBeforeNow() {
Test.assertEqual(end, s.getEnd()!)
}

pub fun test_FlowtySwitches_TimestampSwitch_Ended() {
pub fun test_FlowtySwitchers_TimestampSwitch_Ended() {
let start = UInt64(getCurrentBlock().timestamp) - 10
let end = UInt64(getCurrentBlock().timestamp) - 1
let s = FlowtySwitches.TimestampSwitch(start: start, end: end)
let s = FlowtySwitchers.TimestampSwitch(start: start, end: end)

Test.assertEqual(true, s.hasStarted())
Test.assertEqual(true, s.hasEnded())
}

pub fun test_FlowtySwitches_TimestampSwitch_InvalidStartEnd() {
pub fun test_FlowtySwitchers_TimestampSwitch_InvalidStartEnd() {
let start: UInt64 = 10
let end: UInt64 = 9

Test.expectFailure(fun() {
FlowtySwitches.TimestampSwitch(start: start, end: end)
FlowtySwitchers.TimestampSwitch(start: start, end: end)
}, errorMessageSubstring: "start must be less than end")
}
2 changes: 1 addition & 1 deletion tests/test_helpers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fun deployAll() {
deploy("ExampleToken", "../contracts/standard/ExampleToken.cdc", [])

deploy("FlowtyDrops", "../contracts/FlowtyDrops.cdc", [])
deploy("FlowtySwitches", "../contracts/FlowtySwitches.cdc", [])
deploy("FlowtySwitchers", "../contracts/FlowtySwitchers.cdc", [])
deploy("FlowtyPricers", "../contracts/FlowtyPricers.cdc", [])
deploy("FlowtyAddressVerifiers", "../contracts/FlowtyAddressVerifiers.cdc", [])
deploy("DropFactory", "../contracts/DropFactory.cdc", [])
Expand Down
2 changes: 1 addition & 1 deletion transactions/drops/add_free_phase.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ transaction(dropID: UInt64, start: UInt64?, end: UInt64?) {
let drop = container.borrowDrop(id: dropID) ?? panic("drop not found")
let firstPhase = drop.borrowPhase(index: 0)

let details = FlowtyDrops.PhaseDetails(switch: firstPhase.details.switch, display: firstPhase.details.display, pricer: FlowtyPricers.Free(), addressVerifier: firstPhase.details.addressVerifier)
let details = FlowtyDrops.PhaseDetails(switcher: firstPhase.details.switcher, display: firstPhase.details.display, pricer: FlowtyPricers.Free(), addressVerifier: firstPhase.details.addressVerifier)
let phase <- FlowtyDrops.createPhase(details: details)

drop.addPhase(<- phase)
Expand Down
Loading

0 comments on commit 4d5cf05

Please sign in to comment.