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

Updated remaining deprecated scripts & txns to Cadence 1.0 #175

Merged
merged 4 commits into from
Oct 22, 2024
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
31 changes: 13 additions & 18 deletions flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@
"testnet": "294e44e1ec6993c6"
}
},
"FlowToken": {
"source": "./node_modules/@flowtyio/flow-contracts/contracts/FlowToken.cdc",
"aliases": {
"emulator": "0ae53cb6e3f42a79",
"mainnet": "1654653399040a61",
"testnet": "7e60df042a9c0868"
}
},
"HybridCustody": {
"source": "./contracts/HybridCustody.cdc",
"aliases": {
Expand Down Expand Up @@ -177,43 +169,48 @@
"testnet": "9a0766d93b6608b7"
}
},
"FlowToken": {
"source": "mainnet://1654653399040a61.FlowToken",
"hash": "cefb25fd19d9fc80ce02896267eb6157a6b0df7b1935caa8641421fe34c0e67a",
"aliases": {
"emulator": "0ae53cb6e3f42a79",
"mainnet": "1654653399040a61",
"testnet": "7e60df042a9c0868"
}
},
"FungibleToken": {
"source": "mainnet://f233dcee88fe0abe.FungibleToken",
"hash": "1410889b47fef8b02f6867eef3d67a75288a56a651b67a7e815ce273ad301cff",
"hash": "050328d01c6cde307fbe14960632666848d9b7ea4fef03ca8c0bbfb0f2884068",
"aliases": {
"emulator": "ee82856bf20e2aa6",
"mainnet": "f233dcee88fe0abe",
"previewnet": "a0225e7000ac82a9",
"testnet": "9a0766d93b6608b7"
}
},
"FungibleTokenMetadataViews": {
"source": "mainnet://f233dcee88fe0abe.FungibleTokenMetadataViews",
"hash": "294ada6a3df68757fcac4d794f62307c2ea4fe49c93f67e3771d3c6d8377dd47",
"hash": "dff704a6e3da83997ed48bcd244aaa3eac0733156759a37c76a58ab08863016a",
"aliases": {
"emulator": "ee82856bf20e2aa6",
"mainnet": "f233dcee88fe0abe",
"previewnet": "a0225e7000ac82a9",
"testnet": "9a0766d93b6608b7"
}
},
"MetadataViews": {
"source": "mainnet://1d7e57aa55817448.MetadataViews",
"hash": "be26ea7959d7cbc06ac69fe00926b812c4da67984ea2d1bde1029141ae091378",
"hash": "10a239cc26e825077de6c8b424409ae173e78e8391df62750b6ba19ffd048f51",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"mainnet": "1d7e57aa55817448",
"previewnet": "b6763b4399a888c8",
"testnet": "631e88ae7f1d7c20"
}
},
"NonFungibleToken": {
"source": "mainnet://1d7e57aa55817448.NonFungibleToken",
"hash": "49a58b950afdaf0728fdb7d4eb47cf4f2ec3077d655f274b7fdeb504c742f528",
"hash": "b63f10e00d1a814492822652dac7c0574428a200e4c26cb3c832c4829e2778f0",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"mainnet": "1d7e57aa55817448",
"previewnet": "b6763b4399a888c8",
"testnet": "631e88ae7f1d7c20"
}
},
Expand All @@ -231,15 +228,13 @@
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"mainnet": "1d7e57aa55817448",
"previewnet": "b6763b4399a888c8",
"testnet": "631e88ae7f1d7c20"
}
}
},
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"previewnet": "access.previewnet.nodes.onflow.org:9000",
"sandboxnet": "access.sandboxnet.nodes.onflow.org:9000",
"testing": "127.0.0.1:3569",
"testnet": "access.devnet.nodes.onflow.org:9000"
Expand Down
1 change: 0 additions & 1 deletion modules/flow-ft
Submodule flow-ft deleted from a31032
1 change: 0 additions & 1 deletion modules/flow-nft
Submodule flow-nft deleted from 4c0c68
1 change: 0 additions & 1 deletion modules/flow-utils
Submodule flow-utils deleted from c10ce0
1 change: 0 additions & 1 deletion scripts/example-nft/mint_to_account.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ transaction(receiver: Address, name: String, description: String, thumbnail: Str
let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>())! as! MetadataViews.NFTCollectionData

let c = getAccount(receiver).capabilities.get<&{NonFungibleToken.CollectionPublic}>(d.publicPath)
?? panic("no receiver capability found")
let r = c.borrow() ?? panic("could not borrow collection")
self.minter.mintNFT(recipient: r, name: name, description: description, thumbnail: thumbnail, royaltyReceipient: self.minter.owner!.address)
}
Expand Down
20 changes: 9 additions & 11 deletions scripts/example-nft/setup_full.cdc
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)
}
}
}
6 changes: 3 additions & 3 deletions scripts/example-nft/setup_only_save.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import "MetadataViews"
import "ExampleNFT"

transaction {
prepare(acct: AuthAccount) {
if acct.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil {
acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath)
prepare(acct: auth(BorrowValue, SaveValue) &Account) {
if acct.storage.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil {
acct.storage.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath)
}
}
}
17 changes: 0 additions & 17 deletions scripts/example-nft/setup_public.cdc

This file was deleted.

56 changes: 28 additions & 28 deletions scripts/hybrid-custody/get_accessible_child_account_nfts.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ import "MetadataViews"

// This script iterates through a parent's child accounts,
// identifies private paths with an accessible NonFungibleToken.Provider, and returns the corresponding typeIds
pub fun main(addr: Address): AnyStruct {
let manager = getAuthAccount(addr).borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) ?? panic ("manager does not exist")

var typeIdsWithProvider = {} as {Address: [String]}
access(all) fun main(addr: Address, expectedAddressToIDs: {Address: [UInt64]}): AnyStruct {
let manager = getAuthAccount<auth(Storage) &Account>(addr).storage.borrow<auth(HybridCustody.Manage) &HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath)
?? panic ("manager does not exist")

// Address -> nft UUID -> Display
var nftViews = {} as {Address: {UInt64: MetadataViews.Display}}
var typeIdsWithProvider: {Address: [String]} = {}
var nftViews: {Address: {UInt64: MetadataViews.Display}} = {}


let providerType = Type<Capability<&{NonFungibleToken.Provider}>>()
let providerType = Type<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}>()
let collectionType: Type = Type<@{NonFungibleToken.CollectionPublic}>()

// Iterate through child accounts
for address in manager.getChildAddresses() {
let acct = getAuthAccount(address)
let acct = getAuthAccount<auth(Storage, Capabilities) &Account>(address)
let foundTypes: [String] = []
let views: {UInt64: MetadataViews.Display} = {}
let childAcct = manager.borrowAccount(addr: address) ?? panic("child account not found")
// get all private paths
acct.forEachPrivate(fun (path: PrivatePath, type: Type): Bool {
// Check which private paths have NFT Provider AND can be borrowed
if !type.isSubtype(of: providerType){
return true
}
if let cap = childAcct.getCapability(path: path, type: Type<&{NonFungibleToken.Provider}>()) {
let providerCap = cap as! Capability<&{NonFungibleToken.Provider}>

if !providerCap.check(){
// if this isn't a provider capability, exit the account iteration function for this path
return true
for s in acct.storage.storagePaths {
for c in acct.capabilities.storage.getControllers(forPath: s) {
if !c.borrowType.isSubtype(of: providerType){
continue
}

if let cap: Capability = childAcct.getCapability(controllerID: c.capabilityID, type: providerType) {
let providerCap = cap as! Capability<&{NonFungibleToken.Provider}>

if !providerCap.check(){
continue
}

foundTypes.append(cap.borrow<&AnyResource>()!.getType().identifier)
typeIdsWithProvider[address] = foundTypes
break
}
foundTypes.append(cap.borrow<&AnyResource>()!.getType().identifier)
}
return true
})
typeIdsWithProvider[address] = foundTypes
}

// iterate storage, check if typeIdsWithProvider contains the typeId, if so, add to views
acct.forEachStored(fun (path: StoragePath, type: Type): Bool {
acct.storage.forEachStored(fun (path: StoragePath, type: Type): Bool {

if typeIdsWithProvider[address] == nil {
return true
Expand All @@ -59,12 +59,12 @@ pub fun main(addr: Address): AnyStruct {
if type.isInstance(collectionType) {
continue
}
if let collection = acct.borrow<&{NonFungibleToken.CollectionPublic}>(from: path) {
if let collection = acct.storage.borrow<&{NonFungibleToken.CollectionPublic}>(from: path) {
// Iterate over IDs & resolve the view
for id in collection.getIDs() {
let nft = collection.borrowNFT(id: id)
let nft = collection.borrowNFT(id)!
if let display = nft.resolveView(Type<MetadataViews.Display>())! as? MetadataViews.Display {
views.insert(key: nft.uuid, display)
views.insert(key: id, display)
}
}
}
Expand Down
27 changes: 13 additions & 14 deletions scripts/hybrid-custody/get_all_collection_data_from_storage.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ import "HybridCustody"

/// Helper function that retrieves data about all publicly accessible NFTs in an account
///
pub fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCollectionData] {
access(all) fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCollectionData] {

let account: AuthAccount = getAuthAccount(address)
let account = getAuthAccount<auth(BorrowValue) &Account>(address)
let data: [MetadataViews.NFTCollectionData] = []

let collectionType: Type = Type<@{NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>()
let collectionType: Type = Type<@{NonFungibleToken.Collection}>()
let viewType: Type = Type<MetadataViews.NFTCollectionData>()

// Iterate over each public path
account.forEachStored(fun (path: StoragePath, type: Type): Bool {
// Return if not the type we're looking for
if !type.isInstance(collectionType) && !type.isSubtype(of: collectionType) {
account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool {
// Return early if the collection is broken or is not the type we're looking for
if type.isRecovered || (!type.isInstance(collectionType) && !type.isSubtype(of: collectionType)) {
return true
}
if let collectionRef = account
.borrow<&{NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>(from: path) {
if let collectionRef = account.storage.borrow<&{NonFungibleToken.Collection}>(from: path) {
// Return early if no Resolver found in the Collection
let ids: [UInt64]= collectionRef.getIDs()
if ids.length == 0 {
return true
}
// Otherwise, attempt to get the NFTCollectionData & append if exists
if let dataView = collectionRef.borrowViewResolver(id: ids[0]).resolveView(viewType) as! MetadataViews.NFTCollectionData? {
data.append(dataView)
if let resolver = collectionRef.borrowViewResolver(id: ids[0]) {
if let dataView = resolver.resolveView(viewType) as! MetadataViews.NFTCollectionData? {
data.append(dataView)
}
}
}
return true
Expand All @@ -37,16 +38,14 @@ pub fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCollection

/// Script that retrieve data about all NFT Collections in the storage of an account and any of its child accounts
///
pub fun main(address: Address): {Address: [MetadataViews.NFTCollectionData]} {
access(all) fun main(address: Address): {Address: [MetadataViews.NFTCollectionData]} {

let allNFTData: {Address: [MetadataViews.NFTCollectionData]} = {address: getAllViewsFromAddress(address)}
let seen: [Address] = [address]

/* Iterate over any child accounts */
//
if let managerRef = getAccount(address).getCapability<&HybridCustody.Manager{HybridCustody.ManagerPublic}>(
HybridCustody.ManagerPublicPath
).borrow() {
if let managerRef = getAccount(address).capabilities.borrow<&HybridCustody.Manager>(HybridCustody.ManagerPublicPath) {

for childAddress in managerRef.getChildAddresses() {
allNFTData.insert(key: childAddress, getAllViewsFromAddress(childAddress))
Expand Down
14 changes: 7 additions & 7 deletions scripts/hybrid-custody/get_all_vault_bal_from_storage.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import "HybridCustody"

/// Returns a mapping of balances indexed on the Type of resource containing the balance
///
pub fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} {
access(all) fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} {
// Get the account
let account: AuthAccount = getAuthAccount(address)
let account = getAuthAccount<auth(BorrowValue) &Account>(address)
// Init for return value
let balances: {Type: UFix64} = {}
// Track seen Types in array
let seen: [Type] = []
// Assign the type we'll need
let balanceType: Type = Type<@{FungibleToken.Balance}>()
// Iterate over all stored items & get the path if the type is what we're looking for
account.forEachStored(fun (path: StoragePath, type: Type): Bool {
if type.isInstance(balanceType) || type.isSubtype(of: balanceType) {
account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool {
if !type.isRecovered && (type.isInstance(balanceType) || type.isSubtype(of: balanceType)) {
// Get a reference to the resource & its balance
let vaultRef = account.borrow<&{FungibleToken.Balance}>(from: path)!
let vaultRef = account.storage.borrow<&{FungibleToken.Balance}>(from: path)!
// Insert a new values if it's the first time we've seen the type
if !seen.contains(type) {
balances.insert(key: type, vaultRef.balance)
Expand All @@ -34,7 +34,7 @@ pub fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} {

/// Queries for FT.Vault balance of all FT.Vaults in the specified account and all of its associated accounts
///
pub fun main(address: Address): {Address: {Type: UFix64}} {
access(all) fun main(address: Address): {Address: {Type: UFix64}} {

// Get the balance for the given address
let balances: {Address: {Type: UFix64}} = { address: getAllBalancesInStorage(address) }
Expand All @@ -43,7 +43,7 @@ pub fun main(address: Address): {Address: {Type: UFix64}} {

/* Iterate over any associated accounts */
//
if let managerRef = getAuthAccount(address)
if let managerRef = getAuthAccount<auth(BorrowValue) &Account>(address).storage
.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) {

for childAccount in managerRef.getChildAddresses() {
Expand Down
Loading
Loading