-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create COA on request accounts (#2120)
* Create COA on request accounts * Add tests * Fix test * Remove * Update test * Refactor * Add events * Fix tests * Run prettier * Fix * Move tx * Move cadence --------- Co-authored-by: Chase Fleming <[email protected]>
- Loading branch information
1 parent
d11dd4e
commit e37469b
Showing
8 changed files
with
215 additions
and
75 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,62 @@ | ||
import {getContractAddress} from "./util/eth" | ||
import {ContractType} from "./constants" | ||
|
||
export const getCOAScript = (chainId: number) => ` | ||
import EVM from ${getContractAddress(ContractType.EVM, chainId)} | ||
access(all) | ||
fun main(address: Address): String? { | ||
if let coa = getAuthAccount(address) | ||
.storage | ||
.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm) { | ||
return coa.address().toString() | ||
} | ||
return nil | ||
} | ||
` | ||
|
||
export const createCOATx = (chainId: number) => ` | ||
import EVM from ${getContractAddress(ContractType.EVM, chainId)} | ||
transaction() { | ||
prepare(signer: auth(SaveValue, IssueStorageCapabilityController, PublishCapability) &Account) { | ||
let storagePath = /storage/evm | ||
let publicPath = /public/evm | ||
let coa: @EVM.CadenceOwnedAccount <- EVM.createCadenceOwnedAccount() | ||
signer.storage.save(<-coa, to: storagePath) | ||
let cap = signer.capabilities.storage.issue<&EVM.CadenceOwnedAccount>(storagePath) | ||
signer.capabilities.publish(cap, at: publicPath) | ||
} | ||
} | ||
` | ||
|
||
export const sendTransactionTx = (chainId: number) => ` | ||
import EVM from ${getContractAddress(ContractType.EVM, chainId)} | ||
/// Executes the calldata from the signer's COA | ||
transaction(evmContractAddressHex: String, calldata: String, gasLimit: UInt64, value: UInt256) { | ||
let evmAddress: EVM.EVMAddress | ||
let coa: auth(EVM.Call) &EVM.CadenceOwnedAccount | ||
prepare(signer: auth(BorrowValue) &Account) { | ||
self.evmAddress = EVM.addressFromString(evmContractAddressHex) | ||
self.coa = signer.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm) | ||
?? panic("Could not borrow COA from provided gateway address") | ||
} | ||
execute { | ||
let valueBalance = EVM.Balance(attoflow: value) | ||
let callResult = self.coa.call( | ||
to: self.evmAddress, | ||
data: calldata.decodeHex(), | ||
gasLimit: gasLimit, | ||
value: valueBalance | ||
) | ||
assert(callResult.status == EVM.Status.successful, message: "Call failed") | ||
} | ||
} | ||
` |
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
Oops, something went wrong.