startup errors fix #1
This commit is contained in:
parent
e51bb86dc0
commit
4cca40a626
|
|
@ -12,7 +12,8 @@ RUN apt-get update && apt-get install -y \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
curl \
|
curl \
|
||||||
gnupg \
|
gnupg \
|
||||||
lsb-release && \
|
lsb-release \
|
||||||
|
ffmpeg && \
|
||||||
install -m 0755 -d /etc/apt/keyrings && \
|
install -m 0755 -d /etc/apt/keyrings && \
|
||||||
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
|
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
|
||||||
chmod a+r /etc/apt/keyrings/docker.asc && \
|
chmod a+r /etc/apt/keyrings/docker.asc && \
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ async def s_api_v1_auth_me(request):
|
||||||
WalletConnection.invalidated == False
|
WalletConnection.invalidated == False
|
||||||
)
|
)
|
||||||
).order_by(WalletConnection.created.desc())
|
).order_by(WalletConnection.created.desc())
|
||||||
))).scalars().first()
|
)).scalars().first()
|
||||||
|
|
||||||
return response.json({
|
return response.json({
|
||||||
'user': request.ctx.user.json_format(),
|
'user': request.ctx.user.json_format(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import asyncio
|
|
||||||
from os import getenv, urandom
|
from os import getenv, urandom
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
@ -6,31 +5,16 @@ from nacl.bindings import crypto_sign_seed_keypair
|
||||||
from tonsdk.utils import Address
|
from tonsdk.utils import Address
|
||||||
|
|
||||||
from app.core._blockchain.ton.wallet_v3cr3 import WalletV3CR3
|
from app.core._blockchain.ton.wallet_v3cr3 import WalletV3CR3
|
||||||
from app.core.models._config import ServiceConfig
|
|
||||||
from app.core.storage import db_session
|
|
||||||
from app.core.logger import make_log
|
from app.core.logger import make_log
|
||||||
|
|
||||||
|
|
||||||
async def load_hot_pair_async():
|
def _load_seed_from_env_or_generate() -> bytes:
|
||||||
async with db_session() as session:
|
seed_hex = os.getenv("TON_INIT_HOT_SEED")
|
||||||
service_config = ServiceConfig(session)
|
if seed_hex:
|
||||||
hot_seed = await service_config.get('private_key')
|
make_log("HotWallet", "Loaded seed from env")
|
||||||
if hot_seed is None:
|
return bytes.fromhex(seed_hex)
|
||||||
make_log("HotWallet", "No seed found, generating new one", level='info')
|
make_log("HotWallet", "No seed provided; generating ephemeral seed", level='info')
|
||||||
hot_seed_env = os.getenv("TON_INIT_HOT_SEED")
|
return urandom(32)
|
||||||
if not hot_seed_env:
|
|
||||||
hot_seed_bytes = urandom(32)
|
|
||||||
make_log("HotWallet", f"Generated random seed")
|
|
||||||
else:
|
|
||||||
hot_seed_bytes = bytes.fromhex(hot_seed_env)
|
|
||||||
make_log("HotWallet", f"Loaded seed from env")
|
|
||||||
|
|
||||||
await service_config.set('private_key', hot_seed_bytes.hex())
|
|
||||||
hot_seed = hot_seed_bytes.hex()
|
|
||||||
|
|
||||||
hot_seed_bytes = bytes.fromhex(hot_seed)
|
|
||||||
public_key, private_key = crypto_sign_seed_keypair(hot_seed_bytes)
|
|
||||||
return hot_seed_bytes, public_key, private_key
|
|
||||||
|
|
||||||
|
|
||||||
_extra_ton_wallet_options = {}
|
_extra_ton_wallet_options = {}
|
||||||
|
|
@ -39,14 +23,14 @@ if getenv('TON_CUSTOM_WALLET_ADDRESS'):
|
||||||
|
|
||||||
|
|
||||||
def _init_wallet():
|
def _init_wallet():
|
||||||
# Safe to call at import time; Sanic event loop not running yet
|
hot_seed_bytes = _load_seed_from_env_or_generate()
|
||||||
hot_seed, hot_pubkey, hot_privkey = asyncio.run(load_hot_pair_async())
|
pub, priv = crypto_sign_seed_keypair(hot_seed_bytes)
|
||||||
wallet = WalletV3CR3(
|
wallet = WalletV3CR3(
|
||||||
private_key=hot_privkey,
|
private_key=priv,
|
||||||
public_key=hot_pubkey,
|
public_key=pub,
|
||||||
**_extra_ton_wallet_options
|
**_extra_ton_wallet_options
|
||||||
)
|
)
|
||||||
return hot_seed, hot_pubkey, hot_privkey, wallet
|
return hot_seed_bytes, pub, priv, wallet
|
||||||
|
|
||||||
|
|
||||||
hot_seed, hot_pubkey, hot_privkey, service_wallet = _init_wallet()
|
hot_seed, hot_pubkey, hot_privkey, service_wallet = _init_wallet()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue