diff --git a/cadence/scripts/utils/get_registry_address.cdc b/cadence/scripts/utils/get_registry_address.cdc new file mode 100644 index 00000000..687d0906 --- /dev/null +++ b/cadence/scripts/utils/get_registry_address.cdc @@ -0,0 +1,29 @@ +import "EVM" + +import "FlowEVMBridgeConfig" +import "FlowEVMBridgeUtils" + +access(all) +fun main(coaHost: Address): String { + let coa = getAuthAccount(coaHost) + .storage + .borrow(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()], data: res.data) + + assert(decodedRes.length == 1, message: "Invalid response length") + + return (decodedRes[0] as! EVM.EVMAddress).toString() +}