diff --git a/src/bridge/bridge_daemon.py b/src/bridge/bridge_daemon.py new file mode 100644 index 00000000..513860bb --- /dev/null +++ b/src/bridge/bridge_daemon.py @@ -0,0 +1,26 @@ +# BridgeDaemon: Daemon to handle the RustChain to Ergo bridge +import time +from ergo_connector import ErgoBridgeConnector + +class BridgeDaemon: + def __init__(self, ergo_rpc_url, rustchain_node_url, contract_address): + self.connector = ErgoBridgeConnector(ergo_rpc_url, rustchain_node_url, contract_address) + + def start(self): + while True: + try: + # Get Merkle root from RustChain + merkle_root = self.connector.get_merkle_root() + + # Verify if contract exists on Ergo + if self.connector.verify_contract(): + # Submit Merkle root to Ergo + result = self.connector.submit_merkle_root_to_ergo(merkle_root) + print(f'Successfully submitted Merkle root: {result}') + else: + print('Contract does not exist on Ergo') + + except Exception as e: + print(f'Error: {e}') + + time.sleep(60) # Sleep for 1 minute before retrying diff --git a/src/bridge/config.json b/src/bridge/config.json new file mode 100644 index 00000000..ea0d5414 --- /dev/null +++ b/src/bridge/config.json @@ -0,0 +1,5 @@ +{ + "ergo_rpc_url": "https://ergo.mainnet.rpc", + "rustchain_node_url": "http://localhost:8080", + "contract_address": "9d97f3f8e6b225c8e7a3edfb618f604b257bc2d9bfc9d7ee599c3ff64c7de02f" +} \ No newline at end of file diff --git a/src/bridge/ergo_connector.py b/src/bridge/ergo_connector.py new file mode 100644 index 00000000..35c421df --- /dev/null +++ b/src/bridge/ergo_connector.py @@ -0,0 +1,33 @@ +# ErgoBridgeConnector: Interface for connecting RustChain to Ergo mainnet +import json +import requests + +class ErgoBridgeConnector: + def __init__(self, ergo_rpc_url, rustchain_node_url, contract_address): + self.ergo_rpc_url = ergo_rpc_url + self.rustchain_node_url = rustchain_node_url + self.contract_address = contract_address + + def get_merkle_root(self): + # Get Merkle root from RustChain node + response = requests.get(f'{self.rustchain_node_url}/get_merkle_root') + if response.status_code == 200: + return response.json()['merkle_root'] + else: + raise Exception('Failed to fetch Merkle root from RustChain') + + def submit_merkle_root_to_ergo(self, merkle_root): + # Submit Merkle root to Ergo contract + data = {"contract_address": self.contract_address, "merkle_root": merkle_root} + response = requests.post(f'{self.ergo_rpc_url}/submit_merkle_root', json=data) + if response.status_code != 200: + raise Exception('Failed to submit Merkle root to Ergo') + return response.json() + + def verify_contract(self): + # Verify if the contract exists on Ergo + response = requests.get(f'{self.ergo_rpc_url}/verify_contract/{self.contract_address}') + if response.status_code == 200: + return response.json()['status'] == 'exists' + else: + raise Exception('Failed to verify contract on Ergo')