Skip to content

Commit

Permalink
Merge pull request #62 from dapperlabs/loic/upgrade-nft-provider-aggr…
Browse files Browse the repository at this point in the history
…egator-to-c1

Update NFTProviderAggregator to Cadence 1.0
  • Loading branch information
loic1 authored Aug 2, 2024
2 parents 8e3a2bf + 7a0ec1e commit 16cec75
Show file tree
Hide file tree
Showing 62 changed files with 7,408 additions and 19,448 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/nft-provider-aggregator-test.yml
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
3 changes: 3 additions & 0 deletions nft-provider-aggregator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: test
test:
$(MAKE) test -C ./lib/go
9 changes: 5 additions & 4 deletions nft-provider-aggregator/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:

Expand All @@ -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
```
389 changes: 306 additions & 83 deletions nft-provider-aggregator/contracts/ExampleNFT.cdc

Large diffs are not rendered by default.

264 changes: 148 additions & 116 deletions nft-provider-aggregator/contracts/NFTProviderAggregator.cdc

Large diffs are not rendered by default.

150 changes: 0 additions & 150 deletions nft-provider-aggregator/contracts/NonFungibleToken.cdc

This file was deleted.

50 changes: 50 additions & 0 deletions nft-provider-aggregator/contracts/imports/Burner.cdc
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
}
}
}
Loading

0 comments on commit 16cec75

Please sign in to comment.