Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/multi_mint_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ async def add_new_mint(wallet: Wallet, mint_url: str):
print(f"\n➕ Adding new mint: {mint_url}")

if mint_url not in wallet.mint_urls:
wallet.mint_urls.add(mint_url)
wallet.mint_urls.append(mint_url)

# Update wallet event with new mint
try:
await wallet.initialize_wallet(force=True)
# Need to provide wallet_privkey to update the wallet event
# For this example, we'll use a placeholder key
wallet_privkey = "placeholder_wallet_privkey"
await wallet.event_manager.update_wallet_event(wallet_privkey)
print("✅ Mint added and wallet updated")
except Exception as e:
print(f"⚠️ Mint added locally but failed to update wallet event: {e}")
Expand Down
4 changes: 2 additions & 2 deletions examples/queued_relay_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async def demonstrate_queued_operations(wallet: Wallet):
async def show_relay_status(wallet: Wallet):
"""Show current relay configuration and status."""
print("\n🌐 Relay Configuration:")
print(f" Configured relays: {len(wallet.relays)}")
for i, relay in enumerate(wallet.relays, 1):
print(f" Configured relays: {len(wallet.relay_urls)}")
for i, relay in enumerate(wallet.relay_urls, 1):
print(f" {i}. {relay}")

print(
Expand Down
17 changes: 12 additions & 5 deletions examples/recovery_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ async def demonstrate_recovery(nsec: str):
async with Wallet(nsec=nsec) as wallet:
print("✅ Wallet created and connected to relays")

# Check if wallet events exist
exists, wallet_event = await wallet.check_wallet_event_exists()
# Fetch all wallet events to check if configuration exists
from sixty_nuts.relay import EventKind
from sixty_nuts.crypto import get_pubkey

if exists and wallet_event:
pubkey = get_pubkey(wallet._privkey)
all_events = await wallet.relay_manager.fetch_wallet_events(pubkey)
wallet_events = [e for e in all_events if e["kind"] == EventKind.Wallet]

if wallet_events:
# Get the newest wallet event
wallet_event = max(wallet_events, key=lambda e: e["created_at"])
from datetime import datetime

created_time = datetime.fromtimestamp(wallet_event["created_at"])
Expand All @@ -38,8 +45,8 @@ async def demonstrate_recovery(nsec: str):
for i, mint_url in enumerate(wallet.mint_urls, 1):
print(f" {i}. {mint_url}")

print(f" Relays: {len(wallet.relays)}")
for i, relay_url in enumerate(wallet.relays, 1):
print(f" Relays: {len(wallet.relay_urls)}")
for i, relay_url in enumerate(wallet.relay_urls, 1):
print(f" {i}. {relay_url}")

# Show recovered balance and proofs
Expand Down
19 changes: 13 additions & 6 deletions examples/refresh_proofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ async def refresh_proofs(wallet: Wallet):
print("❌ No proofs found in wallet!")
return

print(f"Found {len(state.proofs)} proofs worth {state.balance} sats")
print(
f"Found {len(state.proofs)} proofs worth {await state.total_balance_sat()} sats"
)

print(f"Refreshing proofs at {len(state.proofs_by_mints)} mint(s)...")
print(f"Refreshing proofs at {len(state.proofs_by_mint)} mint(s)...")

for mint_url, mint_proofs in state.proofs_by_mints.items():
for mint_url, mint_proofs in state.proofs_by_mint.items():
mint_balance = sum(p["amount"] for p in mint_proofs)
print(f"\n📍 Processing {len(mint_proofs)} proofs at {mint_url}")
print(f" Balance: {mint_balance} sats")

try:
# Get currency unit from the first proof
currency = mint_proofs[0].get("unit", "sat")

# Calculate optimal denominations for consolidation
optimal_denoms = wallet._calculate_optimal_denominations(mint_balance)
optimal_denoms = await wallet._calculate_optimal_denominations(
mint_balance, mint_url, currency
)

# Swap proofs for optimal denominations
new_proofs = await wallet._swap_proof_denominations(
mint_proofs, optimal_denoms, mint_url
mint_proofs, optimal_denoms, mint_url, currency
)

print(f" ✅ Refreshed to {len(new_proofs)} optimized proofs")
Expand All @@ -47,7 +54,7 @@ async def refresh_proofs(wallet: Wallet):
# Verify final state
print("\nVerifying final state...")
final_state = await wallet.fetch_wallet_state(check_proofs=True)
print(f"Final balance: {final_state.balance} sats")
print(f"Final balance: {await final_state.total_balance_sat()} sats")
print(f"Final proof count: {len(final_state.proofs)}")


Expand Down
2 changes: 1 addition & 1 deletion examples/split_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def split_tokens(wallet: Wallet, target_amounts: list[int]):

# Get current wallet state
state = await wallet.fetch_wallet_state(check_proofs=False)
print(f"💳 Current balance: {state.balance} sats")
print(f"💳 Current balance: {await state.total_balance_sat()} sats")

# For each target amount, try to create exact tokens
created_tokens = []
Expand Down
4 changes: 2 additions & 2 deletions sixty_nuts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

from .wallet import Wallet
from .temp import TempWallet
from .types import ProofDict, WalletError
from .types import Proof, WalletError

__all__ = [
# Main wallet classes
"Wallet",
# Temporary wallet
"TempWallet",
# Shared types
"ProofDict",
"Proof",
"WalletError",
]
Loading
Loading