Skip to content

Commit

Permalink
crescendo handling for raffles contracts and FlowtyWrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Aug 20, 2024
1 parent 40da242 commit 2ba2add
Show file tree
Hide file tree
Showing 30 changed files with 315 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
- name: Install Flow dependencies
run: npm i
- name: Install Flow CLI
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.8.0
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
- name: Run tests
run: sh ./run-tests.sh
188 changes: 97 additions & 91 deletions contracts/FlowtyWrapped.cdc

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions contracts/WrappedEditions.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,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] // type identifier of each collection
access(all) let collections: [String] // type identifier of each collection
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 +35,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) fun resolveView(_ t: Type, _ nft: &FlowtyWrapped.NFT): AnyStruct? {
let wrapped = nft.data["wrapped"]! as! Wrapped2023Data
switch t {
case Type<MetadataViews.Display>():
Expand All @@ -71,7 +71,7 @@ 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: "QmRfVR98oe6qxeWFcnY9tfM2CLUJg3rvxbBPS5LjYwp69Z".concat(params), path: nil), mediaType: "text/html"
)
let imageMedia = MetadataViews.Media(
file: MetadataViews.HTTPFile(url: self.baseImageUrl.concat(nft.serial.toString())), mediaType: "image/jpeg"
Expand All @@ -84,7 +84,7 @@ pub contract WrappedEditions {
return nil
}

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

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

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

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

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

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

Expand All @@ -143,7 +143,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.Add) fun addEntry(_ v: AnyStruct) {
pre {
v.getType() == self.entryType: "incorrect entry type"
}

self.entries.append(v)
}

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

self.entries.appendAll(v)
}

pub fun revealCallback(drawingResult: FlowtyRaffles.DrawingResult) {
access(contract) 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

0 comments on commit 2ba2add

Please sign in to comment.