Skip to content

Instantly share code, notes, and snippets.

@bjartek
Created May 7, 2022 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjartek/6a707eef7bb808b0325b95dd3bc919e9 to your computer and use it in GitHub Desktop.
Save bjartek/6a707eef7bb808b0325b95dd3bc919e9 to your computer and use it in GitHub Desktop.
bl0x
{
"networks": {
"emulator": {
"scripts": {
"bl0x": {
"code": "import Bl0x from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\n\npub fun main(address: Address, id:UInt64) : Bl0x.Metadata? {\n let account=getAccount(address)\n /* Check on bl0xPack */\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n return nil\n }\n let bl0x = bl0xCap.borrow()!\n return bl0x.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n}",
"spec": {
"order": [
"address",
"id"
],
"parameters": {
"address": "Address",
"id": "UInt64"
}
}
},
"ids": {
"code": "import NonFungibleToken from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\n\n//get all the views for an nft and address/path/id\npub fun main(address: Address, path:PublicPath) : [UInt64] {\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n return collection.getIDs()\n}",
"spec": {
"order": [
"address",
"path"
],
"parameters": {
"address": "Address",
"path": "PublicPath"
}
}
},
"packTypeStatus": {
"code": "import MetadataViews from 0xf8d6e0586b0a20c7\nimport Bl0xPack from 0xf8d6e0586b0a20c7\n\npub struct BloxPackStatus {\n pub let remainingPacks: UInt64\n pub let whiteListTime: UFix64?\n pub let floatEventId: UInt64?\n pub let buyTime: UFix64\n pub let openTime: UFix64\n pub let price: UFix64\n pub let walletType: String \n pub let typeId: UInt64\n pub let thumbnail: String\n\n init(remainingPacks: UInt64 , \n whiteListTime: UFix64? ,\n floatEventId: UInt64?,\n buyTime: UFix64 ,\n openTime: UFix64 ,\n price: UFix64 ,\n walletType: String ,\n typeId: UInt64,\n thumbnail:String\n ) {\n self.remainingPacks = remainingPacks\n self.whiteListTime = whiteListTime\n self.floatEventId = floatEventId\n self.buyTime = buyTime\n self.openTime = openTime\n self.price = price\n self.walletType = walletType\n self.typeId = typeId\n self.thumbnail=thumbnail\n }\n}\npub fun main(address: Address, typeId: UInt64) : BloxPackStatus {\n\n let collectionRef = getAccount(address).getCapability(Bl0xPack.CollectionPublicPath).borrow\u003c\u0026Bl0xPack.Collection{Bl0xPack.CollectionPublic}\u003e()!\n let remainingPacks = collectionRef.getPacksLeftForType(typeId)\n let metadata = Bl0xPack.getMetadata(typeId: typeId) ?? panic(\"Cannot get metadata of this type :\".concat(typeId.toString()))\n return BloxPackStatus(remainingPacks: remainingPacks, \n whiteListTime: metadata.whiteListTime, \n floatEventId: metadata.floatEventId, \n buyTime: metadata.buyTime, \n openTime: metadata.openTime, \n price: metadata.price, \n walletType: metadata.walletType.identifier,\n typeId: typeId, \n thumbnail: metadata.getThumbnail().uri()\n )\n}",
"spec": {
"order": [
"address",
"typeId"
],
"parameters": {
"address": "Address",
"typeId": "UInt64"
}
}
},
"packsRemaining": {
"code": "import MetadataViews from 0xf8d6e0586b0a20c7\nimport Bl0xPack from 0xf8d6e0586b0a20c7\n\npub fun main(address: Address) : Int {\n\n let collection= getAccount(address).getCapability(Bl0xPack.CollectionPublicPath).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n return collection.getIDs().length\n}",
"spec": {
"order": [
"address"
],
"parameters": {
"address": "Address"
}
}
},
"validUser": {
"code": "import Bl0xPack from 0xf8d6e0586b0a20c7\nimport Bl0x from 0xf8d6e0586b0a20c7\nimport NonFungibleToken from 0xf8d6e0586b0a20c7\n\npub fun main(target: Address) : Bool {\n\n let account=getAccount(target)\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n\n return findPackCap.check() \u0026\u0026 bl0xCap.check()\n}",
"spec": {
"order": [
"target"
],
"parameters": {
"target": "Address"
}
}
},
"view": {
"code": "import NonFungibleToken from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\n\n//Fetch a single view from a nft on a given path\npub fun main(address: Address, path:PublicPath, id: UInt64, identifier: String) : AnyStruct? {\n\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n\n let nft=collection.borrowViewResolver(id: id)\n for v in nft.getViews() {\n if v.identifier== identifier {\n return nft.resolveView(v)\n }\n }\n return nil\n}",
"spec": {
"order": [
"address",
"path",
"id",
"identifier"
],
"parameters": {
"address": "Address",
"id": "UInt64",
"identifier": "String",
"path": "PublicPath"
}
}
},
"viewUser": {
"code": "import Profile from 0xf8d6e0586b0a20c7\nimport Bl0xPack from 0xf8d6e0586b0a20c7\nimport Bl0x from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\nimport FLOAT from 0xf8d6e0586b0a20c7\n\npub struct FINDNameBl0xReport{\n pub let profile: Profile.UserProfile?\n pub let bl0xPack: [Bl0xPackData] // empty array means empty collection. nil means no collection set up\n pub let bl0x: [Bl0x.Metadata] // empty array means empty collection. nil means no collection set up\n pub let canByPack:Bool\n\n init(profile: Profile.UserProfile?, bl0xPack: [Bl0xPackData] , bl0x: [Bl0x.Metadata], canByPack:Bool) {\n self.profile = profile\n self.bl0xPack = bl0xPack \n self.bl0x = bl0x\n self.canByPack=canByPack\n }\n}\n\npub struct Bl0xPackData {\n pub let id : UInt64\n pub let name : String \n pub let image : String \n pub let canBeOpened : Bool \n\n init(id: UInt64, name: String, image: String, canBeOpened: Bool) {\n self.id = id \n self.name = name \n self.image = image \n self.canBeOpened = canBeOpened\n }\n}\n\npub fun main(address: Address) : FINDNameBl0xReport{\n\n let packTypeId:UInt64=2\n let account=getAccount(address)\n /* Check on profile */\n let profile= account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath).borrow()?.asProfile()\n\n /* Check on bl0xPack */\n var bl0xPack : [Bl0xPackData] = []\n let bl0xPackCap = account.getCapability\u003c\u0026Bl0xPack.Collection{MetadataViews.ResolverCollection}\u003e(Bl0xPack.CollectionPublicPath)\n if bl0xPackCap.check() {\n let bl0xPackIds = bl0xPackCap.borrow()!.getIDs()\n for id in bl0xPackIds {\n let Bl0xPackMetadata=bl0xPackCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0xPack.Metadata\u003e())! as! Bl0xPack.Metadata\n let metadata = Bl0xPackData(id: id, name: Bl0xPackMetadata.name, image: Bl0xPackMetadata.getThumbnail().uri(), canBeOpened: Bl0xPackMetadata.canBeOpened())\n bl0xPack.append(metadata)\n }\n }\n\n /* Check on bl0xPack */\n var bl0x : [Bl0x.Metadata] = []\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if bl0xCap.check() {\n let bl0xIds = bl0xCap.borrow()!.getIDs()\n for id in bl0xIds {\n let metadata=bl0xCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n bl0x.append(metadata)\n }\n }\n\n\n \n return FINDNameBl0xReport(\n profile: profile,\n bl0xPack: bl0xPack, \n bl0x: bl0x,\n canByPack: Bl0xPack.canBuy(packTypeId: packTypeId, user:address)\n )\n\n}",
"spec": {
"order": [
"address"
],
"parameters": {
"address": "Address"
}
}
},
"views": {
"code": "import NonFungibleToken from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\n\n//get all the views for an nft and address/path/id\npub fun main(address: Address, path:PublicPath, id: UInt64) : [String] {\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n let nft=collection.borrowViewResolver(id: id)\n let views:[String]=[]\n for v in nft.getViews() {\n views.append(v.identifier)\n }\n return views\n}",
"spec": {
"order": [
"address",
"path",
"id"
],
"parameters": {
"address": "Address",
"id": "UInt64",
"path": "PublicPath"
}
}
}
},
"transactions": {
"buyPack": {
"code": "import Bl0xPack from 0xf8d6e0586b0a20c7\nimport Bl0x from 0xf8d6e0586b0a20c7\nimport FungibleToken from 0xee82856bf20e2aa6\nimport NonFungibleToken from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\nimport FlowToken from 0x0ae53cb6e3f42a79\nimport FUSD from 0xf8d6e0586b0a20c7\nimport Profile from 0xf8d6e0586b0a20c7\n\ntransaction(packTypeId:UInt64, numberOfPacks:UInt64, totalAmount: UFix64) {\n let packs: \u0026Bl0xPack.Collection{Bl0xPack.CollectionPublic}\n\n let userPacks: Capability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.Receiver}\u003e\n let salePrice: UFix64\n let packsLeft: UInt64\n\n let userFlowTokenVault: \u0026FlowToken.Vault\n\n let paymentVault: @FungibleToken.Vault\n let balanceBeforeTransfer:UFix64\n\n prepare(account: AuthAccount) {\n\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n if !findPackCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e( \u003c- Bl0xPack.createEmptyCollection(), to: Bl0xPack.CollectionStoragePath)\n account.link\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0xPack.CollectionPublicPath,\n target: Bl0xPack.CollectionStoragePath\n )\n }\n\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e(\u003c- Bl0x.createEmptyCollection(), to: Bl0x.CollectionStoragePath)\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPublicPath,\n target: Bl0x.CollectionStoragePath\n )\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPrivatePath,\n target: Bl0x.CollectionStoragePath\n )\n }\n\n let profileCap = account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath)\n if !profileCap.check() {\n let profile \u003c-Profile.createUser(name:account.address.toString(), createdAt: \"Bl0x\")\n\n //Add exising FUSD or create a new one and add it\n let fusdReceiver = account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver)\n if !fusdReceiver.check() {\n let fusd \u003c- FUSD.createEmptyVault()\n account.save(\u003c- fusd, to: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Receiver}\u003e( /public/fusdReceiver, target: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Balance}\u003e( /public/fusdBalance, target: /storage/fusdVault)\n }\n\n let fusdWallet=Profile.Wallet(\n name:\"FUSD\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/fusdBalance),\n accept: Type\u003c@FUSD.Vault\u003e(),\n names: [\"fusd\", \"stablecoin\"]\n )\n\n profile.addWallet(fusdWallet)\n\n let flowWallet=Profile.Wallet(\n name:\"Flow\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/flowTokenReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/flowTokenBalance),\n accept: Type\u003c@FlowToken.Vault\u003e(),\n names: [\"flow\"]\n )\n profile.addWallet(flowWallet)\n account.save(\u003c-profile, to: Profile.storagePath)\n account.link\u003c\u0026Profile.User{Profile.Public}\u003e(Profile.publicPath, target: Profile.storagePath)\n account.link\u003c\u0026{FungibleToken.Receiver}\u003e(Profile.publicReceiverPath, target: Profile.storagePath)\n\n\n }\n\n self.userPacks=account.getCapability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.Receiver}\u003e(Bl0xPack.CollectionPublicPath)\n self.packs=Bl0xPack.getPacksCollection()\n\n let packMetadata=Bl0xPack.getMetadata(typeId: packTypeId) ?? panic (\"Could not find pack metadata for the given type\") \n self.salePrice= packMetadata.price\n self.packsLeft= self.packs.getPacksLeftForType(packTypeId)\n\n\n self.userFlowTokenVault = account.borrow\u003c\u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault) ?? panic(\"Cannot borrow FlowToken vault from account storage\")\n self.balanceBeforeTransfer = self.userFlowTokenVault.balance\n\n if self.balanceBeforeTransfer \u003c totalAmount {\n panic(\"Your account does not have enough funds has \".concat(self.balanceBeforeTransfer.toString()).concat(\" needs \").concat(totalAmount.toString()))\n }\n self.paymentVault \u003c- self.userFlowTokenVault.withdraw(amount: totalAmount)\n }\n\n pre {\n self.salePrice * UFix64(numberOfPacks) == totalAmount: \"unexpected sending amount\"\n self.packsLeft \u003e= numberOfPacks : \"Rats! there are no packs left\"\n self.userPacks.check() : \"User need a receiver to put the pack in\"\n }\n\n execute {\n var counter = numberOfPacks\n while counter \u003e 0 {\n let purchasingVault \u003c- self.paymentVault.withdraw(amount: self.salePrice)\n self.packs.buy(typeId:packTypeId, vault: \u003c- purchasingVault, collectionCapability: self.userPacks)\n counter = counter - 1\n }\n destroy self.paymentVault\n }\n\n}",
"spec": {
"order": [
"packTypeId",
"numberOfPacks",
"totalAmount"
],
"parameters": {
"numberOfPacks": "UInt64",
"packTypeId": "UInt64",
"totalAmount": "UFix64"
}
}
},
"initUser": {
"code": "import Bl0x from 0xf8d6e0586b0a20c7\nimport Bl0xPack from 0xf8d6e0586b0a20c7\nimport NonFungibleToken from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\nimport Profile from 0xf8d6e0586b0a20c7\nimport FungibleToken from 0xee82856bf20e2aa6\nimport FUSD from 0xf8d6e0586b0a20c7\nimport FlowToken from 0x0ae53cb6e3f42a79\n\n//Initialize a users storage slots for bl0x\ntransaction {\n prepare(account: AuthAccount) {\n\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n if !findPackCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e( \u003c- Bl0xPack.createEmptyCollection(), to: Bl0xPack.CollectionStoragePath)\n account.link\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0xPack.CollectionPublicPath,\n target: Bl0xPack.CollectionStoragePath\n )\n }\n\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e(\u003c- Bl0x.createEmptyCollection(), to: Bl0x.CollectionStoragePath)\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPublicPath,\n target: Bl0x.CollectionStoragePath\n )\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPrivatePath,\n target: Bl0x.CollectionStoragePath\n )\n }\n\n let profileCap = account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath)\n if profileCap.check() {\n return \n }\n let profile \u003c-Profile.createUser(name:account.address.toString(), createdAt: \"Bl0x\")\n\n //Add exising FUSD or create a new one and add it\n let fusdReceiver = account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver)\n if !fusdReceiver.check() {\n let fusd \u003c- FUSD.createEmptyVault()\n account.save(\u003c- fusd, to: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Receiver}\u003e( /public/fusdReceiver, target: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Balance}\u003e( /public/fusdBalance, target: /storage/fusdVault)\n }\n\n let fusdWallet=Profile.Wallet(\n name:\"FUSD\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/fusdBalance),\n accept: Type\u003c@FUSD.Vault\u003e(),\n names: [\"fusd\", \"stablecoin\"]\n )\n\n profile.addWallet(fusdWallet)\n\n let flowWallet=Profile.Wallet(\n name:\"Flow\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/flowTokenReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/flowTokenBalance),\n accept: Type\u003c@FlowToken.Vault\u003e(),\n names: [\"flow\"]\n )\n profile.addWallet(flowWallet)\n account.save(\u003c-profile, to: Profile.storagePath)\n account.link\u003c\u0026Profile.User{Profile.Public}\u003e(Profile.publicPath, target: Profile.storagePath)\n account.link\u003c\u0026{FungibleToken.Receiver}\u003e(Profile.publicReceiverPath, target: Profile.storagePath)\n\n\n }\n}",
"spec": null
},
"openPack": {
"code": "import Bl0x from 0xf8d6e0586b0a20c7\nimport Bl0xPack from 0xf8d6e0586b0a20c7\nimport FungibleToken from 0xee82856bf20e2aa6\nimport NonFungibleToken from 0xf8d6e0586b0a20c7\nimport MetadataViews from 0xf8d6e0586b0a20c7\n\n/// A transaction to open a pack with a given id\n/// @param packId: The id of the pack to open\ntransaction(packId:UInt64) {\n\n let packs: \u0026Bl0xPack.Collection\n let receiver: Capability\u003c\u0026{NonFungibleToken.Receiver}\u003e\n\n prepare(account: AuthAccount) {\n self.packs=account.borrow\u003c\u0026Bl0xPack.Collection\u003e(from: Bl0xPack.CollectionStoragePath)!\n self.receiver = account.getCapability\u003c\u0026{NonFungibleToken.Receiver}\u003e(Bl0x.CollectionPublicPath)\n }\n\n pre {\n self.receiver.check() : \"The receiver collection for the packs is not present\"\n }\n execute {\n self.packs.open(packId: packId, receiverCap:self.receiver)\n }\n\n post {\n !self.packs.getIDs().contains(packId) : \"The pack is still present in the users collection\"\n }\n}",
"spec": {
"order": [
"packId"
],
"parameters": {
"packId": "UInt64"
}
}
},
"sendBl0x": {
"code": "import Bl0x from 0xf8d6e0586b0a20c7\nimport NonFungibleToken from 0xf8d6e0586b0a20c7\n\ntransaction(receiverAddr: Address, id: UInt64) {\n let bl0xCollectionRef: \u0026Bl0x.Collection\n let receiverCollectionCap: Capability\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic}\u003e\n\n prepare(account: AuthAccount) {\n self.bl0xCollectionRef = account.borrow\u003c\u0026Bl0x.Collection\u003e(from: Bl0x.CollectionStoragePath) ?? panic(\"Could not borrow Bl0x Collection\")\n self.receiverCollectionCap = getAccount(receiverAddr).getCapability\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n }\n\n pre{\n self.receiverCollectionCap.check() : \"The receiver do not have Bl0x Collection set up.\"\n }\n\n execute {\n let receiverCollectionRef = self.receiverCollectionCap.borrow()!\n let nft \u003c- self.bl0xCollectionRef.withdraw(withdrawID: id)\n receiverCollectionRef.deposit(token: \u003c- nft)\n }\n}",
"spec": {
"order": [
"receiverAddr",
"id"
],
"parameters": {
"id": "UInt64",
"receiverAddr": "Address"
}
}
},
"sendPack": {
"code": "import Bl0xPack from 0xf8d6e0586b0a20c7\nimport NonFungibleToken from 0xf8d6e0586b0a20c7\n\ntransaction(receiverAddr: Address, id:UInt64) {\n let bl0xPackCollectionRef: \u0026Bl0xPack.Collection\n let receiverCollectionCap: Capability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic}\u003e\n\n prepare(account: AuthAccount) {\n self.bl0xPackCollectionRef = account.borrow\u003c\u0026Bl0xPack.Collection\u003e(from: Bl0xPack.CollectionStoragePath) ?? panic(\"Could not borrow Bl0x Pack Collection\")\n self.receiverCollectionCap = getAccount(receiverAddr).getCapability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n }\n\n pre{\n self.receiverCollectionCap.check() : \"The receiver do not have Bl0x Pack Collection set up.\"\n }\n\n execute {\n let receiverCollectionRef = self.receiverCollectionCap.borrow()!\n let nft \u003c- self.bl0xPackCollectionRef.withdraw(withdrawID: id)\n receiverCollectionRef.deposit(token: \u003c- nft)\n }\n}",
"spec": {
"order": [
"receiverAddr",
"id"
],
"parameters": {
"id": "UInt64",
"receiverAddr": "Address"
}
}
}
}
},
"mainnet": {
"scripts": {
"bl0x": {
"code": "import Bl0x from 0x7620acf6d7f2468a\nimport MetadataViews from 0x1d7e57aa55817448\n\npub fun main(address: Address, id:UInt64) : Bl0x.Metadata? {\n let account=getAccount(address)\n /* Check on bl0xPack */\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n return nil\n }\n let bl0x = bl0xCap.borrow()!\n return bl0x.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n}",
"spec": {
"order": [
"address",
"id"
],
"parameters": {
"address": "Address",
"id": "UInt64"
}
}
},
"bl0xByName": {
"code": "import Bl0x from 0x7620acf6d7f2468a\nimport FIND from 0x097bafa4e0b48eef\nimport MetadataViews from 0x1d7e57aa55817448\n\npub fun main(name: String, id:UInt64) : Bl0x.Metadata? {\n\n let address = FIND.lookupAddress(name)\n\n if address == nil {\n return nil\n }\n let account=getAccount(address!)\n /* Check on bl0xPack */\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n return nil\n }\n let bl0x = bl0xCap.borrow()!\n return bl0x.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n}",
"spec": {
"order": [
"name",
"id"
],
"parameters": {
"id": "UInt64",
"name": "String"
}
}
},
"ids": {
"code": "import NonFungibleToken from 0x1d7e57aa55817448\nimport MetadataViews from 0x1d7e57aa55817448\n\n//get all the views for an nft and address/path/id\npub fun main(address: Address, path:PublicPath) : [UInt64] {\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n return collection.getIDs()\n}",
"spec": {
"order": [
"address",
"path"
],
"parameters": {
"address": "Address",
"path": "PublicPath"
}
}
},
"packTypeStatus": {
"code": "import MetadataViews from 0x1d7e57aa55817448\nimport Bl0xPack from 0x7620acf6d7f2468a\n\npub struct BloxPackStatus {\n pub let remainingPacks: UInt64\n pub let whiteListTime: UFix64?\n pub let floatEventId: UInt64?\n pub let buyTime: UFix64\n pub let openTime: UFix64\n pub let price: UFix64\n pub let walletType: String \n pub let typeId: UInt64\n pub let thumbnail: String\n\n init(remainingPacks: UInt64 , \n whiteListTime: UFix64? ,\n floatEventId: UInt64?,\n buyTime: UFix64 ,\n openTime: UFix64 ,\n price: UFix64 ,\n walletType: String ,\n typeId: UInt64,\n thumbnail:String\n ) {\n self.remainingPacks = remainingPacks\n self.whiteListTime = whiteListTime\n self.floatEventId = floatEventId\n self.buyTime = buyTime\n self.openTime = openTime\n self.price = price\n self.walletType = walletType\n self.typeId = typeId\n self.thumbnail=thumbnail\n }\n}\npub fun main(address: Address, typeId: UInt64) : BloxPackStatus {\n\n let collectionRef = getAccount(address).getCapability(Bl0xPack.CollectionPublicPath).borrow\u003c\u0026Bl0xPack.Collection{Bl0xPack.CollectionPublic}\u003e()!\n let remainingPacks = collectionRef.getPacksLeftForType(typeId)\n let metadata = Bl0xPack.getMetadata(typeId: typeId) ?? panic(\"Cannot get metadata of this type :\".concat(typeId.toString()))\n return BloxPackStatus(remainingPacks: remainingPacks, \n whiteListTime: metadata.whiteListTime, \n floatEventId: metadata.floatEventId, \n buyTime: metadata.buyTime, \n openTime: metadata.openTime, \n price: metadata.price, \n walletType: metadata.walletType.identifier,\n typeId: typeId, \n thumbnail: metadata.getThumbnail().uri()\n )\n}",
"spec": {
"order": [
"address",
"typeId"
],
"parameters": {
"address": "Address",
"typeId": "UInt64"
}
}
},
"packsRemaining": {
"code": "import MetadataViews from 0x1d7e57aa55817448\nimport Bl0xPack from 0x7620acf6d7f2468a\n\npub fun main(address: Address) : Int {\n\n let collection= getAccount(address).getCapability(Bl0xPack.CollectionPublicPath).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n return collection.getIDs().length\n}",
"spec": {
"order": [
"address"
],
"parameters": {
"address": "Address"
}
}
},
"validUser": {
"code": "import Bl0xPack from 0x7620acf6d7f2468a\nimport Bl0x from 0x7620acf6d7f2468a\nimport NonFungibleToken from 0x1d7e57aa55817448\n\npub fun main(target: Address) : Bool {\n\n let account=getAccount(target)\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n\n return findPackCap.check() \u0026\u0026 bl0xCap.check()\n}",
"spec": {
"order": [
"target"
],
"parameters": {
"target": "Address"
}
}
},
"view": {
"code": "import NonFungibleToken from 0x1d7e57aa55817448\nimport MetadataViews from 0x1d7e57aa55817448\n\n//Fetch a single view from a nft on a given path\npub fun main(address: Address, path:PublicPath, id: UInt64, identifier: String) : AnyStruct? {\n\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n\n let nft=collection.borrowViewResolver(id: id)\n for v in nft.getViews() {\n if v.identifier== identifier {\n return nft.resolveView(v)\n }\n }\n return nil\n}",
"spec": {
"order": [
"address",
"path",
"id",
"identifier"
],
"parameters": {
"address": "Address",
"id": "UInt64",
"identifier": "String",
"path": "PublicPath"
}
}
},
"viewUser": {
"code": "import Profile from 0x097bafa4e0b48eef\nimport Bl0xPack from 0x7620acf6d7f2468a\nimport Bl0x from 0x7620acf6d7f2468a\nimport MetadataViews from 0x1d7e57aa55817448\nimport FLOAT from 0x2d4c3caffbeab845\n\npub struct FINDNameBl0xReport{\n pub let profile: Profile.UserProfile?\n pub let bl0xPack: [Bl0xPackData] // empty array means empty collection. nil means no collection set up\n pub let bl0x: [Bl0x.Metadata] // empty array means empty collection. nil means no collection set up\n pub let canByPack:Bool\n\n init(profile: Profile.UserProfile?, bl0xPack: [Bl0xPackData] , bl0x: [Bl0x.Metadata], canByPack:Bool) {\n self.profile = profile\n self.bl0xPack = bl0xPack \n self.bl0x = bl0x\n self.canByPack=canByPack\n }\n}\n\npub struct Bl0xPackData {\n pub let id : UInt64\n pub let name : String \n pub let image : String \n pub let canBeOpened : Bool \n\n init(id: UInt64, name: String, image: String, canBeOpened: Bool) {\n self.id = id \n self.name = name \n self.image = image \n self.canBeOpened = canBeOpened\n }\n}\n\npub fun main(address: Address) : FINDNameBl0xReport{\n\n let packTypeId:UInt64=2\n let account=getAccount(address)\n /* Check on profile */\n let profile= account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath).borrow()?.asProfile()\n\n /* Check on bl0xPack */\n var bl0xPack : [Bl0xPackData] = []\n let bl0xPackCap = account.getCapability\u003c\u0026Bl0xPack.Collection{MetadataViews.ResolverCollection}\u003e(Bl0xPack.CollectionPublicPath)\n if bl0xPackCap.check() {\n let bl0xPackIds = bl0xPackCap.borrow()!.getIDs()\n for id in bl0xPackIds {\n let Bl0xPackMetadata=bl0xPackCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0xPack.Metadata\u003e())! as! Bl0xPack.Metadata\n let metadata = Bl0xPackData(id: id, name: Bl0xPackMetadata.name, image: Bl0xPackMetadata.getThumbnail().uri(), canBeOpened: Bl0xPackMetadata.canBeOpened())\n bl0xPack.append(metadata)\n }\n }\n\n /* Check on bl0xPack */\n var bl0x : [Bl0x.Metadata] = []\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if bl0xCap.check() {\n let bl0xIds = bl0xCap.borrow()!.getIDs()\n for id in bl0xIds {\n let metadata=bl0xCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n bl0x.append(metadata)\n }\n }\n\n\n \n return FINDNameBl0xReport(\n profile: profile,\n bl0xPack: bl0xPack, \n bl0x: bl0x,\n canByPack: Bl0xPack.canBuy(packTypeId: packTypeId, user:address)\n )\n\n}",
"spec": {
"order": [
"address"
],
"parameters": {
"address": "Address"
}
}
},
"viewUserByName": {
"code": "import Profile from 0x097bafa4e0b48eef\nimport Bl0xPack from 0x7620acf6d7f2468a\nimport Bl0x from 0x7620acf6d7f2468a\nimport MetadataViews from 0x1d7e57aa55817448\nimport FIND from 0x097bafa4e0b48eef\n\npub struct FINDNameBl0xReport{\n pub let profile: Profile.UserProfile?\n pub let bl0xPack: [Bl0xPackData] // empty array means empty collection. nil means no collection set up\n pub let bl0x: [Bl0x.Metadata] // empty array means empty collection. nil means no collection set up\n\n init(profile: Profile.UserProfile?, bl0xPack: [Bl0xPackData] , bl0x: [Bl0x.Metadata]) {\n self.profile = profile\n self.bl0xPack = bl0xPack \n self.bl0x = bl0x\n }\n}\n\npub struct Bl0xPackData {\n pub let id : UInt64\n pub let name : String \n pub let image : String \n pub let canBeOpened : Bool \n\n init(id: UInt64, name: String, image: String, canBeOpened: Bool) {\n self.id = id \n self.name = name \n self.image = image \n self.canBeOpened = canBeOpened\n }\n}\n\npub fun main(name: String) : FINDNameBl0xReport{\n\n let address = FIND.lookupAddress(name) ?? panic(\"Name not found\")\n let account=getAccount(address)\n /* Check on profile */\n let profile= account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath).borrow()?.asProfile()\n\n /* Check on bl0xPack */\n var bl0xPack : [Bl0xPackData] = []\n let bl0xPackCap = account.getCapability\u003c\u0026Bl0xPack.Collection{MetadataViews.ResolverCollection}\u003e(Bl0xPack.CollectionPublicPath)\n if bl0xPackCap.check() {\n let bl0xPackIds = bl0xPackCap.borrow()!.getIDs()\n for id in bl0xPackIds {\n let Bl0xPackMetadata=bl0xPackCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0xPack.Metadata\u003e())! as! Bl0xPack.Metadata\n let metadata = Bl0xPackData(id: id, name: Bl0xPackMetadata.name, image: Bl0xPackMetadata.getThumbnail().uri(), canBeOpened: Bl0xPackMetadata.canBeOpened())\n bl0xPack.append(metadata)\n }\n }\n\n var bl0x : [Bl0x.Metadata] = []\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if bl0xCap.check() {\n let bl0xIds = bl0xCap.borrow()!.getIDs()\n for id in bl0xIds {\n let metadata=bl0xCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n bl0x.append(metadata)\n }\n }\n\n return FINDNameBl0xReport(\n profile: profile,\n bl0xPack: bl0xPack, \n bl0x: bl0x\n )\n\n}",
"spec": {
"order": [
"name"
],
"parameters": {
"name": "String"
}
}
},
"views": {
"code": "import NonFungibleToken from 0x1d7e57aa55817448\nimport MetadataViews from 0x1d7e57aa55817448\n\n//get all the views for an nft and address/path/id\npub fun main(address: Address, path:PublicPath, id: UInt64) : [String] {\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n let nft=collection.borrowViewResolver(id: id)\n let views:[String]=[]\n for v in nft.getViews() {\n views.append(v.identifier)\n }\n return views\n}",
"spec": {
"order": [
"address",
"path",
"id"
],
"parameters": {
"address": "Address",
"id": "UInt64",
"path": "PublicPath"
}
}
}
},
"transactions": {
"buyPack": {
"code": "import Bl0xPack from 0x7620acf6d7f2468a\nimport Bl0x from 0x7620acf6d7f2468a\nimport FungibleToken from 0xf233dcee88fe0abe\nimport NonFungibleToken from 0x1d7e57aa55817448\nimport MetadataViews from 0x1d7e57aa55817448\nimport FlowToken from 0x1654653399040a61\nimport FUSD from 0x3c5959b568896393\nimport Profile from 0x097bafa4e0b48eef\n\ntransaction(packTypeId:UInt64, numberOfPacks:UInt64, totalAmount: UFix64) {\n let packs: \u0026Bl0xPack.Collection{Bl0xPack.CollectionPublic}\n\n let userPacks: Capability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.Receiver}\u003e\n let salePrice: UFix64\n let packsLeft: UInt64\n\n let userFlowTokenVault: \u0026FlowToken.Vault\n\n let paymentVault: @FungibleToken.Vault\n let balanceBeforeTransfer:UFix64\n\n prepare(account: AuthAccount) {\n\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n if !findPackCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e( \u003c- Bl0xPack.createEmptyCollection(), to: Bl0xPack.CollectionStoragePath)\n account.link\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0xPack.CollectionPublicPath,\n target: Bl0xPack.CollectionStoragePath\n )\n }\n\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e(\u003c- Bl0x.createEmptyCollection(), to: Bl0x.CollectionStoragePath)\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPublicPath,\n target: Bl0x.CollectionStoragePath\n )\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPrivatePath,\n target: Bl0x.CollectionStoragePath\n )\n }\n\n let profileCap = account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath)\n if !profileCap.check() {\n let profile \u003c-Profile.createUser(name:account.address.toString(), createdAt: \"Bl0x\")\n\n //Add exising FUSD or create a new one and add it\n let fusdReceiver = account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver)\n if !fusdReceiver.check() {\n let fusd \u003c- FUSD.createEmptyVault()\n account.save(\u003c- fusd, to: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Receiver}\u003e( /public/fusdReceiver, target: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Balance}\u003e( /public/fusdBalance, target: /storage/fusdVault)\n }\n\n let fusdWallet=Profile.Wallet(\n name:\"FUSD\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/fusdBalance),\n accept: Type\u003c@FUSD.Vault\u003e(),\n names: [\"fusd\", \"stablecoin\"]\n )\n\n profile.addWallet(fusdWallet)\n\n let flowWallet=Profile.Wallet(\n name:\"Flow\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/flowTokenReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/flowTokenBalance),\n accept: Type\u003c@FlowToken.Vault\u003e(),\n names: [\"flow\"]\n )\n profile.addWallet(flowWallet)\n account.save(\u003c-profile, to: Profile.storagePath)\n account.link\u003c\u0026Profile.User{Profile.Public}\u003e(Profile.publicPath, target: Profile.storagePath)\n account.link\u003c\u0026{FungibleToken.Receiver}\u003e(Profile.publicReceiverPath, target: Profile.storagePath)\n\n\n }\n\n self.userPacks=account.getCapability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.Receiver}\u003e(Bl0xPack.CollectionPublicPath)\n self.packs=Bl0xPack.getPacksCollection()\n\n let packMetadata=Bl0xPack.getMetadata(typeId: packTypeId) ?? panic (\"Could not find pack metadata for the given type\") \n self.salePrice= packMetadata.price\n self.packsLeft= self.packs.getPacksLeftForType(packTypeId)\n\n\n self.userFlowTokenVault = account.borrow\u003c\u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault) ?? panic(\"Cannot borrow FlowToken vault from account storage\")\n self.balanceBeforeTransfer = self.userFlowTokenVault.balance\n\n if self.balanceBeforeTransfer \u003c totalAmount {\n panic(\"Your account does not have enough funds has \".concat(self.balanceBeforeTransfer.toString()).concat(\" needs \").concat(totalAmount.toString()))\n }\n self.paymentVault \u003c- self.userFlowTokenVault.withdraw(amount: totalAmount)\n }\n\n pre {\n self.salePrice * UFix64(numberOfPacks) == totalAmount: \"unexpected sending amount\"\n self.packsLeft \u003e= numberOfPacks : \"Rats! there are no packs left\"\n self.userPacks.check() : \"User need a receiver to put the pack in\"\n }\n\n execute {\n var counter = numberOfPacks\n while counter \u003e 0 {\n let purchasingVault \u003c- self.paymentVault.withdraw(amount: self.salePrice)\n self.packs.buy(typeId:packTypeId, vault: \u003c- purchasingVault, collectionCapability: self.userPacks)\n counter = counter - 1\n }\n destroy self.paymentVault\n }\n\n}",
"spec": {
"order": [
"packTypeId",
"numberOfPacks",
"totalAmount"
],
"parameters": {
"numberOfPacks": "UInt64",
"packTypeId": "UInt64",
"totalAmount": "UFix64"
}
}
},
"initUser": {
"code": "import Bl0x from 0x7620acf6d7f2468a\nimport Bl0xPack from 0x7620acf6d7f2468a\nimport NonFungibleToken from 0x1d7e57aa55817448\nimport MetadataViews from 0x1d7e57aa55817448\nimport Profile from 0x097bafa4e0b48eef\nimport FungibleToken from 0xf233dcee88fe0abe\nimport FUSD from 0x3c5959b568896393\nimport FlowToken from 0x1654653399040a61\n\n//Initialize a users storage slots for bl0x\ntransaction {\n prepare(account: AuthAccount) {\n\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n if !findPackCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e( \u003c- Bl0xPack.createEmptyCollection(), to: Bl0xPack.CollectionStoragePath)\n account.link\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0xPack.CollectionPublicPath,\n target: Bl0xPack.CollectionStoragePath\n )\n }\n\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e(\u003c- Bl0x.createEmptyCollection(), to: Bl0x.CollectionStoragePath)\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPublicPath,\n target: Bl0x.CollectionStoragePath\n )\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPrivatePath,\n target: Bl0x.CollectionStoragePath\n )\n }\n\n let profileCap = account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath)\n if profileCap.check() {\n return \n }\n let profile \u003c-Profile.createUser(name:account.address.toString(), createdAt: \"Bl0x\")\n\n //Add exising FUSD or create a new one and add it\n let fusdReceiver = account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver)\n if !fusdReceiver.check() {\n let fusd \u003c- FUSD.createEmptyVault()\n account.save(\u003c- fusd, to: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Receiver}\u003e( /public/fusdReceiver, target: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Balance}\u003e( /public/fusdBalance, target: /storage/fusdVault)\n }\n\n let fusdWallet=Profile.Wallet(\n name:\"FUSD\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/fusdBalance),\n accept: Type\u003c@FUSD.Vault\u003e(),\n names: [\"fusd\", \"stablecoin\"]\n )\n\n profile.addWallet(fusdWallet)\n\n let flowWallet=Profile.Wallet(\n name:\"Flow\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/flowTokenReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/flowTokenBalance),\n accept: Type\u003c@FlowToken.Vault\u003e(),\n names: [\"flow\"]\n )\n profile.addWallet(flowWallet)\n account.save(\u003c-profile, to: Profile.storagePath)\n account.link\u003c\u0026Profile.User{Profile.Public}\u003e(Profile.publicPath, target: Profile.storagePath)\n account.link\u003c\u0026{FungibleToken.Receiver}\u003e(Profile.publicReceiverPath, target: Profile.storagePath)\n\n\n }\n}",
"spec": null
},
"openPack": {
"code": "import Bl0x from 0x7620acf6d7f2468a\nimport Bl0xPack from 0x7620acf6d7f2468a\nimport FungibleToken from 0xf233dcee88fe0abe\nimport NonFungibleToken from 0x1d7e57aa55817448\nimport MetadataViews from 0x1d7e57aa55817448\n\n/// A transaction to open a pack with a given id\n/// @param packId: The id of the pack to open\ntransaction(packId:UInt64) {\n\n let packs: \u0026Bl0xPack.Collection\n let receiver: Capability\u003c\u0026{NonFungibleToken.Receiver}\u003e\n\n prepare(account: AuthAccount) {\n self.packs=account.borrow\u003c\u0026Bl0xPack.Collection\u003e(from: Bl0xPack.CollectionStoragePath)!\n self.receiver = account.getCapability\u003c\u0026{NonFungibleToken.Receiver}\u003e(Bl0x.CollectionPublicPath)\n }\n\n pre {\n self.receiver.check() : \"The receiver collection for the packs is not present\"\n }\n execute {\n self.packs.open(packId: packId, receiverCap:self.receiver)\n }\n\n post {\n !self.packs.getIDs().contains(packId) : \"The pack is still present in the users collection\"\n }\n}",
"spec": {
"order": [
"packId"
],
"parameters": {
"packId": "UInt64"
}
}
},
"sendBl0x": {
"code": "import Bl0x from 0x7620acf6d7f2468a\nimport NonFungibleToken from 0x1d7e57aa55817448\n\ntransaction(receiverAddr: Address, id: UInt64) {\n let bl0xCollectionRef: \u0026Bl0x.Collection\n let receiverCollectionCap: Capability\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic}\u003e\n\n prepare(account: AuthAccount) {\n self.bl0xCollectionRef = account.borrow\u003c\u0026Bl0x.Collection\u003e(from: Bl0x.CollectionStoragePath) ?? panic(\"Could not borrow Bl0x Collection\")\n self.receiverCollectionCap = getAccount(receiverAddr).getCapability\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n }\n\n pre{\n self.receiverCollectionCap.check() : \"The receiver do not have Bl0x Collection set up.\"\n }\n\n execute {\n let receiverCollectionRef = self.receiverCollectionCap.borrow()!\n let nft \u003c- self.bl0xCollectionRef.withdraw(withdrawID: id)\n receiverCollectionRef.deposit(token: \u003c- nft)\n }\n}",
"spec": {
"order": [
"receiverAddr",
"id"
],
"parameters": {
"id": "UInt64",
"receiverAddr": "Address"
}
}
},
"sendPack": {
"code": "import Bl0xPack from 0x7620acf6d7f2468a\nimport NonFungibleToken from 0x1d7e57aa55817448\n\ntransaction(receiverAddr: Address, id:UInt64) {\n let bl0xPackCollectionRef: \u0026Bl0xPack.Collection\n let receiverCollectionCap: Capability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic}\u003e\n\n prepare(account: AuthAccount) {\n self.bl0xPackCollectionRef = account.borrow\u003c\u0026Bl0xPack.Collection\u003e(from: Bl0xPack.CollectionStoragePath) ?? panic(\"Could not borrow Bl0x Pack Collection\")\n self.receiverCollectionCap = getAccount(receiverAddr).getCapability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n }\n\n pre{\n self.receiverCollectionCap.check() : \"The receiver do not have Bl0x Pack Collection set up.\"\n }\n\n execute {\n let receiverCollectionRef = self.receiverCollectionCap.borrow()!\n let nft \u003c- self.bl0xPackCollectionRef.withdraw(withdrawID: id)\n receiverCollectionRef.deposit(token: \u003c- nft)\n }\n}",
"spec": {
"order": [
"receiverAddr",
"id"
],
"parameters": {
"id": "UInt64",
"receiverAddr": "Address"
}
}
}
}
},
"testnet": {
"scripts": {
"bl0x": {
"code": "import Bl0x from 0xe8124d8428980aa6\nimport MetadataViews from 0x631e88ae7f1d7c20\n\npub fun main(address: Address, id:UInt64) : Bl0x.Metadata? {\n let account=getAccount(address)\n /* Check on bl0xPack */\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n return nil\n }\n let bl0x = bl0xCap.borrow()!\n return bl0x.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n}",
"spec": {
"order": [
"address",
"id"
],
"parameters": {
"address": "Address",
"id": "UInt64"
}
}
},
"bl0xByName": {
"code": "import Bl0x from 0xe8124d8428980aa6\nimport FIND from 0xa16ab1d0abde3625\nimport MetadataViews from 0x631e88ae7f1d7c20\n\npub fun main(name: String, id:UInt64) : Bl0x.Metadata? {\n\n let address = FIND.lookupAddress(name)\n\n if address == nil {\n return nil\n }\n let account=getAccount(address!)\n /* Check on bl0xPack */\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n return nil\n }\n let bl0x = bl0xCap.borrow()!\n return bl0x.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n}",
"spec": {
"order": [
"name",
"id"
],
"parameters": {
"id": "UInt64",
"name": "String"
}
}
},
"ids": {
"code": "import NonFungibleToken from 0x631e88ae7f1d7c20\nimport MetadataViews from 0x631e88ae7f1d7c20\n\n//get all the views for an nft and address/path/id\npub fun main(address: Address, path:PublicPath) : [UInt64] {\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n return collection.getIDs()\n}",
"spec": {
"order": [
"address",
"path"
],
"parameters": {
"address": "Address",
"path": "PublicPath"
}
}
},
"packTypeStatus": {
"code": "import MetadataViews from 0x631e88ae7f1d7c20\nimport Bl0xPack from 0xe8124d8428980aa6\n\npub struct BloxPackStatus {\n pub let remainingPacks: UInt64\n pub let whiteListTime: UFix64?\n pub let floatEventId: UInt64?\n pub let buyTime: UFix64\n pub let openTime: UFix64\n pub let price: UFix64\n pub let walletType: String \n pub let typeId: UInt64\n pub let thumbnail: String\n\n init(remainingPacks: UInt64 , \n whiteListTime: UFix64? ,\n floatEventId: UInt64?,\n buyTime: UFix64 ,\n openTime: UFix64 ,\n price: UFix64 ,\n walletType: String ,\n typeId: UInt64,\n thumbnail:String\n ) {\n self.remainingPacks = remainingPacks\n self.whiteListTime = whiteListTime\n self.floatEventId = floatEventId\n self.buyTime = buyTime\n self.openTime = openTime\n self.price = price\n self.walletType = walletType\n self.typeId = typeId\n self.thumbnail=thumbnail\n }\n}\npub fun main(address: Address, typeId: UInt64) : BloxPackStatus {\n\n let collectionRef = getAccount(address).getCapability(Bl0xPack.CollectionPublicPath).borrow\u003c\u0026Bl0xPack.Collection{Bl0xPack.CollectionPublic}\u003e()!\n let remainingPacks = collectionRef.getPacksLeftForType(typeId)\n let metadata = Bl0xPack.getMetadata(typeId: typeId) ?? panic(\"Cannot get metadata of this type :\".concat(typeId.toString()))\n return BloxPackStatus(remainingPacks: remainingPacks, \n whiteListTime: metadata.whiteListTime, \n floatEventId: metadata.floatEventId, \n buyTime: metadata.buyTime, \n openTime: metadata.openTime, \n price: metadata.price, \n walletType: metadata.walletType.identifier,\n typeId: typeId, \n thumbnail: metadata.getThumbnail().uri()\n )\n}",
"spec": {
"order": [
"address",
"typeId"
],
"parameters": {
"address": "Address",
"typeId": "UInt64"
}
}
},
"packsRemaining": {
"code": "import MetadataViews from 0x631e88ae7f1d7c20\nimport Bl0xPack from 0xe8124d8428980aa6\n\npub fun main(address: Address) : Int {\n\n let collection= getAccount(address).getCapability(Bl0xPack.CollectionPublicPath).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n return collection.getIDs().length\n}",
"spec": {
"order": [
"address"
],
"parameters": {
"address": "Address"
}
}
},
"validUser": {
"code": "import Bl0xPack from 0xe8124d8428980aa6\nimport Bl0x from 0xe8124d8428980aa6\nimport NonFungibleToken from 0x631e88ae7f1d7c20\n\npub fun main(target: Address) : Bool {\n\n let account=getAccount(target)\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n\n return findPackCap.check() \u0026\u0026 bl0xCap.check()\n}",
"spec": {
"order": [
"target"
],
"parameters": {
"target": "Address"
}
}
},
"view": {
"code": "import NonFungibleToken from 0x631e88ae7f1d7c20\nimport MetadataViews from 0x631e88ae7f1d7c20\n\n//Fetch a single view from a nft on a given path\npub fun main(address: Address, path:PublicPath, id: UInt64, identifier: String) : AnyStruct? {\n\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n\n let nft=collection.borrowViewResolver(id: id)\n for v in nft.getViews() {\n if v.identifier== identifier {\n return nft.resolveView(v)\n }\n }\n return nil\n}",
"spec": {
"order": [
"address",
"path",
"id",
"identifier"
],
"parameters": {
"address": "Address",
"id": "UInt64",
"identifier": "String",
"path": "PublicPath"
}
}
},
"viewUser": {
"code": "import Profile from 0xa16ab1d0abde3625\nimport Bl0xPack from 0xe8124d8428980aa6\nimport Bl0x from 0xe8124d8428980aa6\nimport MetadataViews from 0x631e88ae7f1d7c20\nimport FLOAT from 0x0afe396ebc8eee65\n\npub struct FINDNameBl0xReport{\n pub let profile: Profile.UserProfile?\n pub let bl0xPack: [Bl0xPackData] // empty array means empty collection. nil means no collection set up\n pub let bl0x: [Bl0x.Metadata] // empty array means empty collection. nil means no collection set up\n pub let canByPack:Bool\n\n init(profile: Profile.UserProfile?, bl0xPack: [Bl0xPackData] , bl0x: [Bl0x.Metadata], canByPack:Bool) {\n self.profile = profile\n self.bl0xPack = bl0xPack \n self.bl0x = bl0x\n self.canByPack=canByPack\n }\n}\n\npub struct Bl0xPackData {\n pub let id : UInt64\n pub let name : String \n pub let image : String \n pub let canBeOpened : Bool \n\n init(id: UInt64, name: String, image: String, canBeOpened: Bool) {\n self.id = id \n self.name = name \n self.image = image \n self.canBeOpened = canBeOpened\n }\n}\n\npub fun main(address: Address) : FINDNameBl0xReport{\n\n let packTypeId:UInt64=2\n let account=getAccount(address)\n /* Check on profile */\n let profile= account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath).borrow()?.asProfile()\n\n /* Check on bl0xPack */\n var bl0xPack : [Bl0xPackData] = []\n let bl0xPackCap = account.getCapability\u003c\u0026Bl0xPack.Collection{MetadataViews.ResolverCollection}\u003e(Bl0xPack.CollectionPublicPath)\n if bl0xPackCap.check() {\n let bl0xPackIds = bl0xPackCap.borrow()!.getIDs()\n for id in bl0xPackIds {\n let Bl0xPackMetadata=bl0xPackCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0xPack.Metadata\u003e())! as! Bl0xPack.Metadata\n let metadata = Bl0xPackData(id: id, name: Bl0xPackMetadata.name, image: Bl0xPackMetadata.getThumbnail().uri(), canBeOpened: Bl0xPackMetadata.canBeOpened())\n bl0xPack.append(metadata)\n }\n }\n\n /* Check on bl0xPack */\n var bl0x : [Bl0x.Metadata] = []\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if bl0xCap.check() {\n let bl0xIds = bl0xCap.borrow()!.getIDs()\n for id in bl0xIds {\n let metadata=bl0xCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n bl0x.append(metadata)\n }\n }\n\n\n \n return FINDNameBl0xReport(\n profile: profile,\n bl0xPack: bl0xPack, \n bl0x: bl0x,\n canByPack: Bl0xPack.canBuy(packTypeId: packTypeId, user:address)\n )\n\n}",
"spec": {
"order": [
"address"
],
"parameters": {
"address": "Address"
}
}
},
"viewUserByName": {
"code": "import Profile from 0xa16ab1d0abde3625\nimport Bl0xPack from 0xe8124d8428980aa6\nimport Bl0x from 0xe8124d8428980aa6\nimport MetadataViews from 0x631e88ae7f1d7c20\nimport FIND from 0xa16ab1d0abde3625\n\npub struct FINDNameBl0xReport{\n pub let profile: Profile.UserProfile?\n pub let bl0xPack: [Bl0xPackData] // empty array means empty collection. nil means no collection set up\n pub let bl0x: [Bl0x.Metadata] // empty array means empty collection. nil means no collection set up\n\n init(profile: Profile.UserProfile?, bl0xPack: [Bl0xPackData] , bl0x: [Bl0x.Metadata]) {\n self.profile = profile\n self.bl0xPack = bl0xPack \n self.bl0x = bl0x\n }\n}\n\npub struct Bl0xPackData {\n pub let id : UInt64\n pub let name : String \n pub let image : String \n pub let canBeOpened : Bool \n\n init(id: UInt64, name: String, image: String, canBeOpened: Bool) {\n self.id = id \n self.name = name \n self.image = image \n self.canBeOpened = canBeOpened\n }\n}\n\npub fun main(name: String) : FINDNameBl0xReport{\n\n let address = FIND.lookupAddress(name) ?? panic(\"Name not found\")\n let account=getAccount(address)\n /* Check on profile */\n let profile= account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath).borrow()?.asProfile()\n\n /* Check on bl0xPack */\n var bl0xPack : [Bl0xPackData] = []\n let bl0xPackCap = account.getCapability\u003c\u0026Bl0xPack.Collection{MetadataViews.ResolverCollection}\u003e(Bl0xPack.CollectionPublicPath)\n if bl0xPackCap.check() {\n let bl0xPackIds = bl0xPackCap.borrow()!.getIDs()\n for id in bl0xPackIds {\n let Bl0xPackMetadata=bl0xPackCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0xPack.Metadata\u003e())! as! Bl0xPack.Metadata\n let metadata = Bl0xPackData(id: id, name: Bl0xPackMetadata.name, image: Bl0xPackMetadata.getThumbnail().uri(), canBeOpened: Bl0xPackMetadata.canBeOpened())\n bl0xPack.append(metadata)\n }\n }\n\n var bl0x : [Bl0x.Metadata] = []\n let bl0xCap = account.getCapability\u003c\u0026Bl0x.Collection{MetadataViews.ResolverCollection}\u003e(Bl0x.CollectionPublicPath)\n if bl0xCap.check() {\n let bl0xIds = bl0xCap.borrow()!.getIDs()\n for id in bl0xIds {\n let metadata=bl0xCap.borrow()!.borrowViewResolver(id: id).resolveView(Type\u003cBl0x.Metadata\u003e())! as! Bl0x.Metadata\n bl0x.append(metadata)\n }\n }\n\n return FINDNameBl0xReport(\n profile: profile,\n bl0xPack: bl0xPack, \n bl0x: bl0x\n )\n\n}",
"spec": {
"order": [
"name"
],
"parameters": {
"name": "String"
}
}
},
"views": {
"code": "import NonFungibleToken from 0x631e88ae7f1d7c20\nimport MetadataViews from 0x631e88ae7f1d7c20\n\n//get all the views for an nft and address/path/id\npub fun main(address: Address, path:PublicPath, id: UInt64) : [String] {\n let collection= getAccount(address).getCapability(path).borrow\u003c\u0026{MetadataViews.ResolverCollection}\u003e()!\n let nft=collection.borrowViewResolver(id: id)\n let views:[String]=[]\n for v in nft.getViews() {\n views.append(v.identifier)\n }\n return views\n}",
"spec": {
"order": [
"address",
"path",
"id"
],
"parameters": {
"address": "Address",
"id": "UInt64",
"path": "PublicPath"
}
}
}
},
"transactions": {
"buyPack": {
"code": "import Bl0xPack from 0xe8124d8428980aa6\nimport Bl0x from 0xe8124d8428980aa6\nimport FungibleToken from 0x9a0766d93b6608b7\nimport NonFungibleToken from 0x631e88ae7f1d7c20\nimport MetadataViews from 0x631e88ae7f1d7c20\nimport FlowToken from 0x7e60df042a9c0868\nimport FUSD from 0xe223d8a629e49c68\nimport Profile from 0xa16ab1d0abde3625\n\ntransaction(packTypeId:UInt64, numberOfPacks:UInt64, totalAmount: UFix64) {\n let packs: \u0026Bl0xPack.Collection{Bl0xPack.CollectionPublic}\n\n let userPacks: Capability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.Receiver}\u003e\n let salePrice: UFix64\n let packsLeft: UInt64\n\n let userFlowTokenVault: \u0026FlowToken.Vault\n\n let paymentVault: @FungibleToken.Vault\n let balanceBeforeTransfer:UFix64\n\n prepare(account: AuthAccount) {\n\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n if !findPackCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e( \u003c- Bl0xPack.createEmptyCollection(), to: Bl0xPack.CollectionStoragePath)\n account.link\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0xPack.CollectionPublicPath,\n target: Bl0xPack.CollectionStoragePath\n )\n }\n\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e(\u003c- Bl0x.createEmptyCollection(), to: Bl0x.CollectionStoragePath)\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPublicPath,\n target: Bl0x.CollectionStoragePath\n )\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPrivatePath,\n target: Bl0x.CollectionStoragePath\n )\n }\n\n let profileCap = account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath)\n if !profileCap.check() {\n let profile \u003c-Profile.createUser(name:account.address.toString(), createdAt: \"Bl0x\")\n\n //Add exising FUSD or create a new one and add it\n let fusdReceiver = account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver)\n if !fusdReceiver.check() {\n let fusd \u003c- FUSD.createEmptyVault()\n account.save(\u003c- fusd, to: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Receiver}\u003e( /public/fusdReceiver, target: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Balance}\u003e( /public/fusdBalance, target: /storage/fusdVault)\n }\n\n let fusdWallet=Profile.Wallet(\n name:\"FUSD\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/fusdBalance),\n accept: Type\u003c@FUSD.Vault\u003e(),\n names: [\"fusd\", \"stablecoin\"]\n )\n\n profile.addWallet(fusdWallet)\n\n let flowWallet=Profile.Wallet(\n name:\"Flow\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/flowTokenReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/flowTokenBalance),\n accept: Type\u003c@FlowToken.Vault\u003e(),\n names: [\"flow\"]\n )\n profile.addWallet(flowWallet)\n account.save(\u003c-profile, to: Profile.storagePath)\n account.link\u003c\u0026Profile.User{Profile.Public}\u003e(Profile.publicPath, target: Profile.storagePath)\n account.link\u003c\u0026{FungibleToken.Receiver}\u003e(Profile.publicReceiverPath, target: Profile.storagePath)\n\n\n }\n\n self.userPacks=account.getCapability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.Receiver}\u003e(Bl0xPack.CollectionPublicPath)\n self.packs=Bl0xPack.getPacksCollection()\n\n let packMetadata=Bl0xPack.getMetadata(typeId: packTypeId) ?? panic (\"Could not find pack metadata for the given type\") \n self.salePrice= packMetadata.price\n self.packsLeft= self.packs.getPacksLeftForType(packTypeId)\n\n\n self.userFlowTokenVault = account.borrow\u003c\u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault) ?? panic(\"Cannot borrow FlowToken vault from account storage\")\n self.balanceBeforeTransfer = self.userFlowTokenVault.balance\n\n if self.balanceBeforeTransfer \u003c totalAmount {\n panic(\"Your account does not have enough funds has \".concat(self.balanceBeforeTransfer.toString()).concat(\" needs \").concat(totalAmount.toString()))\n }\n self.paymentVault \u003c- self.userFlowTokenVault.withdraw(amount: totalAmount)\n }\n\n pre {\n self.salePrice * UFix64(numberOfPacks) == totalAmount: \"unexpected sending amount\"\n self.packsLeft \u003e= numberOfPacks : \"Rats! there are no packs left\"\n self.userPacks.check() : \"User need a receiver to put the pack in\"\n }\n\n execute {\n var counter = numberOfPacks\n while counter \u003e 0 {\n let purchasingVault \u003c- self.paymentVault.withdraw(amount: self.salePrice)\n self.packs.buy(typeId:packTypeId, vault: \u003c- purchasingVault, collectionCapability: self.userPacks)\n counter = counter - 1\n }\n destroy self.paymentVault\n }\n\n}",
"spec": {
"order": [
"packTypeId",
"numberOfPacks",
"totalAmount"
],
"parameters": {
"numberOfPacks": "UInt64",
"packTypeId": "UInt64",
"totalAmount": "UFix64"
}
}
},
"initUser": {
"code": "import Bl0x from 0xe8124d8428980aa6\nimport Bl0xPack from 0xe8124d8428980aa6\nimport NonFungibleToken from 0x631e88ae7f1d7c20\nimport MetadataViews from 0x631e88ae7f1d7c20\nimport Profile from 0xa16ab1d0abde3625\nimport FungibleToken from 0x9a0766d93b6608b7\nimport FUSD from 0xe223d8a629e49c68\nimport FlowToken from 0x7e60df042a9c0868\n\n//Initialize a users storage slots for bl0x\ntransaction {\n prepare(account: AuthAccount) {\n\n let findPackCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n if !findPackCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e( \u003c- Bl0xPack.createEmptyCollection(), to: Bl0xPack.CollectionStoragePath)\n account.link\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0xPack.CollectionPublicPath,\n target: Bl0xPack.CollectionStoragePath\n )\n }\n\n let bl0xCap= account.getCapability\u003c\u0026{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n if !bl0xCap.check() {\n account.save\u003c@NonFungibleToken.Collection\u003e(\u003c- Bl0x.createEmptyCollection(), to: Bl0x.CollectionStoragePath)\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPublicPath,\n target: Bl0x.CollectionStoragePath\n )\n account.link\u003c\u0026Bl0x.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}\u003e(\n Bl0x.CollectionPrivatePath,\n target: Bl0x.CollectionStoragePath\n )\n }\n\n let profileCap = account.getCapability\u003c\u0026{Profile.Public}\u003e(Profile.publicPath)\n if profileCap.check() {\n return \n }\n let profile \u003c-Profile.createUser(name:account.address.toString(), createdAt: \"Bl0x\")\n\n //Add exising FUSD or create a new one and add it\n let fusdReceiver = account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver)\n if !fusdReceiver.check() {\n let fusd \u003c- FUSD.createEmptyVault()\n account.save(\u003c- fusd, to: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Receiver}\u003e( /public/fusdReceiver, target: /storage/fusdVault)\n account.link\u003c\u0026FUSD.Vault{FungibleToken.Balance}\u003e( /public/fusdBalance, target: /storage/fusdVault)\n }\n\n let fusdWallet=Profile.Wallet(\n name:\"FUSD\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/fusdReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/fusdBalance),\n accept: Type\u003c@FUSD.Vault\u003e(),\n names: [\"fusd\", \"stablecoin\"]\n )\n\n profile.addWallet(fusdWallet)\n\n let flowWallet=Profile.Wallet(\n name:\"Flow\", \n receiver:account.getCapability\u003c\u0026{FungibleToken.Receiver}\u003e(/public/flowTokenReceiver),\n balance:account.getCapability\u003c\u0026{FungibleToken.Balance}\u003e(/public/flowTokenBalance),\n accept: Type\u003c@FlowToken.Vault\u003e(),\n names: [\"flow\"]\n )\n profile.addWallet(flowWallet)\n account.save(\u003c-profile, to: Profile.storagePath)\n account.link\u003c\u0026Profile.User{Profile.Public}\u003e(Profile.publicPath, target: Profile.storagePath)\n account.link\u003c\u0026{FungibleToken.Receiver}\u003e(Profile.publicReceiverPath, target: Profile.storagePath)\n\n\n }\n}",
"spec": null
},
"openPack": {
"code": "import Bl0x from 0xe8124d8428980aa6\nimport Bl0xPack from 0xe8124d8428980aa6\nimport FungibleToken from 0x9a0766d93b6608b7\nimport NonFungibleToken from 0x631e88ae7f1d7c20\nimport MetadataViews from 0x631e88ae7f1d7c20\n\n/// A transaction to open a pack with a given id\n/// @param packId: The id of the pack to open\ntransaction(packId:UInt64) {\n\n let packs: \u0026Bl0xPack.Collection\n let receiver: Capability\u003c\u0026{NonFungibleToken.Receiver}\u003e\n\n prepare(account: AuthAccount) {\n self.packs=account.borrow\u003c\u0026Bl0xPack.Collection\u003e(from: Bl0xPack.CollectionStoragePath)!\n self.receiver = account.getCapability\u003c\u0026{NonFungibleToken.Receiver}\u003e(Bl0x.CollectionPublicPath)\n }\n\n pre {\n self.receiver.check() : \"The receiver collection for the packs is not present\"\n }\n execute {\n self.packs.open(packId: packId, receiverCap:self.receiver)\n }\n\n post {\n !self.packs.getIDs().contains(packId) : \"The pack is still present in the users collection\"\n }\n}",
"spec": {
"order": [
"packId"
],
"parameters": {
"packId": "UInt64"
}
}
},
"sendBl0x": {
"code": "import Bl0x from 0xe8124d8428980aa6\nimport NonFungibleToken from 0x631e88ae7f1d7c20\n\ntransaction(receiverAddr: Address, id: UInt64) {\n let bl0xCollectionRef: \u0026Bl0x.Collection\n let receiverCollectionCap: Capability\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic}\u003e\n\n prepare(account: AuthAccount) {\n self.bl0xCollectionRef = account.borrow\u003c\u0026Bl0x.Collection\u003e(from: Bl0x.CollectionStoragePath) ?? panic(\"Could not borrow Bl0x Collection\")\n self.receiverCollectionCap = getAccount(receiverAddr).getCapability\u003c\u0026Bl0x.Collection{NonFungibleToken.CollectionPublic}\u003e(Bl0x.CollectionPublicPath)\n }\n\n pre{\n self.receiverCollectionCap.check() : \"The receiver do not have Bl0x Collection set up.\"\n }\n\n execute {\n let receiverCollectionRef = self.receiverCollectionCap.borrow()!\n let nft \u003c- self.bl0xCollectionRef.withdraw(withdrawID: id)\n receiverCollectionRef.deposit(token: \u003c- nft)\n }\n}",
"spec": {
"order": [
"receiverAddr",
"id"
],
"parameters": {
"id": "UInt64",
"receiverAddr": "Address"
}
}
},
"sendPack": {
"code": "import Bl0xPack from 0xe8124d8428980aa6\nimport NonFungibleToken from 0x631e88ae7f1d7c20\n\ntransaction(receiverAddr: Address, id:UInt64) {\n let bl0xPackCollectionRef: \u0026Bl0xPack.Collection\n let receiverCollectionCap: Capability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic}\u003e\n\n prepare(account: AuthAccount) {\n self.bl0xPackCollectionRef = account.borrow\u003c\u0026Bl0xPack.Collection\u003e(from: Bl0xPack.CollectionStoragePath) ?? panic(\"Could not borrow Bl0x Pack Collection\")\n self.receiverCollectionCap = getAccount(receiverAddr).getCapability\u003c\u0026Bl0xPack.Collection{NonFungibleToken.CollectionPublic}\u003e(Bl0xPack.CollectionPublicPath)\n }\n\n pre{\n self.receiverCollectionCap.check() : \"The receiver do not have Bl0x Pack Collection set up.\"\n }\n\n execute {\n let receiverCollectionRef = self.receiverCollectionCap.borrow()!\n let nft \u003c- self.bl0xPackCollectionRef.withdraw(withdrawID: id)\n receiverCollectionRef.deposit(token: \u003c- nft)\n }\n}",
"spec": {
"order": [
"receiverAddr",
"id"
],
"parameters": {
"id": "UInt64",
"receiverAddr": "Address"
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment