Implements getting blockTimeEntries

This commit is contained in:
benbierens 2024-04-13 09:19:20 +02:00
parent 24cf6c70b8
commit 581cc80d5d
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 32 additions and 5 deletions

View File

@ -18,6 +18,13 @@ namespace NethereumWorkflow.BlockUtils
bounds = new BlockchainBounds(cache, web3); bounds = new BlockchainBounds(cache, web3);
} }
public BlockTimeEntry Get(ulong blockNumber)
{
var b = cache.Get(blockNumber);
if (b != null) return b;
return GetBlock(blockNumber);
}
public ulong? GetHighestBlockNumberBefore(DateTime moment) public ulong? GetHighestBlockNumberBefore(DateTime moment)
{ {
bounds.Initialize(); bounds.Initialize();

View File

@ -121,5 +121,12 @@ namespace NethereumWorkflow
to: toBlock.Value to: toBlock.Value
); );
} }
public BlockTimeEntry GetBlockForNumber(ulong number)
{
var wrapper = new Web3Wrapper(web3, log);
var blockTimeFinder = new BlockTimeFinder(blockCache, wrapper, log);
return blockTimeFinder.Get(number);
}
} }
} }

View File

@ -5,6 +5,7 @@ using Nethereum.ABI;
using Nethereum.Hex.HexTypes; using Nethereum.Hex.HexTypes;
using Nethereum.Util; using Nethereum.Util;
using NethereumWorkflow; using NethereumWorkflow;
using NethereumWorkflow.BlockUtils;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Utils; using Utils;
@ -89,7 +90,7 @@ namespace CodexContractsPlugin
{ {
var requestEvent = i.GetRequest(Deployment.MarketplaceAddress, e.Event.RequestId); var requestEvent = i.GetRequest(Deployment.MarketplaceAddress, e.Event.RequestId);
var result = requestEvent.ReturnValue1; var result = requestEvent.ReturnValue1;
result.BlockNumber = e.Log.BlockNumber.ToUlong(); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
result.RequestId = e.Event.RequestId; result.RequestId = e.Event.RequestId;
return result; return result;
}) })
@ -102,7 +103,7 @@ namespace CodexContractsPlugin
return events.Select(e => return events.Select(e =>
{ {
var result = e.Event; var result = e.Event;
result.BlockNumber = e.Log.BlockNumber.ToUlong(); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result; return result;
}).ToArray(); }).ToArray();
} }
@ -113,7 +114,7 @@ namespace CodexContractsPlugin
return events.Select(e => return events.Select(e =>
{ {
var result = e.Event; var result = e.Event;
result.BlockNumber = e.Log.BlockNumber.ToUlong(); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result; return result;
}).ToArray(); }).ToArray();
} }
@ -124,7 +125,7 @@ namespace CodexContractsPlugin
return events.Select(e => return events.Select(e =>
{ {
var result = e.Event; var result = e.Event;
result.BlockNumber = e.Log.BlockNumber.ToUlong(); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
result.Host = GetEthAddressFromTransaction(e.Log.TransactionHash); result.Host = GetEthAddressFromTransaction(e.Log.TransactionHash);
return result; return result;
}).ToArray(); }).ToArray();
@ -136,7 +137,7 @@ namespace CodexContractsPlugin
return events.Select(e => return events.Select(e =>
{ {
var result = e.Event; var result = e.Event;
result.BlockNumber = e.Log.BlockNumber.ToUlong(); result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
return result; return result;
}).ToArray(); }).ToArray();
} }
@ -169,6 +170,11 @@ namespace CodexContractsPlugin
return gethNode.Call<RequestStateFunction, RequestState>(Deployment.MarketplaceAddress, func); return gethNode.Call<RequestStateFunction, RequestState>(Deployment.MarketplaceAddress, func);
} }
private BlockTimeEntry GetBlock(ulong number)
{
return gethNode.GetBlockForNumber(number);
}
private EthAddress GetEthAddressFromTransaction(string transactionHash) private EthAddress GetEthAddressFromTransaction(string transactionHash)
{ {
var transaction = gethNode.GetTransaction(transactionHash); var transaction = gethNode.GetTransaction(transactionHash);

View File

@ -5,6 +5,7 @@ using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts; using Nethereum.Contracts;
using Nethereum.RPC.Eth.DTOs; using Nethereum.RPC.Eth.DTOs;
using NethereumWorkflow; using NethereumWorkflow;
using NethereumWorkflow.BlockUtils;
using Utils; using Utils;
namespace GethPlugin namespace GethPlugin
@ -27,6 +28,7 @@ namespace GethPlugin
List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockInterval blockRange) where TEvent : IEventDTO, new(); List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockInterval blockRange) where TEvent : IEventDTO, new();
List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new(); List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new();
BlockInterval ConvertTimeRangeToBlockRange(TimeRange timeRange); BlockInterval ConvertTimeRangeToBlockRange(TimeRange timeRange);
BlockTimeEntry GetBlockForNumber(ulong number);
} }
public class DeploymentGethNode : BaseGethNode, IGethNode public class DeploymentGethNode : BaseGethNode, IGethNode
@ -160,6 +162,11 @@ namespace GethPlugin
return StartInteraction().ConvertTimeRangeToBlockRange(timeRange); return StartInteraction().ConvertTimeRangeToBlockRange(timeRange);
} }
public BlockTimeEntry GetBlockForNumber(ulong number)
{
return StartInteraction().GetBlockForNumber(number);
}
protected abstract NethereumInteraction StartInteraction(); protected abstract NethereumInteraction StartInteraction();
} }
} }