This repository was archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 207
feat: import cdc files #192
Merged
+432
−9,433
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import KittyItems from 0xKittyItems | ||
|
|
||
| pub struct AccountItem { | ||
| pub let itemID: UInt64 | ||
| pub let typeID: UInt64 | ||
| pub let rarityID: UInt64 | ||
| pub let owner: Address | ||
|
|
||
| init(itemID: UInt64, typeID: UInt64, rarityID: UInt64, owner: Address) { | ||
| self.itemID = itemID | ||
| self.typeID = typeID | ||
| self.rarityID = rarityID | ||
| self.owner = owner | ||
| } | ||
| } | ||
|
|
||
| pub fun fetch(address: Address, id: UInt64): AccountItem? { | ||
| if let col = getAccount(address).getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath).borrow() { | ||
| if let item = col.borrowKittyItem(id: id) { | ||
| return AccountItem(itemID: id, typeID: item.typeID, rarityID: item.rarityID, owner: address) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| pub fun main(keys: [String], addresses: [Address], ids: [UInt64]): {String: AccountItem?} { | ||
| let r: {String: AccountItem?} = {} | ||
| var i = 0 | ||
| while i < keys.length { | ||
| let key = keys[i] | ||
| let address = addresses[i] | ||
| let id = ids[i] | ||
| r[key] = fetch(address: address, id: id) | ||
| i = i + 1 | ||
| } | ||
| return r | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import KittyItems from 0xKittyItems | ||
|
|
||
| pub fun main(address: Address): [UInt64] { | ||
| if let collection = getAccount(address).getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath).borrow() { | ||
| return collection.getIDs() | ||
| } | ||
|
|
||
| return [] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import NFTStorefront from 0xNFTStorefront | ||
| import KittyItems from 0xKittyItems | ||
|
|
||
| pub struct SaleItem { | ||
| pub let itemID: UInt64 | ||
| pub let typeID: UInt64 | ||
| pub let owner: Address | ||
| pub let price: UFix64 | ||
|
|
||
| init(itemID: UInt64, typeID: UInt64, owner: Address, price: UFix64) { | ||
| self.itemID = itemID | ||
| self.typeID = typeID | ||
| self.owner = owner | ||
| self.price = price | ||
| } | ||
| } | ||
|
|
||
| pub fun main(address: Address, listingResourceID: UInt64): SaleItem? { | ||
| let account = getAccount(address) | ||
| if let storefrontRef = account.getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(NFTStorefront.StorefrontPublicPath).borrow() { | ||
| if let listing = storefrontRef.borrowListing(listingResourceID: listingResourceID) { | ||
| let details = listing.getDetails() | ||
|
|
||
| let itemID = details.nftID | ||
| let itemPrice = details.salePrice | ||
|
|
||
| if let collection = account.getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath).borrow() { | ||
| if let item = collection.borrowKittyItem(id: itemID) { | ||
| return SaleItem(itemID: itemID, typeID: item.typeID, owner: address, price: itemPrice) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import NFTStorefront from 0xNFTStorefront | ||
|
|
||
| pub fun main(address: Address): [UInt64] { | ||
| let storefrontRef = getAccount(address) | ||
| .getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>( | ||
| NFTStorefront.StorefrontPublicPath | ||
| ) | ||
| .borrow() | ||
| ?? panic("Could not borrow public storefront from address") | ||
|
|
||
| return storefrontRef.getListingIDs() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import FungibleToken from 0xFungibleToken | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import KittyItems from 0xKittyItems | ||
| import NFTStorefront from 0xNFTStorefront | ||
|
|
||
| pub fun hasItems(_ address: Address): Bool { | ||
| return getAccount(address) | ||
| .getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath) | ||
| .check() | ||
| } | ||
|
|
||
| pub fun hasStorefront(_ address: Address): Bool { | ||
| return getAccount(address) | ||
| .getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(NFTStorefront.StorefrontPublicPath) | ||
| .check() | ||
| } | ||
|
|
||
| pub fun main(address: Address): {String: Bool} { | ||
| let ret: {String: Bool} = {} | ||
| ret["KittyItems"] = hasItems(address) | ||
| ret["KittyItemsMarket"] = hasStorefront(address) | ||
| return ret | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import FungibleToken from 0xFungibleToken | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import FlowToken from 0xFlowToken | ||
| import KittyItems from 0xKittyItems | ||
| import NFTStorefront from 0xNFTStorefront | ||
|
|
||
| pub fun getOrCreateStorefront(account: AuthAccount): &NFTStorefront.Storefront { | ||
| if let storefrontRef = account.borrow<&NFTStorefront.Storefront>(from: NFTStorefront.StorefrontStoragePath) { | ||
| return storefrontRef | ||
| } | ||
|
|
||
| let storefront <- NFTStorefront.createStorefront() | ||
|
|
||
| let storefrontRef = &storefront as &NFTStorefront.Storefront | ||
|
|
||
| account.save(<-storefront, to: NFTStorefront.StorefrontStoragePath) | ||
|
|
||
| account.link<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(NFTStorefront.StorefrontPublicPath, target: NFTStorefront.StorefrontStoragePath) | ||
|
|
||
| return storefrontRef | ||
| } | ||
|
|
||
| transaction(saleItemID: UInt64, saleItemPrice: UFix64) { | ||
|
|
||
| let flowReceiver: Capability<&FlowToken.Vault{FungibleToken.Receiver}> | ||
| let kittyItemsProvider: Capability<&KittyItems.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}> | ||
| let storefront: &NFTStorefront.Storefront | ||
|
|
||
| prepare(account: AuthAccount) { | ||
| // We need a provider capability, but one is not provided by default so we create one if needed. | ||
| let kittyItemsCollectionProviderPrivatePath = /private/kittyItemsCollectionProvider | ||
|
|
||
| self.flowReceiver = account.getCapability<&FlowToken.Vault{FungibleToken.Receiver}>(/public/flowTokenReceiver)! | ||
|
|
||
| assert(self.flowReceiver.borrow() != nil, message: "Missing or mis-typed FLOW receiver") | ||
|
|
||
| if !account.getCapability<&KittyItems.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(kittyItemsCollectionProviderPrivatePath)!.check() { | ||
| account.link<&KittyItems.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(kittyItemsCollectionProviderPrivatePath, target: KittyItems.CollectionStoragePath) | ||
| } | ||
|
|
||
| self.kittyItemsProvider = account.getCapability<&KittyItems.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(kittyItemsCollectionProviderPrivatePath)! | ||
|
|
||
| assert(self.kittyItemsProvider.borrow() != nil, message: "Missing or mis-typed KittyItems.Collection provider") | ||
|
|
||
| self.storefront = getOrCreateStorefront(account: account) | ||
| } | ||
|
|
||
| execute { | ||
| let saleCut = NFTStorefront.SaleCut( | ||
| receiver: self.flowReceiver, | ||
| amount: saleItemPrice | ||
| ) | ||
|
|
||
| self.storefront.createListing( | ||
| nftProviderCapability: self.kittyItemsProvider, | ||
| nftType: Type<@KittyItems.NFT>(), | ||
| nftID: saleItemID, | ||
| salePaymentVaultType: Type<@FlowToken.Vault>(), | ||
| saleCuts: [saleCut] | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import FungibleToken from 0xFungibleToken | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import KittyItems from 0xKittyItems | ||
| import NFTStorefront from 0xNFTStorefront | ||
|
|
||
| pub fun hasItems(_ address: Address): Bool { | ||
| return getAccount(address) | ||
| .getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath) | ||
| .check() | ||
| } | ||
|
|
||
| pub fun hasStorefront(_ address: Address): Bool { | ||
| return getAccount(address) | ||
| .getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(NFTStorefront.StorefrontPublicPath) | ||
| .check() | ||
| } | ||
|
|
||
| transaction { | ||
| prepare(acct: AuthAccount) { | ||
| if !hasItems(acct.address) { | ||
| if acct.borrow<&KittyItems.Collection>(from: KittyItems.CollectionStoragePath) == nil { | ||
| acct.save(<-KittyItems.createEmptyCollection(), to: KittyItems.CollectionStoragePath) | ||
| } | ||
| acct.unlink(KittyItems.CollectionPublicPath) | ||
| acct.link<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath, target: KittyItems.CollectionStoragePath) | ||
| } | ||
|
|
||
| if !hasStorefront(acct.address) { | ||
| if acct.borrow<&NFTStorefront.Storefront>(from: NFTStorefront.StorefrontStoragePath) == nil { | ||
| acct.save(<-NFTStorefront.createStorefront(), to: NFTStorefront.StorefrontStoragePath) | ||
| } | ||
| acct.unlink(NFTStorefront.StorefrontPublicPath) | ||
| acct.link<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(NFTStorefront.StorefrontPublicPath, target: NFTStorefront.StorefrontStoragePath) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import FungibleToken from 0xFungibleToken | ||
| import NonFungibleToken from 0xNonFungibleToken | ||
| import FlowToken from 0xFlowToken | ||
| import KittyItems from 0xKittyItems | ||
| import NFTStorefront from 0xNFTStorefront | ||
|
|
||
| pub fun getOrCreateCollection(account: AuthAccount): &KittyItems.Collection{NonFungibleToken.Receiver} { | ||
| if let collectionRef = account.borrow<&KittyItems.Collection>(from: KittyItems.CollectionStoragePath) { | ||
| return collectionRef | ||
| } | ||
|
|
||
| // create a new empty collection | ||
| let collection <- KittyItems.createEmptyCollection() as! @KittyItems.Collection | ||
|
|
||
| let collectionRef = &collection as &KittyItems.Collection | ||
|
|
||
| // save it to the account | ||
| account.save(<-collection, to: KittyItems.CollectionStoragePath) | ||
|
|
||
| // create a public capability for the collection | ||
| account.link<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath, target: KittyItems.CollectionStoragePath) | ||
|
|
||
| return collectionRef | ||
| } | ||
|
|
||
| transaction(listingResourceID: UInt64, storefrontAddress: Address) { | ||
| let paymentVault: @FungibleToken.Vault | ||
| let kittyItemsCollection: &KittyItems.Collection{NonFungibleToken.Receiver} | ||
| let storefront: &NFTStorefront.Storefront{NFTStorefront.StorefrontPublic} | ||
| let listing: &NFTStorefront.Listing{NFTStorefront.ListingPublic} | ||
|
|
||
| prepare(account: AuthAccount) { | ||
| self.storefront = getAccount(storefrontAddress) | ||
| .getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>( | ||
| NFTStorefront.StorefrontPublicPath | ||
| )! | ||
| .borrow() | ||
| ?? panic("Could not borrow Storefront from provided address") | ||
|
|
||
| self.listing = self.storefront.borrowListing(listingResourceID: listingResourceID) | ||
| ?? panic("No Listing with that ID in Storefront") | ||
|
|
||
| let price = self.listing.getDetails().salePrice | ||
|
|
||
| let mainFLOWVault = account.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault) | ||
| ?? panic("Cannot borrow FLOW vault from account storage") | ||
|
|
||
| self.paymentVault <- mainFLOWVault.withdraw(amount: price) | ||
|
|
||
| self.kittyItemsCollection = getOrCreateCollection(account: account) | ||
| } | ||
|
|
||
| execute { | ||
| let item <- self.listing.purchase( | ||
| payment: <-self.paymentVault | ||
| ) | ||
|
|
||
| self.kittyItemsCollection.deposit(token: <-item) | ||
|
|
||
| self.storefront.cleanup(listingResourceID: listingResourceID) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import NFTStorefront from 0xNFTStorefront | ||
|
|
||
| transaction(listingResourceID: UInt64) { | ||
| let storefront: &NFTStorefront.Storefront{NFTStorefront.StorefrontManager} | ||
|
|
||
| prepare(acct: AuthAccount) { | ||
| self.storefront = acct.borrow<&NFTStorefront.Storefront{NFTStorefront.StorefrontManager}>(from: NFTStorefront.StorefrontStoragePath) | ||
| ?? panic("Missing or mis-typed NFTStorefront.Storefront") | ||
| } | ||
|
|
||
| execute { | ||
| self.storefront.removeListing(listingResourceID: listingResourceID) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.