Update app.py
Browse files
app.py
CHANGED
|
@@ -13,12 +13,20 @@ import os
|
|
| 13 |
#from helpers.mongodbconnection import provideClient
|
| 14 |
from fastapi.concurrency import run_in_threadpool
|
| 15 |
import pybase64
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
app = FastAPI()
|
| 20 |
solana_client = Client("https://devnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
seed_text="shellinfo"
|
| 23 |
seed = hashlib.sha256(seed_text.encode()).digest()
|
| 24 |
SERVER_KEY = Keypair.from_seed(seed)
|
|
@@ -31,6 +39,9 @@ class TransactionPayload(BaseModel):
|
|
| 31 |
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
|
|
@@ -254,4 +265,46 @@ async def broadcast_transaction(payload: TransactionPayload):
|
|
| 254 |
"signature": '',
|
| 255 |
"status": "Failed"
|
| 256 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
|
|
|
| 13 |
#from helpers.mongodbconnection import provideClient
|
| 14 |
from fastapi.concurrency import run_in_threadpool
|
| 15 |
import pybase64
|
| 16 |
+
from web3 import Web3
|
| 17 |
+
import hexbytes
|
| 18 |
+
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
app = FastAPI()
|
| 23 |
solana_client = Client("https://devnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b")
|
| 24 |
|
| 25 |
+
ETH_RPC_URL = "https://mainnet.infura.io/v3/7ad20d8703134068a4e4563f4a5a2279"
|
| 26 |
+
w3 = Web3(Web3.HTTPProvider(ETH_RPC_URL))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
seed_text="shellinfo"
|
| 31 |
seed = hashlib.sha256(seed_text.encode()).digest()
|
| 32 |
SERVER_KEY = Keypair.from_seed(seed)
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
+
class EthTransactionPayload(BaseModel):
|
| 43 |
+
signed_hex: str # The 0x... hex string from your frontend ethers.js code
|
| 44 |
+
|
| 45 |
|
| 46 |
|
| 47 |
|
|
|
|
| 265 |
"signature": '',
|
| 266 |
"status": "Failed"
|
| 267 |
}
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
@app.post("/relay/broadcast/ethereum")
|
| 274 |
+
async def broadcast_ethereum_transaction(payload: EthTransactionPayload):
|
| 275 |
+
"""
|
| 276 |
+
Receives a signed ETH hex, strips headers,
|
| 277 |
+
and broadcasts to the Ethereum network.
|
| 278 |
+
"""
|
| 279 |
+
try:
|
| 280 |
+
# 1. Connection Check
|
| 281 |
+
if not w3.is_connected():
|
| 282 |
+
raise HTTPException(status_code=500, detail="Relayer lost connection to Ethereum Gateway")
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
signed_tx = payload.signed_hex if payload.signed_hex.startswith("0x") else f"0x{payload.signed_hex}"
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
tx_hash = w3.eth.send_raw_transaction(signed_tx)
|
| 289 |
+
|
| 290 |
+
return {
|
| 291 |
+
"success": True,
|
| 292 |
+
"signature": tx_hash.hex(),
|
| 293 |
+
"status": "Relayed to Ethereum Network"
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
except ValueError as ve:
|
| 297 |
+
print(f"Validation Error: {str(ve)}")
|
| 298 |
+
return {
|
| 299 |
+
"success": False,
|
| 300 |
+
"signature": tx_hash.hex(),
|
| 301 |
+
"status": "Validation Error"
|
| 302 |
+
}
|
| 303 |
+
except Exception as e:
|
| 304 |
+
print(f"Relay Error: {str(e)}")
|
| 305 |
+
return {
|
| 306 |
+
"success": False,
|
| 307 |
+
"signature": tx_hash.hex(),
|
| 308 |
+
"status": "Relay error"
|
| 309 |
+
}
|
| 310 |
|