Adds transaction ID to record of user activity

This commit is contained in:
benbierens 2023-12-15 11:09:15 +01:00
parent beaa67c280
commit 03283414cb
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 32 additions and 11 deletions

View File

@ -43,29 +43,29 @@ namespace BiblioTech.Commands
await context.Followup(string.Join(Environment.NewLine, report));
}
private TestToken ProcessTokens(ICodexContracts contracts, EthAddress addr, List<string> report)
private Transaction<TestToken>? ProcessTokens(ICodexContracts contracts, EthAddress addr, List<string> report)
{
if (ShouldMintTestTokens(contracts, addr))
{
var transaction = contracts.MintTestTokens(addr, defaultTestTokensToMint);
report.Add($"Minted {defaultTestTokensToMint}. ({FormatTransactionLink(transaction)})");
return defaultTestTokensToMint;
return new Transaction<TestToken>(defaultTestTokensToMint, transaction);
}
report.Add("TestToken balance over threshold. (No TestTokens minted.)");
return 0.TestTokens();
return null;
}
private Ether ProcessEth(IGethNode gethNode, EthAddress addr, List<string> report)
private Transaction<Ether>? ProcessEth(IGethNode gethNode, EthAddress addr, List<string> report)
{
if (ShouldSendEth(gethNode, addr))
{
var transaction = gethNode.SendEth(addr, defaultEthToSend);
report.Add($"Sent {defaultEthToSend}. ({FormatTransactionLink(transaction)})");
return defaultEthToSend;
return new Transaction<Ether>(defaultEthToSend, transaction);
}
report.Add("Eth balance is over threshold. (No Eth sent.)");
return 0.Eth();
return null;
}
private bool ShouldMintTestTokens(ICodexContracts contracts, EthAddress addr)

View File

@ -0,0 +1,14 @@
namespace BiblioTech
{
public class Transaction<T>
{
public Transaction(T tokenAmount, string transactionHash)
{
TokenAmount = tokenAmount;
TransactionHash = transactionHash;
}
public T TokenAmount { get; }
public string TransactionHash { get; }
}
}

View File

@ -25,7 +25,7 @@ namespace BiblioTech
}
}
public void AddMintEventForUser(IUser user, EthAddress usedAddress, Ether eth, TestToken tokens)
public void AddMintEventForUser(IUser user, EthAddress usedAddress, Transaction<Ether>? eth, Transaction<TestToken>? tokens)
{
lock (repoLock)
{
@ -67,7 +67,14 @@ namespace BiblioTech
}
foreach (var me in userData.MintEvents)
{
result.Add($"{me.Utc.ToString("o")} - Minted {me.EthReceived} and {me.TestTokensMinted} to {me.UsedAddress}.");
if (me.EthReceived != null)
{
result.Add($"{me.Utc.ToString("o")} - Sent {me.EthReceived.TokenAmount} to {me.UsedAddress}. ({me.EthReceived.TransactionHash})");
}
if (me.TestTokensMinted != null)
{
result.Add($"{me.Utc.ToString("o")} - Minted {me.TestTokensMinted.TokenAmount} to {me.UsedAddress}. ({me.TestTokensMinted.TransactionHash})");
}
}
}
}
@ -221,7 +228,7 @@ namespace BiblioTech
public class UserMintEvent
{
public UserMintEvent(DateTime utc, EthAddress usedAddress, Ether ethReceived, TestToken testTokensMinted)
public UserMintEvent(DateTime utc, EthAddress usedAddress, Transaction<Ether>? ethReceived, Transaction<TestToken>? testTokensMinted)
{
Utc = utc;
UsedAddress = usedAddress;
@ -231,7 +238,7 @@ namespace BiblioTech
public DateTime Utc { get; }
public EthAddress UsedAddress { get; }
public Ether EthReceived { get; }
public TestToken TestTokensMinted { get; }
public Transaction<Ether>? EthReceived { get; }
public Transaction<TestToken>? TestTokensMinted { get; }
}
}