-
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.
add a test to borrow active phases (#6)
- Loading branch information
1 parent
72a41ad
commit 6d42346
Showing
5 changed files
with
91 additions
and
3 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
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,23 @@ | ||
import "FlowtyDrops" | ||
import "ViewResolver" | ||
|
||
pub fun main(contractAddress: Address, contractName: String, dropID: UInt64): [UInt64] { | ||
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName) | ||
?? panic("contract does not implement ViewResolver interface") | ||
|
||
let dropResolver = resolver.resolveView(Type<FlowtyDrops.DropResolver>())! as! FlowtyDrops.DropResolver | ||
|
||
let container = dropResolver.borrowContainer() | ||
?? panic("drop container not found") | ||
|
||
let drop = container.borrowDropPublic(id: dropID) | ||
?? panic("drop not found") | ||
|
||
let phases = drop.borrowActivePhases() | ||
let ids: [UInt64] = [] | ||
for p in phases { | ||
ids.append(p.uuid) | ||
} | ||
|
||
return ids | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import "FlowtyDrops" | ||
import "FlowtyPricers" | ||
|
||
transaction(dropID: UInt64, start: UInt64?, end: UInt64?) { | ||
prepare(acct: AuthAccount) { | ||
let container = acct.borrow<&FlowtyDrops.Container>(from: FlowtyDrops.ContainerStoragePath) | ||
?? panic("container not found") | ||
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 phase <- FlowtyDrops.createPhase(details: details) | ||
|
||
drop.addPhase(<- phase) | ||
} | ||
} |
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,16 @@ | ||
import "FlowtyDrops" | ||
import "FlowtyPricers" | ||
|
||
transaction(dropID: UInt64, start: UInt64?, end: UInt64?) { | ||
prepare(acct: AuthAccount) { | ||
let container = acct.borrow<&FlowtyDrops.Container>(from: FlowtyDrops.ContainerStoragePath) | ||
?? panic("container not found") | ||
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 phases = drop.borrowAllPhases() | ||
destroy drop.removePhase(index: phases.length - 1) | ||
} | ||
} |