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

Fixes issue #75 : changed transactions to use prepare/execute #103

Merged
merged 2 commits into from
Mar 9, 2021
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
10 changes: 8 additions & 2 deletions transactions/admin/add_play_to_set.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import TopShot from 0xTOPSHOTADDRESS

transaction(setID: UInt32, playID: UInt32) {

// Local variable for the topshot Admin object
let adminRef: &TopShot.Admin

prepare(acct: AuthAccount) {

// borrow a reference to the Admin resource in storage
let admin = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
self.adminRef = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("Could not borrow a reference to the Admin resource")
}

execute {

// Borrow a reference to the set to be added to
let setRef = admin.borrowSet(setID: setID)
let setRef = self.adminRef.borrowSet(setID: setID)

// Add the specified play ID
setRef.addPlay(playID: playID)
Expand Down
13 changes: 11 additions & 2 deletions transactions/admin/create_play.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ import TopShot from 0xTOPSHOTADDRESS
// transaction string, but want to use transaction arguments soon

transaction(metadata: {String: String}) {

// Local variable for the topshot Admin object
let adminRef: &TopShot.Admin

prepare(acct: AuthAccount) {

// borrow a reference to the admin resource
let admin = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
self.adminRef = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("No admin resource in storage")
admin.createPlay(metadata: metadata)
}

execute {

// Create a play with the specified metadata
self.adminRef.createPlay(metadata: metadata)
}
}
12 changes: 10 additions & 2 deletions transactions/admin/create_set.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import TopShot from 0xTOPSHOTADDRESS
// setName: the name of a new Set to be created

transaction(setName: String) {

// Local variable for the topshot Admin object
let adminRef: &TopShot.Admin

prepare(acct: AuthAccount) {

// borrow a reference to the Admin resource in storage
let admin = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
self.adminRef = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("Could not borrow a reference to the Admin resource")
}

execute {

// Create a set with the specified name
admin.createSet(name: setName)
self.adminRef.createSet(name: setName)
}
}
12 changes: 10 additions & 2 deletions transactions/admin/start_new_series.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import TopShot from 0xTOPSHOTADDRESS
// This transaction is for an Admin to start a new Top Shot series

transaction {

// Local variable for the topshot Admin object
let adminRef: &TopShot.Admin

prepare(acct: AuthAccount) {

// borrow a reference to the Admin resource in storage
let admin = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
self.adminRef = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("No admin resource in storage")
}

execute {

// Increment the series number
admin.startNewSeries()
self.adminRef.startNewSeries()
}
}

12 changes: 10 additions & 2 deletions transactions/admin/transfer_admin.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import TopshotAdminReceiver from 0xADMINRECEIVERADDRESS

transaction {

// Local variable for the topshot Admin object
let adminRef: @TopShot.Admin

prepare(acct: AuthAccount) {
let admin <- acct.load<@TopShot.Admin>(from: /storage/TopShotAdmin)

self.adminRef <- acct.load<@TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("No topshot admin in storage")
}

execute {

TopshotAdminReceiver.storeAdmin(newAdmin: <-admin)
TopshotAdminReceiver.storeAdmin(newAdmin: <-self.adminRef)

}
}
13 changes: 11 additions & 2 deletions transactions/market/change_percentage.cdc
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import Market from 0xMARKETADDRESS

transaction(newPercentage: UFix64) {

// Local variable for the account's topshot sale collection
let topshotSaleCollectionRef: &Market.SaleCollection

prepare(acct: AuthAccount) {

let topshotSaleCollection = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
// borrow a reference to the owner's sale collection
self.topshotSaleCollectionRef = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
?? panic("Could not borrow from sale in storage")
}

execute {

topshotSaleCollection.changePercentage(newPercentage)
// Change the percentage of the moment
self.topshotSaleCollectionRef.changePercentage(newPercentage)
}
}
11 changes: 9 additions & 2 deletions transactions/market/change_price.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import Market from 0xMARKETADDRESS
// newPrice: the new price of the moment

transaction(tokenID: UInt64, newPrice: UFix64) {

// Local variable for the account's topshot sale collection
let topshotSaleCollectionRef: &Market.SaleCollection

prepare(acct: AuthAccount) {

// borrow a reference to the owner's sale collection
let topshotSaleCollection = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
self.topshotSaleCollectionRef = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
?? panic("Could not borrow from sale in storage")
}

execute {

// Change the price of the moment
topshotSaleCollection.changePrice(tokenID: tokenID, newPrice: newPrice)
self.topshotSaleCollectionRef.changePrice(tokenID: tokenID, newPrice: newPrice)
}
}
15 changes: 13 additions & 2 deletions transactions/market/change_receiver.cdc
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import Market from 0xMARKETADDRESS

transaction(receiverPath: PublicPath) {

// Local variables for the sale collection object and receiver
let saleCollectionRef: &Market.SaleCollection
let receiverPathRef: Capability

prepare(acct: AuthAccount) {

let topshotSaleCollection = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
self.saleCollectionRef = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
?? panic("Could not borrow from sale in storage")

topshotSaleCollection.changeOwnerReceiver(acct.getCapability(receiverPath))
self.receiverPathRef = acct.getCapability(receiverPath)
}

execute {

self.saleCollectionRef.changeOwnerReceiver(self.receiverPathRef)

}
}
20 changes: 14 additions & 6 deletions transactions/market/create_start_sale.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import Market from 0xMARKETADDRESS
import TopShot from 0xTOPSHOTADDRESS

transaction(tokenReceiverPath: PublicPath, beneficiaryAccount: Address, cutPercentage: UFix64, momentID: UInt64, price: UFix64) {

// Local variables for the topshot collection and market sale collection objects
let collectionRef: &TopShot.Collection
let marketSaleCollectionRef: &Market.SaleCollection

prepare(acct: AuthAccount) {

// check to see if a sale collection already exists
if acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection) == nil {
// get the fungible token capabilities for the owner and beneficiary
Expand All @@ -20,18 +26,20 @@ transaction(tokenReceiverPath: PublicPath, beneficiaryAccount: Address, cutPerce
}

// borrow a reference to the seller's moment collection
let nftCollection = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
self.collectionRef = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
?? panic("Could not borrow from MomentCollection in storage")

// withdraw the moment to put up for sale
let token <- nftCollection.withdraw(withdrawID: momentID) as! @TopShot.NFT

// borrow a reference to the sale
let topshotSaleCollection = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
self.marketSaleCollectionRef = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
?? panic("Could not borrow from sale in storage")
}

execute {
// withdraw the moment to put up for sale
let token <- self.collectionRef.withdraw(withdrawID: momentID) as! @TopShot.NFT

// the the moment for sale
topshotSaleCollection.listForSale(token: <-token, price: UFix64(price))
self.marketSaleCollectionRef.listForSale(token: <-token, price: UFix64(price))

}
}
13 changes: 10 additions & 3 deletions transactions/market/mint_and_purchase.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ import Market from 0xMARKETADDRESS

transaction(sellerAddress: Address, recipient: Address, tokenID: UInt64, purchaseAmount: UFix64) {

// Local variable for the coin admin
let ducRef: &DapperUtilityCoin.Administrator

prepare(signer: AuthAccount) {

let tokenAdmin = signer
self.ducRef = signer
.borrow<&DapperUtilityCoin.Administrator>(from: /storage/dapperUtilityCoinAdmin)
?? panic("Signer is not the token admin")
}

execute {
let minter <- self.ducRef.createNewMinter(allowedAmount: purchaseAmount)

let minter <- tokenAdmin.createNewMinter(allowedAmount: purchaseAmount)
let mintedVault <- minter.mintTokens(amount: purchaseAmount) as! @DapperUtilityCoin.Vault

destroy minter

let seller = getAccount(sellerAddress)

let topshotSaleCollection = seller.getCapability(/public/topshotSaleCollection)
.borrow<&{Market.SalePublic}>()
?? panic("Could not borrow public sale reference")
Expand All @@ -31,4 +38,4 @@ transaction(sellerAddress: Address, recipient: Address, tokenID: UInt64, purchas
// deposit the NFT in the receivers collection
recipient.deposit(token: <-boughtToken)
}
}
}
18 changes: 13 additions & 5 deletions transactions/market/purchase_moment.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ import Market from 0xMARKETADDRESS
// purchaseAmount: the amount for which the user is paying for the moment; must not be less than the moment's price

transaction(sellerAddress: Address, tokenID: UInt64, purchaseAmount: UFix64) {

// Local variables for the topshot collection object and token provider
let collectionRef: &TopShot.Collection
let providerRef: &DapperUtilityCoin.Vault{FungibleToken.Provider}

prepare(acct: AuthAccount) {

// borrow a reference to the signer's collection
let collection = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
self.collectionRef = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
?? panic("Could not borrow reference to the Moment Collection")

// borrow a reference to the signer's fungible token Vault
let provider = acct.borrow<&DapperUtilityCoin.Vault{FungibleToken.Provider}>(from: /storage/dapperUtilityCoinVault)!

self.providerRef = acct.borrow<&DapperUtilityCoin.Vault{FungibleToken.Provider}>(from: /storage/dapperUtilityCoinVault)!
}

execute {

// withdraw tokens from the signer's vault
let tokens <- provider.withdraw(amount: purchaseAmount) as! @DapperUtilityCoin.Vault
let tokens <- self.providerRef.withdraw(amount: purchaseAmount) as! @DapperUtilityCoin.Vault

// get the seller's public account object
let seller = getAccount(sellerAddress)
Expand All @@ -37,6 +45,6 @@ transaction(sellerAddress: Address, tokenID: UInt64, purchaseAmount: UFix64) {
let purchasedToken <- topshotSaleCollection.purchase(tokenID: tokenID, buyTokens: <-tokens)

// deposit the purchased moment into the signer's collection
collection.deposit(token: <-purchasedToken)
self.collectionRef.deposit(token: <-purchasedToken)
}
}
19 changes: 13 additions & 6 deletions transactions/market/start_sale.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,27 @@ import Market from 0xMARKETADDRESS
// price: the sell price of the moment

transaction(momentID: UInt64, price: UFix64) {

let collectionRef: &TopShot.Collection
let saleCollectionRef: &Market.SaleCollection

prepare(acct: AuthAccount) {

// borrow a reference to the Top Shot Collection
let nftCollection = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
self.collectionRef = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
?? panic("Could not borrow from MomentCollection in storage")

// withdraw the specified token from the collection
let token <- nftCollection.withdraw(withdrawID: momentID) as! @TopShot.NFT

// borrow a reference to the topshot Sale Collection
let topshotSaleCollection = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
self.saleCollectionRef = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
?? panic("Could not borrow from sale in storage")
}

execute {

// withdraw the specified token from the collection
let token <- self.collectionRef.withdraw(withdrawID: momentID) as! @TopShot.NFT

// List the specified moment for sale
topshotSaleCollection.listForSale(token: <-token, price: price)
self.saleCollectionRef.listForSale(token: <-token, price: price)
}
}
16 changes: 11 additions & 5 deletions transactions/market/stop_sale.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ import Market from 0xMARKETADDRESS

transaction(tokenID: UInt64) {

let collectionRef: &TopShot.Collection
let saleCollectionRef: &Market.SaleCollection

prepare(acct: AuthAccount) {

// Borrow a reference to the NFT collection in the signers account
let nftCollection = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
self.collectionRef = acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection)
?? panic("Could not borrow from MomentCollection in storage")

// borrow a reference to the owner's sale collection
let topshotSaleCollection = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
self.saleCollectionRef = acct.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection)
?? panic("Could not borrow from sale in storage")
}

execute{

// withdraw the moment from the sale, thereby de-listing it
let token <- topshotSaleCollection.withdraw(tokenID: tokenID)
let token <- self.saleCollectionRef.withdraw(tokenID: tokenID)

// deposit the moment into the owner's collection
nftCollection.deposit(token: <-token)
self.collectionRef.deposit(token: <-token)
}
}
}