From b66d59252403191811bd936d7daba8bfb287ee51 Mon Sep 17 00:00:00 2001 From: Felipe Ribeiro Date: Tue, 19 Dec 2023 16:57:00 -0300 Subject: [PATCH] address code review request changes --- contracts/FlowtyWrapped.cdc | 14 +++++++++----- contracts/WrappedEditions.cdc | 24 +++++------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/contracts/FlowtyWrapped.cdc b/contracts/FlowtyWrapped.cdc index 916e2c9..cd36b94 100644 --- a/contracts/FlowtyWrapped.cdc +++ b/contracts/FlowtyWrapped.cdc @@ -32,7 +32,7 @@ pub contract FlowtyWrapped: NonFungibleToken, ViewResolver { pub struct interface WrappedEdition { pub fun getName(): String pub fun resolveView(_ t: Type, _ nft: &NFT): AnyStruct? - access(account) fun mint(data: {String: AnyStruct}): @NFT + access(account) fun mint(address: Address, data: {String: AnyStruct}): @NFT pub fun setStatus(_ s: String) } @@ -45,17 +45,20 @@ pub contract FlowtyWrapped: NonFungibleToken, ViewResolver { pub let id: UInt64 pub let serial: UInt64 pub let editionName: String + pub let address: Address pub let data: {String: AnyStruct} init( id: UInt64, serial: UInt64, editionName: String, + address: Address, data: {String: AnyStruct} ) { self.id = id self.serial = serial self.editionName = editionName + self.address = address self.data = data } @@ -162,7 +165,7 @@ pub contract FlowtyWrapped: NonFungibleToken, ViewResolver { /// pub fun deposit(token: @NonFungibleToken.NFT) { let token <- token as! @FlowtyWrapped.NFT - let nftOwnerAddress = token.data["address"] as! Address + let nftOwnerAddress = token.address assert(nftOwnerAddress == self.owner?.address, message: "The NFT must be owned by the collection owner") @@ -246,12 +249,12 @@ pub contract FlowtyWrapped: NonFungibleToken, ViewResolver { /// /// @param recipient: A capability to the collection where the new NFT will be deposited /// - pub fun mintNFT(editionName: String, data: {String: AnyStruct}): @FlowtyWrapped.NFT { + pub fun mintNFT(editionName: String, address: Address, data: {String: AnyStruct}): @FlowtyWrapped.NFT { // we want IDs to start at 1, so we'll increment first FlowtyWrapped.totalSupply = FlowtyWrapped.totalSupply + 1 let edition = FlowtyWrapped.getEdition(editionName) - let nft <- edition.mint(data: data) + let nft <- edition.mint(address: address, data: data) return <- nft } @@ -339,8 +342,9 @@ pub contract FlowtyWrapped: NonFungibleToken, ViewResolver { id: UInt64, serial: UInt64, editionName: String, + address: Address, data: {String: AnyStruct}): @NFT { - return <- create NFT(id: id, serial: serial, editionName: editionName, data: data) + return <- create NFT(id: id, serial: serial, editionName: editionName, address: address, data: data) } pub fun getEdition(_ name: String): {WrappedEdition} { diff --git a/contracts/WrappedEditions.cdc b/contracts/WrappedEditions.cdc index d74814a..cc08f4f 100644 --- a/contracts/WrappedEditions.cdc +++ b/contracts/WrappedEditions.cdc @@ -4,8 +4,7 @@ import "StringUtils" pub contract WrappedEditions { pub struct Wrapped2023Data { - pub let address: Address - pub let username: String + pub let username: String? pub let tickets: Int pub let totalNftsOwned: Int @@ -15,7 +14,6 @@ pub contract WrappedEditions { pub fun toTraits(): MetadataViews.Traits { let traits: [MetadataViews.Trait] = [ - WrappedEditions.buildTrait("address", self.address), WrappedEditions.buildTrait("username", self.username), WrappedEditions.buildTrait("tickets", self.tickets), WrappedEditions.buildTrait("totalNftsOwned", self.totalNftsOwned), @@ -27,8 +25,7 @@ pub contract WrappedEditions { return MetadataViews.Traits(traits) } - init(_ address: Address, _ username: String, _ tickets: Int, totalNftsOwned: Int, floatCount: Int, favoriteCollections: [String], collections: [String]) { - self.address = address + init(_ username: String?, _ tickets: Int, totalNftsOwned: Int, floatCount: Int, favoriteCollections: [String], collections: [String]) { self.username = username self.tickets = tickets self.totalNftsOwned = totalNftsOwned @@ -79,22 +76,11 @@ pub contract WrappedEditions { return nil } - pub fun buildIpfsParams(_ data: Wrapped2023Data): String { - var s = "?username=".concat(data.username) - .concat("&tickets=").concat(data.tickets.toString()) - .concat("&totalNftsOwned=").concat(data.totalNftsOwned.toString()) - .concat("&floatCount=").concat(data.floatCount.toString()) - .concat("&favoriteCollections=").concat(StringUtils.join(data.favoriteCollections, ",")) - .concat("&collections=").concat(StringUtils.join(data.collections, ",")) - - return s - } - - access(account) fun mint(data: {String: AnyStruct}): @FlowtyWrapped.NFT { + access(account) fun mint(address: Address, data: {String: AnyStruct}): @FlowtyWrapped.NFT { self.supply = self.supply + 1 let casted = data["wrapped"]! as! Wrapped2023Data - let nft <- FlowtyWrapped.mint(id: FlowtyWrapped.totalSupply, serial: self.supply, editionName: self.name, data: data) + let nft <- FlowtyWrapped.mint(id: FlowtyWrapped.totalSupply, serial: self.supply, editionName: self.name, address: address, data: data) // allocate raffle tickets let manager = FlowtyWrapped.getRaffleManager() @@ -104,7 +90,7 @@ pub contract WrappedEditions { let entries: [Address] = [] var count = 0 while count < casted.tickets { - entries.append(casted.address) + entries.append(address) } raffle.addEntries(entries)