Skip to content

Commit

Permalink
- Update all HybridCustody contract dependencies
Browse files Browse the repository at this point in the history
- Switch dependency management to npm package for now since submodules aren't yet fully working
  • Loading branch information
austinkline committed Mar 23, 2024
1 parent 84bb6f3 commit 82d8da8
Show file tree
Hide file tree
Showing 21 changed files with 622 additions and 415 deletions.
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
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
34 changes: 17 additions & 17 deletions contracts/CapabilityFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@
/// 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?
}

/// 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 +60,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 +72,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 +92,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

0 comments on commit 82d8da8

Please sign in to comment.