-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing tests, make a new _borrowAccount method for internal use …
…and give borrowAccount the Owner entitlement
- Loading branch information
1 parent
b075ab0
commit 96fbbbf
Showing
11 changed files
with
271 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import "HybridCustody" | ||
|
||
access(all) fun main(owner: Address, child: Address): Address { | ||
let m = getAuthAccount<auth(Storage) &Account>(owner).storage.borrow<auth(HybridCustody.Manage) &HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) | ||
?? panic("manager could not be borrowed") | ||
let ownedAcct = m.borrowOwnedAccount(addr: child) | ||
?? panic("could not borrow owned account") | ||
|
||
let acct = ownedAcct.borrowAccount() | ||
return acct.address | ||
} |
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,13 @@ | ||
import "HybridCustody" | ||
|
||
access(all) fun main(parent: Address, child: Address): Address { | ||
let cap = getAccount(parent).capabilities.get<&{HybridCustody.ManagerPublic}>(HybridCustody.ManagerPublicPath) | ||
?? panic("manager not found") | ||
let manager = cap.borrow() | ||
?? panic("unable to borrow manager") | ||
|
||
let acct = manager.borrowAccountPublic(addr: child) | ||
?? panic("child account not found") | ||
|
||
return acct.getAddress() | ||
} |
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,25 @@ | ||
import "NonFungibleToken" | ||
import "FungibleToken" | ||
|
||
import "CapabilityFactory" | ||
|
||
transaction { | ||
prepare(acct: auth(Storage, Capabilities) &Account) { | ||
if acct.storage.borrow<&AnyResource>(from: CapabilityFactory.StoragePath) == nil { | ||
let f <- CapabilityFactory.createFactoryManager() | ||
acct.storage.save(<-f, to: CapabilityFactory.StoragePath) | ||
} | ||
|
||
if acct.capabilities.get<&{CapabilityFactory.Getter}>(CapabilityFactory.PublicPath)?.check() != true { | ||
acct.capabilities.unpublish(CapabilityFactory.PublicPath) | ||
|
||
let cap = acct.capabilities.storage.issue<&{CapabilityFactory.Getter}>(CapabilityFactory.StoragePath) | ||
acct.capabilities.publish(cap, at: CapabilityFactory.PublicPath) | ||
} | ||
|
||
assert( | ||
acct.capabilities.get<&{CapabilityFactory.Getter}>(CapabilityFactory.PublicPath)!.check(), | ||
message: "CapabilityFactory is not setup properly" | ||
) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
transactions/hybrid-custody/metadata/set_child_account_display_to_nil.cdc
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,10 @@ | ||
import "HybridCustody" | ||
|
||
transaction(childAddress: Address) { | ||
prepare(acct: auth(Storage) &Account) { | ||
let m = acct.storage.borrow<auth(HybridCustody.Manage) &HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) | ||
?? panic("manager not found") | ||
|
||
m.setChildAccountDisplay(address: childAddress, nil) | ||
} | ||
} |
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,10 @@ | ||
import "HybridCustody" | ||
|
||
transaction(addr: Address) { | ||
prepare(acct: auth(Storage) &Account) { | ||
let m = acct.storage.borrow<auth(HybridCustody.Manage) &HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) | ||
?? panic("manager not found") | ||
|
||
m.removeOwned(addr: addr) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
transactions/hybrid-custody/set_capability_factory_for_parent.cdc
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,13 @@ | ||
import "HybridCustody" | ||
import "CapabilityFactory" | ||
|
||
transaction(parent: Address, factoryAddress: Address) { | ||
prepare(acct: auth(Storage) &Account) { | ||
let cap = getAccount(factoryAddress).capabilities.get<&{CapabilityFactory.Getter}>(CapabilityFactory.PublicPath) | ||
?? panic("capability factory was nil") | ||
|
||
let ownedAccount = acct.storage.borrow<auth(HybridCustody.Owner) &{HybridCustody.OwnedAccountPrivate}>(from: HybridCustody.OwnedAccountStoragePath) | ||
?? panic("owned account not found") | ||
ownedAccount.setCapabilityFactoryForParent(parent: parent, cap: cap) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
transactions/hybrid-custody/set_capability_filter_for_parent.cdc
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,13 @@ | ||
import "HybridCustody" | ||
import "CapabilityFilter" | ||
|
||
transaction(parent: Address, factoryAddress: Address) { | ||
prepare(acct: auth(Storage) &Account) { | ||
let cap = getAccount(factoryAddress).capabilities.get<&{CapabilityFilter.Filter}>(CapabilityFilter.PublicPath) | ||
?? panic("capability filter was nil") | ||
|
||
let ownedAccount = acct.storage.borrow<auth(HybridCustody.Owner) &{HybridCustody.OwnedAccountPrivate}>(from: HybridCustody.OwnedAccountStoragePath) | ||
?? panic("owned account not found") | ||
ownedAccount.setCapabilityFilterForParent(parent: parent, cap: cap) | ||
} | ||
} |
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,10 @@ | ||
import "HybridCustody" | ||
|
||
transaction(parent: Address) { | ||
prepare(acct: auth(Storage, Capabilities) &Account) { | ||
let storagePath = StoragePath(identifier: HybridCustody.getChildAccountIdentifier(parent))! | ||
for c in acct.capabilities.storage.getControllers(forPath: storagePath) { | ||
c.delete() | ||
} | ||
} | ||
} |