Junaidb commited on
Commit
e9d8d8c
·
verified ·
1 Parent(s): 322091c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -7,18 +7,16 @@ from solana.rpc.api import Client
7
  from solders.transaction import Transaction
8
  from solders.system_program import TransferParams, transfer
9
  import base58
10
-
11
  #from helpers.mongodbconnection import provideClient
12
 
13
 
14
-
15
-
16
  app = FastAPI()
17
  solana_client = Client("https://api.mainnet-beta.solana.com")
18
 
19
- SERVER_KEY = Keypair.from_base58_string("2vk9M7jMzikHmN8bDfUfzfCHj1mW2BjQMGucgbBszJuKuAnaRMSteAYmsh")
20
-
21
-
22
 
23
 
24
  @app.post("/relay-txn")
@@ -39,19 +37,16 @@ async def relay_txn(payload: dict):
39
  # 2. Transaction Execution
40
  # Deserialize the transaction sent from the UI
41
  raw_tx = base58.b58decode(payload['txn'])
42
- txn = Transaction.deserialize(raw_tx)
43
-
44
- # THE MAGIC STEP: The server signs as the "Fee Payer"
45
- # The 'From' address in the txn is still the user's wallet!
46
- response = client.send_transaction(txn, SERVER_PAYER_KEY)
47
-
48
- #🏁 THIS IS IT: The actual on-chain signature!
49
- actual_signature = str(response.value)
50
 
 
51
  return {
52
- "success": True,
53
- "signature": actual_signature,
54
- "status": "Finalized on Solana"
55
  }
56
 
57
 
 
7
  from solders.transaction import Transaction
8
  from solders.system_program import TransferParams, transfer
9
  import base58
10
+ import hashlib
11
  #from helpers.mongodbconnection import provideClient
12
 
13
 
 
 
14
  app = FastAPI()
15
  solana_client = Client("https://api.mainnet-beta.solana.com")
16
 
17
+ seed_text="shellinfo"
18
+ seed = hashlib.sha256(seed_text.encode()).digest()
19
+ SERVER_KEY = Keypair.fromSeed(seed)
20
 
21
 
22
  @app.post("/relay-txn")
 
37
  # 2. Transaction Execution
38
  # Deserialize the transaction sent from the UI
39
  raw_tx = base58.b58decode(payload['txn'])
40
+ txn = Transaction.from_bytes(raw_tx)
41
+ txn.sign([SERVER_KEY], txn.message.recent_blockhash)
42
+ partial_signed_bytes = bytes(txn)
43
+ encoded_txn = base58.b58encode(partial_signed_bytes).decode('utf-8')
 
 
 
 
44
 
45
+
46
  return {
47
+ "success": True,
48
+ "encoded_txn": encoded_txn,
49
+ "status": "Finalized on Solana"
50
  }
51
 
52