-
Notifications
You must be signed in to change notification settings - Fork 7
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 #113 from onflow/update-escrow
Add metadata discovery & resolution paths to escrow contracts
- Loading branch information
Showing
10 changed files
with
189 additions
and
38 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
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 "FlowEVMBridgeTokenEscrow" | ||
|
||
/// Returns the balance of a given FungibleToken Vault type locked in escrow or nil if a vault of the given type is not | ||
/// locked in escrow | ||
/// | ||
/// @param vaultTypeIdentifier: The type identifier of the FungibleToken Vault | ||
/// | ||
access(all) fun main(vaultTypeIdentifier: String): UFix64? { | ||
let tokenType = CompositeType(vaultTypeIdentifier) ?? panic("Malformed Vault type identifier=".concat(vaultTypeIdentifier)) | ||
return FlowEVMBridgeTokenEscrow.getLockedTokenBalance(tokenType: tokenType) | ||
} |
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,16 @@ | ||
import "NonFungibleToken" | ||
|
||
import "FlowEVMBridgeNFTEscrow" | ||
import "FlowEVMBridge" | ||
|
||
/// Returns the views supported by an escrowed NFT or nil if the NFT is not locked in escrow | ||
/// | ||
/// @param nftTypeIdentifier: The type identifier of the NFT | ||
/// @param id: The ID of the NFT | ||
/// | ||
/// @return The metadata view types supported by the escrowed NFT or nil if the NFT is not locked in escrow | ||
/// | ||
access(all) fun main(nftTypeIdentifier: String, id: UInt64): [Type]? { | ||
let type = CompositeType(nftTypeIdentifier) ?? panic("Malformed NFT type identifier=".concat(nftTypeIdentifier)) | ||
return FlowEVMBridgeNFTEscrow.getViews(nftType: type, id: id) | ||
} |
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,16 @@ | ||
import "NonFungibleToken" | ||
|
||
import "FlowEVMBridgeTokenEscrow" | ||
import "FlowEVMBridge" | ||
|
||
/// Returns the views supported by an escrowed FungibleToken Vault or nil if there is no Vault of the given type locked | ||
/// in escrow | ||
/// | ||
/// @param vaultTypeIdentifier: The type identifier of the NFT | ||
/// | ||
/// @return The metadata view types supported by the escrowed FT Vault or nil if there is not Vault locked in escrow | ||
/// | ||
access(all) fun main(vaultTypeIdentifier: String, id: UInt64): [Type]? { | ||
let type = CompositeType(vaultTypeIdentifier) ?? panic("Malformed Vault type identifier=".concat(vaultTypeIdentifier)) | ||
return FlowEVMBridgeTokenEscrow.getViews(tokenType: type) | ||
} |
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,34 @@ | ||
import "NonFungibleToken" | ||
import "MetadataViews" | ||
|
||
import "FlowEVMBridgeTokenEscrow" | ||
import "FlowEVMBridgeUtils" | ||
|
||
/// Resolves the view for the requested locked Vault or nil if the Vault is not locked in escrow | ||
/// NOTE: This functionality is not available via the escrow contract as `resolveView` is not a `view` method, but the | ||
/// escrow contract does provide the necessary functionality to resolve the view from the context of a script | ||
/// | ||
/// @param bridgeAddress: The address of the bridge contract (included as the VM bridge address varies across networks) | ||
/// @param vaultTypeIdentifier: The identifier of the Vault type | ||
/// @param viewIdentifier: The identifier of the view to resolve | ||
/// | ||
/// @return The resolved view if the Vault is escrowed & the view is resolved by it or nil if the Vault is not locked | ||
/// | ||
access(all) fun main(bridgeAddress: Address, vaultTypeIdentifier: String, viewIdentifier: String): AnyStruct? { | ||
// Construct runtime types from provided identifiers | ||
let vaultType: Type = CompositeType(vaultTypeIdentifier) ?? panic("Malformed vault type identifier=".concat(vaultTypeIdentifier)) | ||
let view: Type = CompositeType(viewIdentifier) ?? panic("Malformed view type identifier=".concat(viewIdentifier)) | ||
|
||
// Derive the Locker path for the given Vault type | ||
let lockerPath = FlowEVMBridgeUtils.deriveEscrowStoragePath(fromType: vaultType) | ||
?? panic("Problem deriving Locker path for NFT type identifier=".concat(vaultTypeIdentifier)) | ||
|
||
// Borrow the locker from the bridge account's storage & return the requested view if the locker exists | ||
if let locker = getAuthAccount<auth(BorrowValue) &Account>(bridgeAddress).storage.borrow<&FlowEVMBridgeTokenEscrow.Locker>( | ||
from: lockerPath | ||
) { | ||
return locker.resolveView(view) | ||
} | ||
|
||
return 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
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