Skip to content

Commit

Permalink
address code review request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Ribeiro authored and Felipe Ribeiro committed Dec 19, 2023
1 parent de06f3a commit b66d592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
14 changes: 9 additions & 5 deletions contracts/FlowtyWrapped.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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} {
Expand Down
24 changes: 5 additions & 19 deletions contracts/WrappedEditions.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down

0 comments on commit b66d592

Please sign in to comment.