46 lines
1.3 KiB
C#
Raw Normal View History

2023-10-24 15:25:45 +02:00
using BiblioTech.Options;
using CodexContractsPlugin;
2023-10-20 10:14:56 +02:00
using GethPlugin;
2023-10-20 09:49:23 +02:00
namespace BiblioTech
{
public abstract class BaseGethCommand : BaseCommand
{
protected override async Task Invoke(CommandContext context)
{
var gethConnector = GetGeth();
if (gethConnector == null)
{
await context.Followup("Blockchain operations are (temporarily) unavailable.");
return;
}
2023-10-20 10:14:56 +02:00
2024-01-22 10:27:07 +01:00
var gethNode = gethConnector.GethNode;
var contracts = gethConnector.CodexContracts;
if (!contracts.IsDeployed())
{
await context.Followup("I'm sorry, the Codex SmartContracts are not currently deployed.");
return;
}
2023-10-20 10:14:56 +02:00
2023-10-24 15:25:45 +02:00
await Execute(context, gethNode, contracts);
2023-10-20 09:49:23 +02:00
}
private GethConnector.GethConnector? GetGeth()
{
try
{
return GethConnector.GethConnector.Initialize(Program.Log);
}
catch (Exception ex)
{
Program.Log.Error("Failed to initialize geth connector: " + ex);
return null;
}
}
2023-10-24 15:25:45 +02:00
protected abstract Task Execute(CommandContext context, IGethNode gethNode, ICodexContracts contracts);
2023-10-20 09:49:23 +02:00
}
}