Skip to content

Commit

Permalink
extras
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesign committed Mar 20, 2024
1 parent 2a64a93 commit 1ad60e2
Show file tree
Hide file tree
Showing 8 changed files with 454 additions and 13 deletions.
141 changes: 141 additions & 0 deletions contracts/FDNZ.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import NonFungibleToken from 0x1d7e57aa55817448
import FungibleToken from 0xf233dcee88fe0abe
import MetadataViews from 0x1d7e57aa55817448

pub contract FDNZ{

access(all) fun getAccountLinks(_ account: AuthAccount, domain: String): [{String:AnyStruct}]{

var res : [{String:AnyStruct}] = []

if domain=="public"{
account.forEachPublic(fun (path: PublicPath, type: Type): Bool {
res.append( {
"path" : path,
"borrowType" : type,
"target" : account.getLinkTarget(path)
})
return true
})
}

if domain=="private"{
account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool {
res.append( {
"path" : path,
"borrowType" : type,
"target" : account.getLinkTarget(path)
})
return true
})
}

return res
}

access(all) fun getAccountStorageNFT(_ account: AuthAccount, path: String, uuid: UInt64) : AnyStruct{
var obj = account.borrow<auth &AnyResource>(from: StoragePath(identifier: path)!)!
var meta = obj as? &AnyResource{MetadataViews.ResolverCollection}

var res : {String:AnyStruct} = {}

var vr = meta?.borrowViewResolver(id:uuid)
if let views = vr?.getViews(){
for mdtype in views{
if mdtype==Type<MetadataViews.NFTView>() {
continue
}
if mdtype==Type<MetadataViews.NFTCollectionData>() {
continue
}
res[mdtype.identifier]=vr?.resolveView(mdtype)
}
}

return res
}

access(all) fun getAccountStorage(_ account: AuthAccount, path: String): AnyStruct{

var obj = account.borrow<auth &AnyResource>(from: StoragePath(identifier: path)!)!
var meta = obj as? &AnyResource{MetadataViews.ResolverCollection}

if meta!=nil && meta!.getIDs().length>0{
var res : {UInt64:AnyStruct} = {}
for id in meta!.getIDs(){
res[id] = meta!.borrowViewResolver(id:id).resolveView(Type<MetadataViews.Display>())!
}
return res
}
else{
var col = account.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct
return col
}
}

access(all) fun getAccountStorageRaw(_ account: AuthAccount, path: String): AnyStruct{

var obj = account.borrow<auth &AnyResource>(from: StoragePath(identifier: path)!)!

return obj
}


access(all) fun getAccountData(_ account:AuthAccount):{String:AnyStruct}{

var paths: [Path] = []
var privatePaths: [Path] = []
var publicPaths: [Path] = []
var nft : [AnyStruct] = []
var ft : [AnyStruct] = []


account.forEachStored(fun (path: StoragePath, type: Type): Bool {
if type.isSubtype(of: Type<@NonFungibleToken.Collection>()){
var collection = account.borrow<&NonFungibleToken.Collection>(from:path)!
nft.append({"path":path, "count":collection.getIDs().length})
paths.append(path)
}
else if type.isSubtype(of: Type<@FungibleToken.Vault>()){
var vault = account.borrow<&FungibleToken.Vault>(from:path)!
ft.append({"path":path, "balance":vault.balance})
paths.append(path)
}
else{
paths.append(path)
}
return true
})

account.forEachPublic(fun (path: PublicPath, type: Type): Bool {
publicPaths.append(path)
return true
})

account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool {
privatePaths.append(path)
return true
})


let response: {String: AnyStruct} = {}

//find profile
var findProfile = account.borrow<&AnyResource>(from:/storage/findProfile)
response["find"] = findProfile
response["capacity"] = account.storageCapacity
response["used"] = account.storageUsed
response["available"] = 0
response["paths"] = paths
response["public"] = publicPaths
response["private"] = privatePaths
response["nft"] = nft
response["ft"] = ft

if account.storageCapacity>account.storageUsed{
response["available"] = account.storageCapacity - account.storageUsed
}
return response
}

}
120 changes: 120 additions & 0 deletions contracts/FDNZ1.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import NonFungibleToken from 0xb6763b4399a888c8
import FungibleToken from 0xa0225e7000ac82a9
import MetadataViews from 0xb6763b4399a888c8
import ViewResolver from 0xb6763b4399a888c8

access(all) contract FDNZ{

access(all) fun getAccountLinks(_ account: auth(Storage) &Account, domain: String): [{String:AnyStruct}]{

var res : [{String:AnyStruct}] = []

if domain=="public"{
account.storage.forEachPublic(fun (path: PublicPath, type: Type): Bool {
res.append( {
"path" : path.toString(),
"borrowType" : type.toString(),
"target" : ""
})
return true
})
}


return res
}

access(all) fun getAccountStorageNFT(_ account: auth(Storage) &Account, path: String, uuid: UInt64) : AnyStruct{
var obj = account.storage.borrow<&AnyResource>(from: StoragePath(identifier: path)!)!
var meta = obj as? &{ViewResolver.ResolverCollection}

var res : {String:AnyStruct} = {}

var vr = meta?.borrowViewResolver(id:uuid)!
if let views = vr?.getViews(){
for mdtype in views{
if mdtype==Type<MetadataViews.NFTView>() {
continue
}
if mdtype==Type<MetadataViews.NFTCollectionData>() {
continue
}
res[mdtype.identifier]=vr?.resolveView(mdtype)
}
}

return res
}

access(all) fun getAccountStorage(_ account: auth(Storage) &Account, path: String): AnyStruct{

var obj = account.storage.borrow<&AnyResource>(from: StoragePath(identifier: path)!)!
var meta = obj as? &{ViewResolver.ResolverCollection}

if meta!=nil && meta!.getIDs().length>0{
var res : {UInt64:AnyStruct} = {}
for id in meta!.getIDs(){
res[id] = meta!.borrowViewResolver(id:id)?.resolveView(Type<MetadataViews.Display>())!
}
return res
}
else{
var col = account.storage.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct
return col
}
}



access(all) fun getAccountData(_ account: auth(Storage) &Account):{String:AnyStruct}{

var paths: [Path] = []
var privatePaths: [Path] = []
var publicPaths: [Path] = []
var nft : [AnyStruct] = []
var ft : [AnyStruct] = []


account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool {
if type.isSubtype(of: Type<@{NonFungibleToken.Collection}>()){
var collection = account.storage.borrow<&{NonFungibleToken.Collection}>(from:path)!
nft.append({"path":path, "count":collection.getIDs().length})
}
else if type.isSubtype(of: Type<@{FungibleToken.Vault}>()){
var vault = account.storage.borrow<&{FungibleToken.Vault}>(from:path)!
ft.append({"path":path, "balance":vault.balance})
}
else{
paths.append(path)
}
return true
})

account.storage.forEachPublic(fun (path: PublicPath, type: Type): Bool {
publicPaths.append(path)
return true
})



let response: {String: AnyStruct} = {}

//find profile
var findProfile = account.storage.borrow<&AnyResource>(from:/storage/findProfile)
response["find"] = findProfile
response["capacity"] = account.storage.capacity
response["used"] = account.storage.used
response["available"] = 0
response["paths"] = paths
response["public"] = publicPaths
response["private"] = privatePaths
response["nft"] = nft
response["ft"] = ft

if account.storage.capacity>account.storage.used{
response["available"] = account.storage.capacity - account.storage.used
}
return response
}

}
Loading

0 comments on commit 1ad60e2

Please sign in to comment.