Debug logging for nethereum interactions

This commit is contained in:
benbierens 2023-10-23 16:04:50 +02:00
parent abb9560b6d
commit b3ba39b2e5
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 13 additions and 7 deletions

View File

@ -39,13 +39,12 @@ namespace Logging
LogFile.Write(ApplyReplacements(message));
}
public virtual void Debug(string message = "", int skipFrames = 0)
public void Debug(string message = "", int skipFrames = 0)
{
if (debug)
{
var callerName = DebugStack.GetCallerName(skipFrames);
// We don't use Log because in the debug output we should not have any replacements.
LogFile.Write($"(debug)({callerName}) {message}");
Log($"(debug)({callerName}) {message}");
}
}
@ -73,6 +72,7 @@ namespace Logging
private string ApplyReplacements(string str)
{
if (debug) return str;
foreach (var replacement in replacements)
{
str = replacement.Apply(str);

View File

@ -17,10 +17,6 @@
{
}
public override void Debug(string message = "", int skipFrames = 0)
{
}
public override void Error(string message)
{
Console.WriteLine("Error: " + message);

View File

@ -19,29 +19,34 @@ namespace NethereumWorkflow
public void SendEth(string toAddress, decimal ethAmount)
{
log.Debug();
var receipt = Time.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, ethAmount));
if (!receipt.Succeeded()) throw new Exception("Unable to send Eth");
}
public decimal GetEthBalance()
{
log.Debug();
return GetEthBalance(web3.TransactionManager.Account.Address);
}
public decimal GetEthBalance(string address)
{
log.Debug();
var balance = Time.Wait(web3.Eth.GetBalance.SendRequestAsync(address));
return Web3.Convert.FromWei(balance.Value);
}
public TResult Call<TFunction, TResult>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()
{
log.Debug(typeof(TFunction).ToString());
var handler = web3.Eth.GetContractQueryHandler<TFunction>();
return Time.Wait(handler.QueryAsync<TResult>(contractAddress, function));
}
public void SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()
{
log.Debug();
var handler = web3.Eth.GetContractTransactionHandler<TFunction>();
var receipt = Time.Wait(handler.SendRequestAndWaitForReceiptAsync(contractAddress, function));
if (!receipt.Succeeded()) throw new Exception("Unable to perform contract transaction.");

View File

@ -20,6 +20,7 @@ namespace NethereumWorkflow
public NethereumInteraction CreateWorkflow()
{
log.Debug("Starting interaction to " + ip + ":" + port);
return new NethereumInteraction(log, CreateWeb3());
}

View File

@ -28,6 +28,7 @@ namespace CodexContractsPlugin
public void MintTestTokens(EthAddress address, decimal amount, string tokenAddress)
{
log.Debug($"{amount} -> {address} (token: {tokenAddress})");
MintTokens(address.Address, amount, tokenAddress);
}
@ -44,6 +45,7 @@ namespace CodexContractsPlugin
public bool IsSynced(string marketplaceAddress, string marketplaceAbi)
{
log.Debug();
try
{
return IsBlockNumberOK() && IsContractAvailable(marketplaceAddress, marketplaceAbi);

View File

@ -25,6 +25,7 @@ namespace CodexContractsPlugin
var marketplaceAddress = Retry(FetchMarketplaceAddress);
if (string.IsNullOrEmpty(marketplaceAddress)) throw new InvalidOperationException("Unable to fetch marketplace account from codex-contracts node. Test infra failure.");
log.Debug("Got MarketplaceAddress: " + marketplaceAddress);
return marketplaceAddress;
}
@ -34,6 +35,7 @@ namespace CodexContractsPlugin
var marketplaceAbi = Retry(FetchMarketplaceAbi);
if (string.IsNullOrEmpty(marketplaceAbi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure.");
log.Debug("Got Marketplace ABI: " + marketplaceAbi);
return marketplaceAbi;
}