Skip to content

Commit

Permalink
update EVM util scripts & transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Dec 2, 2024
1 parent 1ca51a6 commit c63a9f5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
6 changes: 5 additions & 1 deletion cadence/scripts/evm/call.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ access(all) fun main(
value: EVM.Balance(attoflow: 0)
)

return EVM.decodeABI(types: getTypeArray(typeIdentifiers), data: evmResult.data)
if typeIdentifiers.length == 0 {
return []
} else {
return EVM.decodeABI(types: getTypeArray(typeIdentifiers), data: evmResult.data)
}
}
14 changes: 5 additions & 9 deletions cadence/scripts/evm/get_evm_address_string.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import "EVM"
/// Returns the hex encoded address of the COA in the given Flow address
///
access(all) fun main(flowAddress: Address): String? {
if let address: EVM.EVMAddress = getAuthAccount<auth(BorrowValue) &Account>(flowAddress)
.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm)?.address() {
let bytes: [UInt8] = []
for byte in address.bytes {
bytes.append(byte)
}
return String.encodeHex(bytes)
}
return nil
return getAuthAccount<auth(BorrowValue) &Account>(flowAddress)
.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm)
?.address()
?.toString()
?? nil
}
4 changes: 1 addition & 3 deletions cadence/scripts/evm/get_evm_address_string_from_bytes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ import "EVM"
access(all) fun main(bytes: [UInt8]): String? {
let constBytes = bytes.toConstantSized<[UInt8; 20]>()
?? panic("Problem converting provided EVMAddress compatible byte array - check byte array contains 20 bytes")
return EVM.EVMAddress(
bytes: constBytes
)
return EVM.EVMAddress(bytes: constBytes).toString()
}
18 changes: 15 additions & 3 deletions cadence/transactions/evm/destroy_coa.cdc
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import "Burner"
import "EVM"

/// !!! CAUTION: Destroys the COA in the signer's account !!!
/// !!! CAUTION: Destroys the COA in the signer's account !!!
///
transaction {
prepare(signer: auth(LoadValue) &Account) {
destroy signer.storage.load<@EVM.CadenceOwnedAccount>(from: /storage/evm)!
prepare(signer: auth(LoadValue, StorageCapabilities, UnpublishCapability) &Account) {
// Unpublish the COA capability
signer.capabilities.unpublish(/public/evm)

// Delete all COA capabilities
signer.capabilities.storage.forEachController(forPath: /storage/evm, fun (controller: &StorageCapabilityController): Bool {
controller.delete()
return true
})

// Destroy the COA
let coa <- signer.storage.load<@EVM.CadenceOwnedAccount>(from: /storage/evm)!
Burner.burn(<-coa)
}
}
2 changes: 1 addition & 1 deletion cadence/transactions/evm/withdraw.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ transaction(amount: UFix64) {
}

post {
self.vault.balance == self.preBalance + amount: "Problem transfering Flow between environments!"
self.vault.balance == self.preBalance + amount: "Problem transferring Flow between environments!"
}
}

0 comments on commit c63a9f5

Please sign in to comment.