Spaces:
No application file
wallet_manager.py
Browse files# wallet_manager.py
from solana.rpc.api import Client
from solana.keypair import Keypair
import base58
import os
class WalletManager:
def __init__(self, rpc_url="https://api.mainnet-beta.solana.com"):
self.client = Client(rpc_url)
self.wallets = {}
def load_wallet(self, private_key_b58, wallet_name):
decoded = base58.b58decode(private_key_b58)
keypair = Keypair.from_secret_key(decoded)
self.wallets[wallet_name] = keypair
print(f"[WalletManager] Wallet {wallet_name} loaded.")
def get_balance(self, wallet_name):
pubkey = self.wallets[wallet_name].public_key
return self.client.get_balance(pubkey)["result"]["value"] / 1e9 # SOL units
def connect_wallet_frontend(self, pubkey):
"""
Simulated connect wallet for frontend component.
"""
return f"[WalletManager] Connected to wallet: {pubkey}"
- wallet_manager.py +26 -0
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# wallet_manager.py
|
| 2 |
+
from solana.rpc.api import Client
|
| 3 |
+
from solana.keypair import Keypair
|
| 4 |
+
import base58
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
class WalletManager:
|
| 8 |
+
def __init__(self, rpc_url="https://api.mainnet-beta.solana.com"):
|
| 9 |
+
self.client = Client(rpc_url)
|
| 10 |
+
self.wallets = {}
|
| 11 |
+
|
| 12 |
+
def load_wallet(self, private_key_b58, wallet_name):
|
| 13 |
+
decoded = base58.b58decode(private_key_b58)
|
| 14 |
+
keypair = Keypair.from_secret_key(decoded)
|
| 15 |
+
self.wallets[wallet_name] = keypair
|
| 16 |
+
print(f"[WalletManager] Wallet {wallet_name} loaded.")
|
| 17 |
+
|
| 18 |
+
def get_balance(self, wallet_name):
|
| 19 |
+
pubkey = self.wallets[wallet_name].public_key
|
| 20 |
+
return self.client.get_balance(pubkey)["result"]["value"] / 1e9 # SOL units
|
| 21 |
+
|
| 22 |
+
def connect_wallet_frontend(self, pubkey):
|
| 23 |
+
"""
|
| 24 |
+
Simulated connect wallet for frontend component.
|
| 25 |
+
"""
|
| 26 |
+
return f"[WalletManager] Connected to wallet: {pubkey}"
|