Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from solders.pubkey import Pubkey
|
|
| 6 |
from solana.rpc.api import Client
|
| 7 |
from solders.transaction import Transaction
|
| 8 |
from solders.system_program import TransferParams, transfer
|
|
|
|
| 9 |
import base58
|
| 10 |
import hashlib
|
| 11 |
import os
|
|
@@ -15,11 +16,8 @@ from fastapi.concurrency import run_in_threadpool
|
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
app = FastAPI()
|
| 22 |
-
solana_client = Client("https://
|
| 23 |
|
| 24 |
seed_text="shellinfo"
|
| 25 |
seed = hashlib.sha256(seed_text.encode()).digest()
|
|
@@ -27,6 +25,11 @@ SERVER_KEY = Keypair.from_seed(seed)
|
|
| 27 |
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
|
|
@@ -219,3 +222,32 @@ async def sign_message(payload: dict):
|
|
| 219 |
|
| 220 |
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from solana.rpc.api import Client
|
| 7 |
from solders.transaction import Transaction
|
| 8 |
from solders.system_program import TransferParams, transfer
|
| 9 |
+
from solana.rpc.types import TxOpts
|
| 10 |
import base58
|
| 11 |
import hashlib
|
| 12 |
import os
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
app = FastAPI()
|
| 20 |
+
solana_client = Client("https://mainnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b")
|
| 21 |
|
| 22 |
seed_text="shellinfo"
|
| 23 |
seed = hashlib.sha256(seed_text.encode()).digest()
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
+
class TransactionPayload(BaseModel):
|
| 29 |
+
signed_hex: str
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
|
| 34 |
|
| 35 |
|
|
|
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
+
|
| 226 |
+
@app.post("/relay/broadcast/solana")
|
| 227 |
+
async def broadcast_transaction(payload: TransactionPayload, request: Request):
|
| 228 |
+
"""
|
| 229 |
+
Receives a pre-signed transaction, strips identifying headers and broadcasts to the Solana mainnet.
|
| 230 |
+
"""
|
| 231 |
+
try:
|
| 232 |
+
|
| 233 |
+
raw_tx = base64.b64decode(payload.signed_hex)
|
| 234 |
+
|
| 235 |
+
response = solana_client.send_raw_transaction(raw_tx,opts=TxOpts(skip_preflight=False))
|
| 236 |
+
|
| 237 |
+
if not response.value:
|
| 238 |
+
raise HTTPException(status_code=400, detail="Broadcast failed: No signature returned")
|
| 239 |
+
|
| 240 |
+
return {
|
| 241 |
+
"success": True,
|
| 242 |
+
"signature": str(response.value),
|
| 243 |
+
"status": "Broadcasted via Relay"
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
except Exception as e:
|
| 247 |
+
print(f"Relay Error: {str(e)}")
|
| 248 |
+
return {
|
| 249 |
+
"success": False,
|
| 250 |
+
"signature": '',
|
| 251 |
+
"status": "Failed"
|
| 252 |
+
}
|
| 253 |
+
|