From c7084abc5b43329a1661aa082b49c37c4ab7a995 Mon Sep 17 00:00:00 2001 From: Prathiksha-Nataraja <90592522+Prathiksha-Nataraja@users.noreply.github.com> Date: Mon, 29 May 2023 17:47:03 +0530 Subject: [PATCH 1/2] chore: relay setup --- services/{jvm/.gitkeep => bin/relay} | 0 services/jvm/chain_config.json | 26 +++++++++++ services/jvm/relay.star | 64 ++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) rename services/{jvm/.gitkeep => bin/relay} (100%) create mode 100644 services/jvm/chain_config.json create mode 100644 services/jvm/relay.star diff --git a/services/jvm/.gitkeep b/services/bin/relay similarity index 100% rename from services/jvm/.gitkeep rename to services/bin/relay diff --git a/services/jvm/chain_config.json b/services/jvm/chain_config.json new file mode 100644 index 00000000..8a14259e --- /dev/null +++ b/services/jvm/chain_config.json @@ -0,0 +1,26 @@ +{ + "chains": { + "icon0": { + "network": "0x3.icon", + "endpoint": "http://localhost:9080/api/v3/icon_dex", + "keystore": "./docker/icon/config/keystore.json", + "keysecret": "./docker/icon/config/keysecret" + }, + "icon1": { + "network": "0x101.icon", + "endpoint": "http://localhost:9180/api/v3/icon_dex", + "keystore": "./docker/icon/config/keystore.json", + "keysecret": "./docker/icon/config/keysecret" + }, + "hardhat": { + "network": "0x539.hardhat", + "endpoint": "http://localhost:8545", + "keystore": "./docker/hardhat/keystore0.json", + "keypass": "hardhat" + } + }, + "link": { + "src": "icon0", + "dst": "hardhat" + } +} diff --git a/services/jvm/relay.star b/services/jvm/relay.star new file mode 100644 index 00000000..e15d140a --- /dev/null +++ b/services/jvm/relay.star @@ -0,0 +1,64 @@ +RELAY_BIN = "../bin/relay" + +def relay(plan,args,chain_config_path, deployment_path): + if RELAY_BIN != "null": + hello=plan.add_service(name="hello", config=ServiceConfig( + image="ubuntu:latest", + )) + plan.exec(service_name="hello",recipe=ExecRecipe( + command=["echo", "hello"], + )) + else: + RELAY_BIN + SRC_NETWORK = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "."+SRC+".network", deployment_path],)) + SRC_BMC_ADDRESS = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "."+SRC+".contracts.bmc"],)) + SRC_ADDRESS = "btp://"+SRC_NETWORK+"/"+SRC_BMC_ADDRESS + SRC = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".link.src",chain_config_path],)) + SRC_ENDPOINT = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".chains."+SRC+".endpoint"],)) + SRC_KEY_STORE = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".chains."+SRC+".keystore" ],)) + SRC_KEY_SECRET = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".chains."+SRC+".keysecret" ],)) + + if SRC_KEY_SECRET != "null": + SRC_KEY_PASSWORD = plan.print(SRC_KEY_SECRET) + else: + SRC_KEY_PASSWORD = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "chain."+SRC+".keypass"],)) + + DST_NETWORK = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "."+DST+".network", deployment_path],)) + DST_BMC_ADDRESS = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "."+DST+".contracts.bmc"],)) + DST_ADDRESS = "btp://"+DST_NETWORK+"/"+DST_BMC_ADDRESS + DST = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".link.dst",chain_config_path],)) + DST_ENDPOINT = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".chains."+DST+".endpoint"],)) + DST_KEY_STORE = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".chains."+DST+".keystore" ],)) + DST_KEY_SECRET = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", ".chains."+DST+".keysecret" ],)) + + if DST_KEY_SECRET != "null": + DST_KEY_PASSWORD = plan.print(DST_KEY_SECRET) + else: + DST_KEY_PASSWORD = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "chain."+DST+".keypass"],)) + + if BMV_BRIDGE == True: + plan.print("using bridge mode") + else: + plan.print("Using BTP Block node") + BMV_BRIDGE = False + + RELAY_BIN [ + "--direction", "both", + "--src_address", SRC_ADDRESS, + "--src.endpoint", SRC_ENDPOINT, + "--src.key_store", SRC_KEY_STORE, + "--src.key_password", SRC_KEY_PASSWORD, + "--src.bridge_mode", BMV_BRIDGE, + "--dst.address", DST_ADDRESS, + "--dst.endpoint", DST_ENDPOINT, + "--dst.key_store", DST_KEY_STORE, + "--dst.key_password", DST_KEY_PASSWORD, + "start" + ] + +def run(plan,args): + plan.print("hello") + result = relay(plan, args, chain_config_path, deployment_path) +run() + + \ No newline at end of file From eecce54f293251307ee343b17a6cf0427fb38122 Mon Sep 17 00:00:00 2001 From: Prathiksha-Nataraja <90592522+Prathiksha-Nataraja@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:17:28 +0530 Subject: [PATCH 2/2] chore: fixed code --- services/jvm/relay.star | 43 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/services/jvm/relay.star b/services/jvm/relay.star index e15d140a..cf8ba17b 100644 --- a/services/jvm/relay.star +++ b/services/jvm/relay.star @@ -10,6 +10,7 @@ def relay(plan,args,chain_config_path, deployment_path): )) else: RELAY_BIN + SRC_NETWORK = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "."+SRC+".network", deployment_path],)) SRC_BMC_ADDRESS = plan.exec(service_name="hello", recipe=ExecRecipe(command=["jq", "."+SRC+".contracts.bmc"],)) SRC_ADDRESS = "btp://"+SRC_NETWORK+"/"+SRC_BMC_ADDRESS @@ -42,23 +43,33 @@ def relay(plan,args,chain_config_path, deployment_path): plan.print("Using BTP Block node") BMV_BRIDGE = False - RELAY_BIN [ - "--direction", "both", - "--src_address", SRC_ADDRESS, - "--src.endpoint", SRC_ENDPOINT, - "--src.key_store", SRC_KEY_STORE, - "--src.key_password", SRC_KEY_PASSWORD, - "--src.bridge_mode", BMV_BRIDGE, - "--dst.address", DST_ADDRESS, - "--dst.endpoint", DST_ENDPOINT, - "--dst.key_store", DST_KEY_STORE, - "--dst.key_password", DST_KEY_PASSWORD, + exec_command = ExecRecipe(command=[ + RELAY_BIN, + "--direction", + "both", + "--src.address", + SRC_ADDRESS, + "--src.endpoint", + SRC_ENDPOINT, + "--src.key_store", + SRC_KEY_STORE, + "--src.key_password", + SRC_KEY_PASSWORD, + "--src.bridge_mode", + BMV_BRIDGE, + "--dst.address", + DST_ADDRESS, + "--dst.endpoint", + DST_ENDPOINT, + "--dst.key_store" + DST_KEY_STORE, + "dst.key_password", + DST_KEY_PASSWORD, "start" - ] + ],) + result = plan.exec(service_name="hello", recipe=exec_command) + + return result["output"] -def run(plan,args): - plan.print("hello") - result = relay(plan, args, chain_config_path, deployment_path) -run() \ No newline at end of file