Adds method for checking of codex contracts are deployed

This commit is contained in:
benbierens 2023-12-18 13:32:58 +01:00
parent 2c026f99ca
commit 87e84ae90d
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 38 additions and 6 deletions

View File

@ -7,6 +7,7 @@ namespace CodexContractsPlugin
{
CodexContractsDeployment Deployment { get; }
bool IsDeployed();
string MintTestTokens(IHasEthAddress owner, TestToken testTokens);
string MintTestTokens(EthAddress ethAddress, TestToken testTokens);
TestToken GetTestTokenBalance(IHasEthAddress owner);
@ -27,6 +28,12 @@ namespace CodexContractsPlugin
public CodexContractsDeployment Deployment { get; }
public bool IsDeployed()
{
var interaction = new ContractInteractions(log, gethNode);
return !string.IsNullOrEmpty(interaction.GetTokenName(Deployment.TokenAddress));
}
public string MintTestTokens(IHasEthAddress owner, TestToken testTokens)
{
return MintTestTokens(owner.EthAddress, testTokens);

View File

@ -26,6 +26,22 @@ namespace CodexContractsPlugin
return gethNode.Call<GetTokenFunction, string>(marketplaceAddress, function);
}
public string GetTokenName(string tokenAddress)
{
try
{
log.Debug(tokenAddress);
var function = new GetTokenNameFunction();
return gethNode.Call<GetTokenNameFunction, string>(tokenAddress, function);
}
catch (Exception ex)
{
log.Log("Failed to get token name: " + ex);
return string.Empty;
}
}
public string MintTestTokens(EthAddress address, decimal amount, string tokenAddress)
{
log.Debug($"{amount} -> {address} (token: {tokenAddress})");
@ -87,6 +103,11 @@ namespace CodexContractsPlugin
{
}
[Function("name", "string")]
public class GetTokenNameFunction : FunctionMessage
{
}
[Function("mint")]
public class MintTokensFunction : FunctionMessage
{

View File

@ -59,12 +59,10 @@ namespace BiblioTech
{
protected override async Task Invoke(CommandContext context)
{
var log = new ConsoleLog();
if (!string.IsNullOrEmpty(GethInput.LoadError))
{
var msg = "Geth input incorrect: " + GethInput.LoadError;
log.Error(msg);
Program.Log.Error(msg);
if (IsInAdminChannel(context.Command))
{
await context.Followup(msg);
@ -82,8 +80,14 @@ namespace BiblioTech
tokenAddress: GethInput.TokenAddress
);
var gethNode = new CustomGethNode(log, GethInput.GethHost, GethInput.GethPort, GethInput.PrivateKey);
var contracts = new CodexContractsAccess(log, gethNode, contractsDeployment);
var gethNode = new CustomGethNode(Program.Log, GethInput.GethHost, GethInput.GethPort, GethInput.PrivateKey);
var contracts = new CodexContractsAccess(Program.Log, gethNode, contractsDeployment);
if (!contracts.IsDeployed())
{
await context.Followup("I'm sorry, the Codex SmartContracts are not currently deployed.");
return;
}
await Execute(context, gethNode, contracts);
}

View File

@ -19,7 +19,7 @@
public static string Get()
{
return "Hold on: " + messages[random.Next(messages.Length)];
return "(⏳): " + messages[random.Next(messages.Length)];
}
}
}