Skip to content
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

Crescendo #163

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ jobs:
with:
go-version: 1.18
- name: Install Flow CLI
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.5.0
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
- name: Run tests
run: sh ./test.sh
- name: Normalize coverage report filepaths
run : sh ./normalize_coverage_report.sh
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coverage.lcov
.idea
*.pkey
*.private
*.pem
*.pem
node_modules/
10 changes: 5 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "modules/flow-nft"]
path = modules/flow-nft
url = https://github.com/Flowtyio/flow-nft.git
[submodule "flow-ft"]
path = flow-ft
url = https://github.com/Flowtyio/flow-ft.git
url = https://github.com/onflow/flow-nft.git
[submodule "modules/flow-utils"]
path = modules/flow-utils
url = https://github.com/Flowtyio/flow-utils.git
url = https://github.com/green-goo-dao/flow-utils.git
[submodule "modules/flow-ft"]
path = modules/flow-ft
url = https://github.com/onflow/flow-ft.git
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ignore:
- "contracts/standard/ExampleNFT.cdc"
- "contracts/standard/ExampleNFT2.cdc"
- "contracts/standard/ExampleToken.cdc"
- "contracts/factories/FTBalanceFactory.cdc"
- "contracts/factories/FTProviderFactory.cdc"
- "contracts/factories/FTReceiverFactory.cdc"
- "contracts/factories/NFTCollectionPublicFactory.cdc"
- "contracts/factories/NFTProviderFactory.cdc"
50 changes: 25 additions & 25 deletions contracts/CapabilityDelegator.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@
/// private `Delegator` can only be borrowed from the child account when you have access to the full `ChildAccount`
/// resource.
///
pub contract CapabilityDelegator {
access(all) contract CapabilityDelegator {

/* --- Canonical Paths --- */
//
pub let StoragePath: StoragePath
pub let PrivatePath: PrivatePath
pub let PublicPath: PublicPath
access(all) let StoragePath: StoragePath
access(all) let PrivatePath: PrivatePath
access(all) let PublicPath: PublicPath

/* --- Events --- */
//
pub event DelegatorCreated(id: UInt64)
pub event DelegatorUpdated(id: UInt64, capabilityType: Type, isPublic: Bool, active: Bool)
access(all) event DelegatorCreated(id: UInt64)
access(all) event DelegatorUpdated(id: UInt64, capabilityType: Type, isPublic: Bool, active: Bool)

/// Private interface for Capability retrieval
///
pub resource interface GetterPrivate {
pub fun getPrivateCapability(_ type: Type): Capability? {
access(all) resource interface GetterPrivate {
access(Capabilities) view fun getPrivateCapability(_ type: Type): Capability? {
post {
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
}
}
pub fun findFirstPrivateType(_ type: Type): Type?
pub fun getAllPrivate(): [Capability]
access(all) view fun findFirstPrivateType(_ type: Type): Type?
access(Capabilities) fun getAllPrivate(): [Capability]
}

/// Exposes public Capability retrieval
///
pub resource interface GetterPublic {
pub fun getPublicCapability(_ type: Type): Capability? {
access(all) resource interface GetterPublic {
access(all) view fun getPublicCapability(_ type: Type): Capability? {
post {
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type "
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
}
}

pub fun findFirstPublicType(_ type: Type): Type?
pub fun getAllPublic(): [Capability]
access(all) view fun findFirstPublicType(_ type: Type): Type?
access(all) view fun getAllPublic(): [Capability]
}

/// This Delegator is used to store Capabilities, partitioned by public and private access with corresponding
/// GetterPublic and GetterPrivate conformances.AccountCapabilityController
///
pub resource Delegator: GetterPublic, GetterPrivate {
access(all) resource Delegator: GetterPublic, GetterPrivate {
access(self) let privateCapabilities: {Type: Capability}
access(self) let publicCapabilities: {Type: Capability}

// ------ Begin Getter methods
//
/// Returns the public Capability of the given Type if it exists
///
pub fun getPublicCapability(_ type: Type): Capability? {
access(all) view fun getPublicCapability(_ type: Type): Capability? {
return self.publicCapabilities[type]
}

Expand All @@ -66,23 +66,23 @@ pub contract CapabilityDelegator {
/// @param type: Type of the Capability to retrieve
/// @return Capability of the given Type if it exists, nil otherwise
///
pub fun getPrivateCapability(_ type: Type): Capability? {
access(Capabilities) view fun getPrivateCapability(_ type: Type): Capability? {
return self.privateCapabilities[type]
}

/// Returns all public Capabilities
///
/// @return List of all public Capabilities
///
pub fun getAllPublic(): [Capability] {
access(all) view fun getAllPublic(): [Capability] {
return self.publicCapabilities.values
}

/// Returns all private Capabilities
///
/// @return List of all private Capabilities
///
pub fun getAllPrivate(): [Capability] {
access(Capabilities) fun getAllPrivate(): [Capability] {
return self.privateCapabilities.values
}

Expand All @@ -91,7 +91,7 @@ pub contract CapabilityDelegator {
/// @param type: Type to check for subtypes
/// @return First public Type that is a subtype of the given Type, nil otherwise
///
pub fun findFirstPublicType(_ type: Type): Type? {
access(all) view fun findFirstPublicType(_ type: Type): Type? {
for t in self.publicCapabilities.keys {
if t.isSubtype(of: type) {
return t
Expand All @@ -106,7 +106,7 @@ pub contract CapabilityDelegator {
/// @param type: Type to check for subtypes
/// @return First private Type that is a subtype of the given Type, nil otherwise
///
pub fun findFirstPrivateType(_ type: Type): Type? {
access(all) view fun findFirstPrivateType(_ type: Type): Type? {
for t in self.privateCapabilities.keys {
if t.isSubtype(of: type) {
return t
Expand All @@ -122,7 +122,7 @@ pub contract CapabilityDelegator {
/// @param cap: Capability to add
/// @param isPublic: Whether the Capability should be public or private
///
pub fun addCapability(cap: Capability, isPublic: Bool) {
access(Mutate) fun addCapability(cap: Capability, isPublic: Bool) {
pre {
cap.check<&AnyResource>(): "Invalid Capability provided"
}
Expand All @@ -138,7 +138,7 @@ pub contract CapabilityDelegator {
///
/// @param cap: Capability to remove
///
pub fun removeCapability(cap: Capability) {
access(Mutate) fun removeCapability(cap: Capability) {
if let removedPublic = self.publicCapabilities.remove(key: cap.getType()) {
emit DelegatorUpdated(id: self.uuid, capabilityType: cap.getType(), isPublic: true, active: false)
}
Expand All @@ -158,7 +158,7 @@ pub contract CapabilityDelegator {
///
/// @return Newly created Delegator
///
pub fun createDelegator(): @Delegator {
access(all) fun createDelegator(): @Delegator {
let delegator <- create Delegator()
emit DelegatorCreated(id: delegator.uuid)
return <- delegator
Expand Down
35 changes: 18 additions & 17 deletions contracts/CapabilityFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,46 @@
/// Capabilities is critical to the use case of Hybrid Custody. It's advised to use Factories sparingly and only for
/// cases where Capabilities must be castable by the caller.
///
pub contract CapabilityFactory {
access(all) contract CapabilityFactory {

pub let StoragePath: StoragePath
pub let PrivatePath: PrivatePath
pub let PublicPath: PublicPath
access(all) let StoragePath: StoragePath
access(all) let PrivatePath: PrivatePath
access(all) let PublicPath: PublicPath

/// Factory structures a common interface for Capability retrieval from a given account at a specified path
///
pub struct interface Factory {
pub fun getCapability(acct: &AuthAccount, path: CapabilityPath): Capability
access(all) struct interface Factory {
access(Capabilities) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability?
access(all) view fun getPublicCapability(acct: auth(Capabilities) &Account, path: PublicPath): Capability?
}

/// Getter defines an interface for retrieval of a Factory if contained within the implementing resource
///
pub resource interface Getter {
pub fun getSupportedTypes(): [Type]
pub fun getFactory(_ t: Type): {CapabilityFactory.Factory}?
access(all) resource interface Getter {
access(all) view fun getSupportedTypes(): [Type]
access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}?
}

/// Manager is a resource that contains Factories and implements the Getter interface for retrieval of contained
/// Factories
///
pub resource Manager: Getter {
access(all) resource Manager: Getter {
/// Mapping of Factories indexed on Type of Capability they retrieve
pub let factories: {Type: {CapabilityFactory.Factory}}
access(all) let factories: {Type: {CapabilityFactory.Factory}}

/// Retrieves a list of Types supported by contained Factories
///
/// @return List of Types supported by the Manager
///
pub fun getSupportedTypes(): [Type] {
access(all) view fun getSupportedTypes(): [Type] {
return self.factories.keys
}

/// Retrieves a Factory from the Manager, returning it or nil if it doesn't exist
///
/// @param t: Type the Factory is indexed on
///
pub fun getFactory(_ t: Type): {CapabilityFactory.Factory}? {
access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}? {
return self.factories[t]
}

Expand All @@ -60,7 +61,7 @@ pub contract CapabilityFactory {
/// @param t: Type of Capability the Factory retrieves
/// @param f: Factory to add
///
pub fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
access(Mutate) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
pre {
!self.factories.containsKey(t): "Factory of given type already exists"
}
Expand All @@ -72,15 +73,15 @@ pub contract CapabilityFactory {
/// @param t: Type of Capability the Factory retrieves
/// @param f: Factory to replace existing Factory
///
pub fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
access(Mutate) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
self.factories[t] = f
}

/// Removes a Factory from the Manager, returning it or nil if it didn't exist
///
/// @param t: Type the Factory is indexed on
///
pub fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
access(Mutate) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
return self.factories.remove(key: t)
}

Expand All @@ -92,7 +93,7 @@ pub contract CapabilityFactory {
/// Creates a Manager resource
///
/// @return Manager resource
pub fun createFactoryManager(): @Manager {
access(all) fun createFactoryManager(): @Manager {
return <- create Manager()
}

Expand Down
Loading
Loading