Skip to content

Commit

Permalink
add Quote struct to DropTypes contract (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline authored Apr 22, 2024
1 parent 0b646a6 commit b717922
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
43 changes: 38 additions & 5 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ pub contract DropTypes {
}
}

pub struct Quote {
pub let price: UFix64
pub let quantity: Int
pub let paymentIdentifier: String
pub let minter: Address

init(price: UFix64, quantity: Int, paymentIdentifier: String, minter: Address) {
self.price = price
self.quantity = quantity
self.paymentIdentifier = paymentIdentifier
self.minter = minter
}
}

pub struct PhaseSummary {
pub let id: UInt64
pub let index: Int
Expand All @@ -95,11 +109,16 @@ pub contract DropTypes {
pub let address: Address?
pub let remainingForAddress: Int?

pub let quote: Quote?

init(
index: Int,
phase: &{FlowtyDrops.PhasePublic},
address: Address?,
totalMinted: Int?
totalMinted: Int?,
minter: Address?,
quantity: Int?,
paymentIdentifier: String?
) {
self.index = index
self.id = phase.uuid
Expand All @@ -126,10 +145,18 @@ pub contract DropTypes {
self.address = nil
self.remainingForAddress = nil
}

if minter != nil && paymentIdentifier != nil && minter != nil {
let price = d.pricer.getPrice(num: quantity!, paymentTokenType: CompositeType(paymentIdentifier!)!, minter: minter!)

self.quote = Quote(price: price, quantity: quantity!, paymentIdentifier: paymentIdentifier!, minter: minter!)
} else {
self.quote = nil
}
}
}

pub fun getDropSummary(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?): DropSummary? {
pub fun getDropSummary(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropSummary? {
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName)
if resolver == nil {
return nil
Expand Down Expand Up @@ -158,7 +185,10 @@ pub contract DropTypes {
index: index,
phase: phase,
address: minter,
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil,
minter: minter,
quantity: quantity,
paymentIdentifier: paymentIdentifier
)
phaseSummaries.append(summary)
}
Expand All @@ -179,7 +209,7 @@ pub contract DropTypes {
return dropSummary
}

pub fun getAllDropSummaries(contractAddress: Address, contractName: String, minter: Address?): [DropSummary] {
pub fun getAllDropSummaries(contractAddress: Address, contractName: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropSummary] {
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName)
if resolver == nil {
return []
Expand Down Expand Up @@ -210,7 +240,10 @@ pub contract DropTypes {
index: index,
phase: phase,
address: minter,
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil
totalMinted: minter != nil ? dropDetails.minters[minter!] : nil,
minter: minter,
quantity: quantity,
paymentIdentifier: paymentIdentifier
)
phaseSummaries.append(summary)
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/get_drop_summaries.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "DropTypes"

pub fun main(contractAddress: Address, contractName: String, minter: Address?): [DropTypes.DropSummary] {
return DropTypes.getAllDropSummaries(contractAddress: contractAddress, contractName: contractName, minter: minter)
pub fun main(contractAddress: Address, contractName: String, minter: Address?, quantity: Int?, paymentIdentifier: String?): [DropTypes.DropSummary] {
return DropTypes.getAllDropSummaries(contractAddress: contractAddress, contractName: contractName, minter: minter, quantity: quantity, paymentIdentifier: paymentIdentifier)
}
4 changes: 2 additions & 2 deletions scripts/get_drop_summary.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "DropTypes"

pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?): DropTypes.DropSummary? {
return DropTypes.getDropSummary(contractAddress: contractAddress, contractName: contractName, dropID: dropID, minter: minter)
pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, minter: Address?, quantity: Int?, paymentIdentifier: String?): DropTypes.DropSummary? {
return DropTypes.getDropSummary(contractAddress: contractAddress, contractName: contractName, dropID: dropID, minter: minter, quantity: quantity, paymentIdentifier: paymentIdentifier)
}
6 changes: 3 additions & 3 deletions tests/FlowtyDrops_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fun test_OpenEditionNFT_getDropSummary() {
setupExampleToken(minter)
mintExampleTokens(minter, 100.0)

let summary = scriptExecutor("get_drop_summary.cdc", [openEditionAccount.address, "OpenEditionNFT", dropID, minter.address])! as! DropTypes.DropSummary
let summary = scriptExecutor("get_drop_summary.cdc", [openEditionAccount.address, "OpenEditionNFT", dropID, minter.address, 1, exampleTokenIdentifier()])! as! DropTypes.DropSummary
Test.assertEqual(minter.address, summary.address!)

let numToMint = 5
Expand All @@ -173,12 +173,12 @@ pub fun test_OpenEditionNFT_getDropSummary() {
commissionAddress: flowtyDropsAccount.address
)

let summaryAfter = scriptExecutor("get_drop_summary.cdc", [openEditionAccount.address, "OpenEditionNFT", dropID, minter.address])! as! DropTypes.DropSummary
let summaryAfter = scriptExecutor("get_drop_summary.cdc", [openEditionAccount.address, "OpenEditionNFT", dropID, minter.address, 1, exampleTokenIdentifier()])! as! DropTypes.DropSummary
Test.assertEqual(summaryAfter.totalMinted, numToMint)
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]
let summaries = scriptExecutor("get_drop_summaries.cdc", [openEditionAccount.address, "OpenEditionNFT", minter.address, 1, exampleTokenIdentifier()])! as! [DropTypes.DropSummary]
Test.assertEqual(1, summaries.length)
Test.assertEqual(summaries[0].totalMinted, numToMint)
Test.assertEqual(summaries[0].mintedByAddress!, numToMint)
Expand Down

0 comments on commit b717922

Please sign in to comment.