mirror of
https://github.com/Such-Software/wowcheckout.git
synced 2026-10-17 05:51:45 +02:00
Minimal changes from upstream xmrcheckout to support Wownero: - Rate provider: Nonlogs WOW-BTC via Kraken BTC/USD - Subaddress derivation: Wownero network byte overrides (53/63/54) - Payment URI scheme: wownero: - Dockerfile: Wownero binaries from Codeberg - Display text: Monero→Wownero, XMR→WOW throughout UI - Default daemon: 192.168.88.235:34568 - Added wownero-logo.svg File and folder structure kept identical to upstream for easy sync.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from .models import User
|
|
from .security import decrypt_secret
|
|
from .subaddress_derivation import derive_subaddress
|
|
|
|
|
|
MAX_SUBADDRESS_INDEX = 100
|
|
|
|
|
|
def create_subaddress_for_user(
|
|
db: Session,
|
|
*,
|
|
user: User,
|
|
) -> tuple[str, int | None]:
|
|
locked = (
|
|
db.query(User)
|
|
.filter(
|
|
User.id == user.id,
|
|
)
|
|
.with_for_update()
|
|
.first()
|
|
)
|
|
if locked is None:
|
|
raise ValueError("User not found")
|
|
start_index = int(locked.subaddress_start_index or 0)
|
|
if start_index < 0 or start_index >= MAX_SUBADDRESS_INDEX:
|
|
start_index = 0
|
|
range_start = start_index + 1
|
|
range_end = MAX_SUBADDRESS_INDEX
|
|
next_index = int(locked.next_subaddress_index or range_start)
|
|
if next_index < range_start or next_index > range_end:
|
|
next_index = range_start
|
|
next_next_index = next_index + 1
|
|
if next_next_index > range_end:
|
|
next_next_index = range_start
|
|
locked.next_subaddress_index = next_next_index
|
|
db.flush()
|
|
view_key = decrypt_secret(locked.view_key_encrypted)
|
|
address = derive_subaddress(
|
|
payment_address=locked.payment_address,
|
|
view_key=view_key,
|
|
account_index=0,
|
|
address_index=next_index,
|
|
)
|
|
return address, int(next_index)
|