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

[Cadence 1.0] - Update contracts, transactions and tests #55

Closed
wants to merge 3 commits into from
Closed
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
262 changes: 168 additions & 94 deletions contracts/FlowtyWrapped.cdc

Large diffs are not rendered by default.

55 changes: 27 additions & 28 deletions contracts/WrappedEditions.cdc
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import "MetadataViews"
import "FlowtyWrapped"
import "StringUtils"

pub contract WrappedEditions {
pub struct Wrapped2023Data {
pub let username: String?
pub let tickets: Int
access(all) contract WrappedEditions {
access(all) struct Wrapped2023Data {
access(all) let username: String?
access(all) let tickets: Int

pub let totalNftsOwned: Int
pub let floatCount: Int
pub let favoriteCollections: [String] // type identifier of each collection
pub let collections: [String] // type identifier of each collection
access(all) let totalNftsOwned: Int
access(all) let floatCount: Int
access(all) let favoriteCollections: [String]
access(all) let collections: [String]

pub fun toTraits(): MetadataViews.Traits {
access(all) fun toTraits(): MetadataViews.Traits {
let traits: [MetadataViews.Trait] = [
WrappedEditions.buildTrait("username", self.username),
WrappedEditions.buildTrait("tickets", self.tickets),
Expand All @@ -35,18 +34,18 @@ pub contract WrappedEditions {
}
}

pub struct Edition2023: FlowtyWrapped.WrappedEdition {
pub let name: String
pub var supply: UInt64
pub var baseImageUrl: String
pub var baseHtmlUrl: String
access(all) struct Edition2023: FlowtyWrapped.WrappedEdition {
access(all) let name: String
access(all) var supply: UInt64
access(all) var baseImageUrl: String
access(all) var baseHtmlUrl: String

pub let raffleID: UInt64
pub var status: String
access(all) let raffleID: UInt64
access(all) var status: String

pub let mintedAddresses: {Address: Bool}
access(all) let mintedAddresses: {Address: Bool}

pub fun resolveView(_ t: Type, _ nft: &FlowtyWrapped.NFT): AnyStruct? {
access(all) view fun resolveView(_ t: Type, _ nft: &FlowtyWrapped.NFT): AnyStruct? {
let wrapped = nft.data["wrapped"]! as! Wrapped2023Data
switch t {
case Type<MetadataViews.Display>():
Expand All @@ -71,20 +70,20 @@ pub contract WrappedEditions {

let params = "?username=".concat(username).concat("&raffleTickets=").concat(wrapped.tickets.toString())
let htmlMedia = MetadataViews.Media(
file: MetadataViews.IPFSFile("QmRfVR98oe6qxeWFcnY9tfM2CLUJg3rvxbBPS5LjYwp69Z".concat(params), nil), mediaType: "text/html"
file: MetadataViews.IPFSFile(cid: "QmfPkn13gbBNVK6bKtdqyUEa92bmqDy8aVQqGj3pByyyoP".concat(params), path: nil), mediaType: "text/html"
)
let imageMedia = MetadataViews.Media(
file: MetadataViews.HTTPFile(url: self.baseImageUrl.concat(nft.serial.toString())), mediaType: "image/jpeg"
)
return MetadataViews.Medias([htmlMedia, imageMedia])
case Type<MetadataViews.Traits>():
return wrapped.toTraits()
// case Type<MetadataViews.Traits>():
// return wrapped.toTraits()
}

return nil
}

pub fun getEditionSupply(): UInt64 {
access(all) view fun getEditionSupply(): UInt64 {
return self.supply
}

Expand Down Expand Up @@ -115,19 +114,19 @@ pub contract WrappedEditions {
return <- nft
}

pub fun getName(): String {
access(all) view fun getName(): String {
return self.name
}

pub fun setStatus(_ s: String) {
access(all) fun setStatus(_ s: String) {
self.status = s
}

pub fun setBaseImageUrl(_ s: String) {
access(all) fun setBaseImageUrl(_ s: String) {
self.baseImageUrl = s
}

pub fun setBaseHtmlUrl(_ s: String) {
access(all) fun setBaseHtmlUrl(_ s: String) {
self.baseHtmlUrl = s
}

Expand All @@ -143,7 +142,7 @@ pub contract WrappedEditions {
}
}

pub fun buildTrait(_ name: String, _ value: AnyStruct): MetadataViews.Trait {
access(all) fun buildTrait(_ name: String, _ value: AnyStruct): MetadataViews.Trait {
return MetadataViews.Trait(name: name, value: value, displayType: nil, rarity: nil)
}
}
26 changes: 13 additions & 13 deletions contracts/raffle/FlowtyRaffleSource.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ In addition to entryType, a field called `removeAfterReveal` is also provided, w
from the entries array any time a reveal is performed. This is useful for cases where you don't want the same entry to be able to be drawn
multiple times.
*/
pub contract FlowtyRaffleSource {
pub resource AnyStructRaffleSource: FlowtyRaffles.RaffleSourcePublic, FlowtyRaffles.RaffleSourcePrivate {
pub let entries: [AnyStruct]
pub let entryType: Type
pub let removeAfterReveal: Bool
access(all) contract FlowtyRaffleSource {
access(all) resource AnyStructRaffleSource: FlowtyRaffles.RaffleSourcePublic, FlowtyRaffles.RaffleSourcePrivate {
access(all) let entries: [AnyStruct]
access(all) let entryType: Type
access(all) let removeAfterReveal: Bool

pub fun getEntryType(): Type {
access(all) fun getEntryType(): Type {
return self.entryType
}

pub fun getEntryAt(index: Int): AnyStruct {
access(all) fun getEntryAt(index: Int): AnyStruct {
return self.entries[index]
}

pub fun getEntries(): [AnyStruct] {
access(all) fun getEntries(): [AnyStruct] {
return self.entries
}

pub fun getEntryCount(): Int {
access(all) fun getEntryCount(): Int {
return self.entries.length
}

pub fun addEntry(_ v: AnyStruct) {
access(FlowtyRaffles.AddEntry) fun addEntry(_ v: AnyStruct) {
pre {
v.getType() == self.entryType: "incorrect entry type"
}

self.entries.append(v)
}

pub fun addEntries(_ v: [AnyStruct]) {
access(FlowtyRaffles.AddEntry) fun addEntries(_ v: [AnyStruct]) {
pre {
VariableSizedArrayType(self.entryType) == v.getType(): "incorrect array type"
}

self.entries.appendAll(v)
}

pub fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
access(FlowtyRaffles.RevealRaffle) fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
if !self.removeAfterReveal {
return
}
Expand All @@ -66,7 +66,7 @@ pub contract FlowtyRaffleSource {
}
}

pub fun createRaffleSource(entryType: Type, removeAfterReveal: Bool): @AnyStructRaffleSource {
access(all) fun createRaffleSource(entryType: Type, removeAfterReveal: Bool): @AnyStructRaffleSource {
pre {
entryType.isSubtype(of: Type<AnyStruct>()): "entry type must be a subtype of AnyStruct"
}
Expand Down
Loading
Loading