-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c512ff
commit 235c24d
Showing
18 changed files
with
158 additions
and
191 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import "NonFungibleToken" | ||
import "MetadataViews" | ||
|
||
import ExampleNFT from "ExampleNFT" | ||
import "ExampleNFT" | ||
|
||
transaction { | ||
prepare(acct: AuthAccount) { | ||
let d = ExampleNFT.resolveView(Type<MetadataViews.NFTCollectionData>())! as! MetadataViews.NFTCollectionData | ||
prepare(acct: auth(BorrowValue, SaveValue, PublishCapability, UnpublishCapability) &Account) { | ||
let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>())! as! MetadataViews.NFTCollectionData | ||
|
||
if acct.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { | ||
acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) | ||
if acct.storage.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { | ||
acct.storage.save(<- ExampleNFT.createEmptyCollection(), to: d.storagePath) | ||
} | ||
|
||
acct.unlink(d.publicPath) | ||
acct.link<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(d.publicPath, target: d.storagePath) | ||
|
||
acct.unlink(d.providerPath) | ||
acct.link<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Provider}>(d.providerPath, target: d.storagePath) | ||
acct.capabilities.unpublish(d.publicPath) | ||
let cap = acct.capabilities.storage.issue<&ExampleNFT.Collection>(d.storagePath) | ||
acct.capabilities.publish(cap, at: d.publicPath) | ||
} | ||
} | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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
53 changes: 0 additions & 53 deletions
53
scripts/hybrid-custody/get_nft_display_view_from_public.cdc
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
scripts/hybrid-custody/get_nft_display_view_from_storage.cdc
This file contains 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,56 @@ | ||
import "NonFungibleToken" | ||
import "ViewResolver" | ||
import "MetadataViews" | ||
import "HybridCustody" | ||
|
||
/// Returns resolved Display from given address at specified path for each ID or nil if ResolverCollection is not found | ||
/// | ||
access(all) fun getViews(_ address: Address, _ collectionPath: StoragePath): {UInt64: MetadataViews.Display} { | ||
|
||
let account = getAuthAccount<auth(BorrowValue) &Account>(address) | ||
let views: {UInt64: MetadataViews.Display} = {} | ||
|
||
// Borrow the Collection | ||
if let collection = account.storage | ||
.borrow<&{NonFungibleToken.Collection}>(from: collectionPath) { | ||
// Iterate over IDs & resolve the view | ||
for id in collection.getIDs() { | ||
if let resolver = collection.borrowViewResolver(id: id) { | ||
if let display = resolver.resolveView(Type<MetadataViews.Display>()) as! MetadataViews.Display? { | ||
views.insert(key: id, display) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return views | ||
} | ||
|
||
/// Queries for the MetadataViews.Display of each NFT across all associated accounts from Collections at the provided | ||
/// PublicPath | ||
/// | ||
access(all) fun main(address: Address, collectionPath: StoragePath): {Address: {UInt64: MetadataViews.Display}} { | ||
|
||
let allViews: {Address: {UInt64: MetadataViews.Display}} = {address: getViews(address, collectionPath)} | ||
let seen: [Address] = [address] | ||
|
||
/* Iterate over any associated accounts */ | ||
// | ||
if let managerRef = getAuthAccount<auth(BorrowValue) &Account>(address).storage | ||
.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) { | ||
|
||
for childAccount in managerRef.getChildAddresses() { | ||
allViews.insert(key: childAccount, getViews(address, collectionPath)) | ||
seen.append(childAccount) | ||
} | ||
|
||
for ownedAccount in managerRef.getOwnedAddresses() { | ||
if seen.contains(ownedAccount) == false { | ||
allViews.insert(key: ownedAccount, getViews(address, collectionPath)) | ||
seen.append(ownedAccount) | ||
} | ||
} | ||
} | ||
|
||
return allViews | ||
} |
This file contains 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.