- Coin: Zano → Lethean, ticker: ZAN/ZANO → LTHN - Ports: 11211 → 36941 (mainnet RPC), 46941 (testnet RPC) - Wallet: 11212 → 36944/46944 - Address prefix: iTHN - URLs: zano.org → lethean.io - Explorer links: explorer.lthn.io Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Plugins.Lethean.Configuration;
|
|
using BTCPayServer.Plugins.Lethean.RPC.Models;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace BTCPayServer.Plugins.Lethean.Services;
|
|
|
|
public class LetheanLoadUpService : IHostedService
|
|
{
|
|
private const string CryptoCode = "LTHN";
|
|
private readonly ILogger<LetheanLoadUpService> _logger;
|
|
private readonly LetheanRpcProvider _letheanRpcProvider;
|
|
private readonly LetheanConfiguration _letheanConfiguration;
|
|
|
|
public LetheanLoadUpService(ILogger<LetheanLoadUpService> logger, LetheanRpcProvider letheanRpcProvider, LetheanConfiguration letheanConfiguration)
|
|
{
|
|
_letheanRpcProvider = letheanRpcProvider;
|
|
_letheanConfiguration = letheanConfiguration;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
if (!_letheanConfiguration.LetheanConfigurationItems.TryGetValue(CryptoCode, out var configItem))
|
|
{
|
|
_logger.LogInformation("No Lethean configuration found, skipping wallet load");
|
|
return;
|
|
}
|
|
|
|
var walletDir = configItem.WalletDirectory;
|
|
if (!string.IsNullOrEmpty(walletDir))
|
|
{
|
|
_logger.LogInformation("Attempting to load existing Lethean wallet");
|
|
|
|
string password = await TryToGetPassword(walletDir, cancellationToken);
|
|
|
|
await _letheanRpcProvider.WalletRpcClients[CryptoCode]
|
|
.SendCommandAsync<OpenWalletRequest, OpenWalletResponse>("open_wallet",
|
|
new OpenWalletRequest { Filename = "wallet", Password = password }, cancellationToken);
|
|
|
|
await _letheanRpcProvider.UpdateSummary(CryptoCode);
|
|
_logger.LogInformation("Existing Lethean wallet successfully loaded");
|
|
}
|
|
else
|
|
{
|
|
_logger.LogInformation("No wallet directory configured. Wallet should be pre-opened in simplewallet RPC mode.");
|
|
// Still try to update summary — wallet may already be running in RPC mode
|
|
await _letheanRpcProvider.UpdateSummary(CryptoCode);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError("Failed to load {CryptoCode} wallet. Error: {ErrorMessage}", CryptoCode, ex.Message);
|
|
}
|
|
}
|
|
|
|
private async Task<string> TryToGetPassword(string walletDir, CancellationToken cancellationToken)
|
|
{
|
|
string password = "";
|
|
string passwordFile = Path.Combine(walletDir, "password");
|
|
if (File.Exists(passwordFile))
|
|
{
|
|
password = await File.ReadAllTextAsync(passwordFile, cancellationToken);
|
|
password = password.Trim();
|
|
}
|
|
else
|
|
{
|
|
_logger.LogInformation("No password file found - using empty password");
|
|
}
|
|
|
|
return password;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|