Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to get all drop summaries #11

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,57 @@

return dropSummary
}

pub fun getAllDropSummaries(contractAddress: Address, contractName: String, minter: Address?): [DropSummary] {
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName)
if resolver == nil {
return []

Check warning on line 185 in contracts/DropTypes.cdc

View check run for this annotation

Codecov / codecov/patch

contracts/DropTypes.cdc#L185

Added line #L185 was not covered by tests
}

let dropResolver = resolver!.resolveView(Type<FlowtyDrops.DropResolver>()) as! FlowtyDrops.DropResolver?
if dropResolver == nil {
return []

Check warning on line 190 in contracts/DropTypes.cdc

View check run for this annotation

Codecov / codecov/patch

contracts/DropTypes.cdc#L190

Added line #L190 was not covered by tests
}

let container = dropResolver!.borrowContainer()
if container == nil {
return []

Check warning on line 195 in contracts/DropTypes.cdc

View check run for this annotation

Codecov / codecov/patch

contracts/DropTypes.cdc#L195

Added line #L195 was not covered by tests
}

let summaries: [DropSummary] = []
for id in container!.getIDs() {
let drop = container!.borrowDropPublic(id: id)
if drop == nil {
continue

Check warning on line 202 in contracts/DropTypes.cdc

View check run for this annotation

Codecov / codecov/patch

contracts/DropTypes.cdc#L202

Added line #L202 was not covered by tests
}

let dropDetails = drop!.getDetails()

let phaseSummaries: [PhaseSummary] = []
for index, phase in drop!.borrowAllPhases() {
let summary = PhaseSummary(
index: index,
phase: phase,
address: minter,
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil
)
phaseSummaries.append(summary)
}

summaries.append(DropSummary(
id: drop!.uuid,
display: dropDetails.display,
medias: dropDetails.medias,
totalMinted: dropDetails.totalMinted,
minterCount: dropDetails.minters.keys.length,
mintedByAddress: minter != nil ? dropDetails.minters[minter!] : nil,
commissionRate: dropDetails.commissionRate,
nftType: dropDetails.nftType,
address: minter,
phases: phaseSummaries
))
}

return summaries
}
}
5 changes: 5 additions & 0 deletions scripts/get_drop_summaries.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "DropTypes"

pub fun main(contractAddress: Address, contractName: String, minter: Address?): [DropTypes.DropSummary] {
return DropTypes.getAllDropSummaries(contractAddress: contractAddress, contractName: contractName, minter: minter)
}
5 changes: 5 additions & 0 deletions tests/FlowtyDrops_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ pub fun test_OpenEditionNFT_getDropSummary() {
Test.assertEqual(summaryAfter.mintedByAddress!, numToMint)
Test.assertEqual(1, summaryAfter.phases.length)

let summaries = scriptExecutor("get_drop_summaries.cdc", [openEditionAccount.address, "OpenEditionNFT", minter.address])! as! [DropTypes.DropSummary]
Test.assertEqual(1, summaries.length)
Test.assertEqual(summaries[0].totalMinted, numToMint)
Test.assertEqual(summaries[0].mintedByAddress!, numToMint)
Test.assertEqual(1, summaries[0].phases.length)
}

// ------------------------------------------------------------------------
Expand Down
Loading