Skip to content

Commit

Permalink
add registry getter script
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Aug 14, 2024
1 parent ca4c65c commit 0c2899f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cadence/scripts/utils/get_registry_address.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import "EVM"

import "FlowEVMBridgeConfig"
import "FlowEVMBridgeUtils"

access(all)
fun main(coaHost: Address): String {
let coa = getAuthAccount<auth(BorrowValue) &Account>(coaHost)
.storage
.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm)
?? panic("Could not borrow CadenceOwnedAccount from host=".concat(coaHost.toString()))
let res = coa.call(
to: FlowEVMBridgeUtils.getBridgeFactoryEVMAddress(),
data: EVM.encodeABIWithSignature("getRegistry()", []),
gasLimit: FlowEVMBridgeConfig.gasLimit,
value: EVM.Balance(attoflow: UInt(0))
)

assert(
res.status == EVM.Status.successful,
message: "getRegistry call to FlowEVMBridgeFactory failed"
)

let decodedRes = EVM.decodeABI(types: [Type<EVM.EVMAddress>()], data: res.data)

assert(decodedRes.length == 1, message: "Invalid response length")

return (decodedRes[0] as! EVM.EVMAddress).toString()
}

0 comments on commit 0c2899f

Please sign in to comment.