Skip to content

Commit

Permalink
Debugging tx
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Dec 12, 2024
1 parent cd0c813 commit f21be92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
45 changes: 29 additions & 16 deletions cadence/transactions/purchase_nft.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ transaction {
let storefront: &{NFTStorefront.StorefrontPublic}
let listing: &{NFTStorefront.ListingPublic}

prepare(acct: auth(Storage, Capabilities) &Account) {
// Borrow the storefront reference
self.storefront = acct.capabilities
.getCapability(NFTStorefront.StorefrontPublicPath)
.borrow<&{NFTStorefront.StorefrontPublic}>()
?? panic("Could not borrow Storefront from provided address")
prepare(acct: auth(Storage, Capabilities) &Account) {

// Create and save the storefront
let storefront <- NFTStorefront.createStorefront()
acct.storage.save(<-storefront, to: NFTStorefront.StorefrontStoragePath)

// Publish the storefront capability to the public path
let storefrontCap = acct.capabilities.storage.issue<&{NFTStorefront.StorefrontPublic}>(
NFTStorefront.StorefrontStoragePath
)
acct.capabilities.publish(storefrontCap, at: NFTStorefront.StorefrontPublicPath)

// Borrow the storefront reference using the public capability path
let storefrontRef = acct.capabilities.borrow<&{NFTStorefront.StorefrontPublic}>(
NFTStorefront.StorefrontPublicPath
) ?? panic("Could not borrow Storefront from provided address")
self.storefront = storefrontRef

// Borrow the listing reference
self.listing = self.storefront.borrowListing(listingResourceID: 10)
Expand All @@ -24,18 +35,20 @@ transaction {
// Fetch the sale price
let price = self.listing.getDetails().salePrice

// Borrow FlowToken vault and withdraw payment
let mainFlowVault = acct.capabilities
.getCapability(/public/flowTokenReceiver)
.borrow<&{FungibleToken.Provider}>()
?? panic("Cannot borrow FlowToken vault from account storage")
self.paymentVault <- mainFlowVault.withdraw(amount: price)
// Borrow FlowToken vault with proper authorization to withdraw
let flowTokenCap = acct.capabilities.borrow<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>(
/public/flowTokenReceiver
) ?? panic("Cannot borrow FlowToken vault with Withdraw entitlement from account")

// Withdraw the payment
self.paymentVault <- flowTokenCap.withdraw(amount: price)


// Borrow the NFT collection receiver reference
self.exampleNFTCollection = acct.capabilities
.getCapability(ExampleNFT.CollectionPublicPath)
.borrow<&ExampleNFT.Collection>()
?? panic("Cannot borrow NFT collection receiver from account")
let nftCollectionCap = acct.capabilities.borrow<&ExampleNFT.Collection>(
ExampleNFT.CollectionPublicPath
) ?? panic("Cannot borrow NFT collection receiver from account")
self.exampleNFTCollection = nftCollectionCap
}

execute {
Expand Down
8 changes: 4 additions & 4 deletions flow.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"contracts": {
"NFTStorefront": {
"source": "./cadence/contracts/Recipe.cdc",
"ExampleNFT": {
"source": "./cadence/contracts/ExampleNFT.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
},
"ExampleNFT": {
"source": "./cadence/contracts/ExampleNFT.cdc",
"NFTStorefront": {
"source": "./cadence/contracts/Recipe.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
Expand Down

0 comments on commit f21be92

Please sign in to comment.