-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from dapperlabs/loic/upgrade-nft-provider-aggr…
…egator-to-c1 Update NFTProviderAggregator to Cadence 1.0
- Loading branch information
Showing
62 changed files
with
7,408 additions
and
19,448 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
paths: | ||
- "nft-provider-aggregator/**" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v1 | ||
with: | ||
go-version: '1.22' | ||
- run: cd nft-provider-aggregator && make test |
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,3 @@ | ||
.PHONY: test | ||
test: | ||
$(MAKE) test -C ./lib/go |
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 |
---|---|---|
|
@@ -26,6 +26,8 @@ removes all the resource's NFT provider capabilities and render child `Supplier` | |
|
||
## Architecture Considerations | ||
|
||
> July 2024 Update: NFT Provider Aggregator was created prior to Cadence 1.0 and then updated for Cadence 1.0 with the goal of ensuring backwards compatibility. Even though Cadence 1.0 introduced relevant new features that (e.g., the ability to add tags to keep track of capability usage), this current version of NFT Provider Aggregator doesn't have any architecture changes compared to the pre-Cadence 1.0 version. | ||
The use of the `Supplier` resource allows: | ||
- Explicitly keeping track of the NFT provider capabilities that are expected to be valid all in one place, the parent `Aggregator` resource, and emitting dedicated events when a capability is added or removed. | ||
- Reversibly exposing NFT provider capabilities to the parent `Aggregator` resource without the capabilities being retrievable individually by the **manager**. This is made possible by the `Aggregator` resource’s `nftProviderCapabilities` dictionary being defined with `access(self)` access control and devoid of any getter function, though, if the `NFTProviderAggregator` contract is updatable, a contract update may potentially change that. | ||
|
@@ -68,7 +70,7 @@ The transactions included in this repository and listed below are all single-sig | |
|
||
- `claim_aggregated_nft_provider_capability.cdc` | ||
|
||
- `unpublish_capability.cdc` | ||
- `unpublish_inbox_capability.cdc` | ||
|
||
#### Resource Destruction: | ||
|
||
|
@@ -92,7 +94,6 @@ The scripts included in this repository and listed below are scripts that access | |
|
||
``` | ||
git clone [email protected]:dapperlabs/nft-provider-aggregator.git | ||
cd ./nft-provider-aggregator/test | ||
npm install | ||
npm test | ||
cd ./nft-provider-aggregator | ||
make test | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
264 changes: 148 additions & 116 deletions
264
nft-provider-aggregator/contracts/NFTProviderAggregator.cdc
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
/// 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(_ toBurn: @AnyResource?) { | ||
if toBurn == nil { | ||
destroy toBurn | ||
return | ||
} | ||
let r <- toBurn! | ||
|
||
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.