2024-05-31 08:06:34 +00:00
|
|
|
|
using CodexContractsPlugin.Marketplace;
|
|
|
|
|
using GethPlugin;
|
|
|
|
|
using Logging;
|
|
|
|
|
using Nethereum.Hex.HexTypes;
|
|
|
|
|
using NethereumWorkflow.BlockUtils;
|
|
|
|
|
using Utils;
|
|
|
|
|
|
|
|
|
|
namespace CodexContractsPlugin
|
|
|
|
|
{
|
|
|
|
|
public interface ICodexContractsEvents
|
|
|
|
|
{
|
2024-05-31 08:16:57 +00:00
|
|
|
|
BlockInterval BlockInterval { get; }
|
2024-05-31 08:06:34 +00:00
|
|
|
|
Request[] GetStorageRequests();
|
|
|
|
|
RequestFulfilledEventDTO[] GetRequestFulfilledEvents();
|
|
|
|
|
RequestCancelledEventDTO[] GetRequestCancelledEvents();
|
2024-08-21 11:59:54 +00:00
|
|
|
|
RequestFailedEventDTO[] GetRequestFailedEvents();
|
2024-05-31 08:06:34 +00:00
|
|
|
|
SlotFilledEventDTO[] GetSlotFilledEvents();
|
|
|
|
|
SlotFreedEventDTO[] GetSlotFreedEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CodexContractsEvents : ICodexContractsEvents
|
|
|
|
|
{
|
|
|
|
|
private readonly ILog log;
|
|
|
|
|
private readonly IGethNode gethNode;
|
|
|
|
|
private readonly CodexContractsDeployment deployment;
|
|
|
|
|
|
|
|
|
|
public CodexContractsEvents(ILog log, IGethNode gethNode, CodexContractsDeployment deployment, BlockInterval blockInterval)
|
|
|
|
|
{
|
|
|
|
|
this.log = log;
|
|
|
|
|
this.gethNode = gethNode;
|
|
|
|
|
this.deployment = deployment;
|
2024-05-31 08:16:57 +00:00
|
|
|
|
BlockInterval = blockInterval;
|
2024-05-31 08:06:34 +00:00
|
|
|
|
}
|
2024-05-31 08:16:57 +00:00
|
|
|
|
|
|
|
|
|
public BlockInterval BlockInterval { get; }
|
2024-05-31 08:06:34 +00:00
|
|
|
|
|
|
|
|
|
public Request[] GetStorageRequests()
|
|
|
|
|
{
|
2024-05-31 08:16:57 +00:00
|
|
|
|
var events = gethNode.GetEvents<StorageRequestedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
2024-05-31 08:06:34 +00:00
|
|
|
|
var i = new ContractInteractions(log, gethNode);
|
|
|
|
|
return events
|
|
|
|
|
.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
var requestEvent = i.GetRequest(deployment.MarketplaceAddress, e.Event.RequestId);
|
|
|
|
|
var result = requestEvent.ReturnValue1;
|
|
|
|
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
|
|
|
result.RequestId = e.Event.RequestId;
|
|
|
|
|
return result;
|
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents()
|
|
|
|
|
{
|
2024-05-31 08:16:57 +00:00
|
|
|
|
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
2024-05-31 08:06:34 +00:00
|
|
|
|
return events.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
var result = e.Event;
|
|
|
|
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
|
|
|
return result;
|
|
|
|
|
}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RequestCancelledEventDTO[] GetRequestCancelledEvents()
|
|
|
|
|
{
|
2024-05-31 08:16:57 +00:00
|
|
|
|
var events = gethNode.GetEvents<RequestCancelledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
2024-05-31 08:06:34 +00:00
|
|
|
|
return events.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
var result = e.Event;
|
|
|
|
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
|
|
|
return result;
|
|
|
|
|
}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 11:59:54 +00:00
|
|
|
|
public RequestFailedEventDTO[] GetRequestFailedEvents()
|
|
|
|
|
{
|
|
|
|
|
var events = gethNode.GetEvents<RequestFailedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
|
|
|
|
return events.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
var result = e.Event;
|
|
|
|
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
|
|
|
return result;
|
|
|
|
|
}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 08:06:34 +00:00
|
|
|
|
public SlotFilledEventDTO[] GetSlotFilledEvents()
|
|
|
|
|
{
|
2024-05-31 08:16:57 +00:00
|
|
|
|
var events = gethNode.GetEvents<SlotFilledEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
2024-05-31 08:06:34 +00:00
|
|
|
|
return events.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
var result = e.Event;
|
|
|
|
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
|
|
|
result.Host = GetEthAddressFromTransaction(e.Log.TransactionHash);
|
|
|
|
|
return result;
|
|
|
|
|
}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SlotFreedEventDTO[] GetSlotFreedEvents()
|
|
|
|
|
{
|
2024-05-31 08:16:57 +00:00
|
|
|
|
var events = gethNode.GetEvents<SlotFreedEventDTO>(deployment.MarketplaceAddress, BlockInterval);
|
2024-05-31 08:06:34 +00:00
|
|
|
|
return events.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
var result = e.Event;
|
|
|
|
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
|
|
|
return result;
|
|
|
|
|
}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BlockTimeEntry GetBlock(ulong number)
|
|
|
|
|
{
|
|
|
|
|
return gethNode.GetBlockForNumber(number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EthAddress GetEthAddressFromTransaction(string transactionHash)
|
|
|
|
|
{
|
|
|
|
|
var transaction = gethNode.GetTransaction(transactionHash);
|
|
|
|
|
return new EthAddress(transaction.From);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|