-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contract updates for cadence 1.0 (#21)
- Loading branch information
1 parent
9db39e2
commit e85dd28
Showing
74 changed files
with
6,496 additions
and
2,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// Burner is a contract that can facilitate the destruction of any resource on flow. | ||
/// | ||
/// Contributors | ||
/// - Austin Kline - https://twitter.com/austin_flowty | ||
/// - Deniz Edincik - https://twitter.com/bluesign | ||
/// - Bastian Müller - https://twitter.com/turbolent | ||
access(all) contract Burner { | ||
/// When Crescendo (Cadence 1.0) is released, custom destructors will be removed from cadece. | ||
/// Burnable is an interface meant to replace this lost feature, allowing anyone to add a callback | ||
/// method to ensure they do not destroy something which is not meant to be, | ||
/// or to add logic based on destruction such as tracking the supply of a FT Collection | ||
/// | ||
/// NOTE: The only way to see benefit from this interface | ||
/// is to always use the burn method in this contract. Anyone who owns a resource can always elect **not** | ||
/// to destroy a resource this way | ||
access(all) resource interface Burnable { | ||
access(contract) fun burnCallback() | ||
} | ||
|
||
/// burn is a global method which will destroy any resource it is given. | ||
/// If the provided resource implements the Burnable interface, | ||
/// it will call the burnCallback method and then destroy afterwards. | ||
access(all) fun burn(_ r: @AnyResource) { | ||
if let s <- r as? @{Burnable} { | ||
s.burnCallback() | ||
destroy s | ||
} else if let arr <- r as? @[AnyResource] { | ||
while arr.length > 0 { | ||
let item <- arr.removeFirst() | ||
self.burn(<-item) | ||
} | ||
destroy arr | ||
} else if let dict <- r as? @{HashableStruct: AnyResource} { | ||
let keys = dict.keys | ||
while keys.length > 0 { | ||
let item <- dict.remove(key: keys.removeFirst())! | ||
self.burn(<-item) | ||
} | ||
destroy dict | ||
} else { | ||
destroy r | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.