-
Notifications
You must be signed in to change notification settings - Fork 0
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
Felipe tests 2 #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there's some confusion for what the goal is to abstracting away the source of a raffle into its own resource. I'll make a PR that fills in some of these details to help, but the TL;DR to some of this is that a raffle cannot have any knowledge about the kind of raffle it is, and so we cannot include anything that makes assumptions about it
pub fun getAddressSource(): &AddressRaffleSource { | ||
let source = &self.source as auth &{RaffleSource} | ||
return source as! &AddressRaffleSource | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be added here, unfortunately. The Raffle itself should have no knowledge of the "source" it is using
What we likely have to do is permit returning an auth reference source to the owner of the raffle so that they can cast it to the original type at will
pub fun getAddresses(): [Address] { | ||
return self.getAddressSource().getAddresses() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this, unfortunately can't be included
pub fun getRaffleAddresses(id: UInt64): [Address] { | ||
return (&self.raffles[id] as &Raffle?)!.getAddresses() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally with method like this, they should exist in the underlying resource you are calling, and a borrow method should be used to get to it (borrowRafflePublic
in this case)
pub fun draw(id: UInt64) { | ||
let raffle: &Raffles.Raffle? = &self.raffles[id] as &Raffle? | ||
if raffle == nil { | ||
panic("raffle with id ".concat(id.toString()).concat(" does not exist")) | ||
} | ||
|
||
let index = raffle!.draw() | ||
let value = raffle!.getEntryAt(index: index) | ||
|
||
Raffles.emitDrawing(address: self.owner!.address, raffleID: id, sourceType: raffle!.getSourceType() ,index: index, value: value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here on borrowing, the Raffle resource itself can encapsulate this
No description provided.