diff --git a/contracts/DropTypes.cdc b/contracts/DropTypes.cdc index 375a155..c866095 100644 --- a/contracts/DropTypes.cdc +++ b/contracts/DropTypes.cdc @@ -178,4 +178,57 @@ pub contract DropTypes { 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 [] + } + + let dropResolver = resolver!.resolveView(Type()) as! FlowtyDrops.DropResolver? + if dropResolver == nil { + return [] + } + + let container = dropResolver!.borrowContainer() + if container == nil { + return [] + } + + let summaries: [DropSummary] = [] + for id in container!.getIDs() { + let drop = container!.borrowDropPublic(id: id) + if drop == nil { + continue + } + + 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 + } } \ No newline at end of file diff --git a/scripts/get_drop_summaries.cdc b/scripts/get_drop_summaries.cdc new file mode 100644 index 0000000..b9c48a2 --- /dev/null +++ b/scripts/get_drop_summaries.cdc @@ -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) +} \ No newline at end of file diff --git a/tests/FlowtyDrops_tests.cdc b/tests/FlowtyDrops_tests.cdc index 3d2bdd4..298fecc 100644 --- a/tests/FlowtyDrops_tests.cdc +++ b/tests/FlowtyDrops_tests.cdc @@ -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) } // ------------------------------------------------------------------------