Extracts event methods from CodexContractsAccess
This commit is contained in:
parent
f1d453251c
commit
f94a67adb4
|
@ -0,0 +1,7 @@
|
||||||
|
namespace CodexContractsPlugin.ChainMonitor
|
||||||
|
{
|
||||||
|
public class ChainEvents
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace CodexContractsPlugin.ChainMonitor
|
||||||
|
{
|
||||||
|
public class ChainState
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,8 @@
|
||||||
using GethPlugin;
|
using GethPlugin;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Nethereum.ABI;
|
using Nethereum.ABI;
|
||||||
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;
|
||||||
|
@ -22,13 +20,10 @@ namespace CodexContractsPlugin
|
||||||
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
||||||
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
||||||
|
|
||||||
Request[] GetStorageRequests(BlockInterval blockRange);
|
ICodexContractsEvents GetEvents(TimeRange timeRange);
|
||||||
|
ICodexContractsEvents GetEvents(BlockInterval blockInterval);
|
||||||
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
||||||
RequestState GetRequestState(Request request);
|
RequestState GetRequestState(Request request);
|
||||||
RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockInterval blockRange);
|
|
||||||
RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockInterval blockRange);
|
|
||||||
SlotFilledEventDTO[] GetSlotFilledEvents(BlockInterval blockRange);
|
|
||||||
SlotFreedEventDTO[] GetSlotFreedEvents(BlockInterval blockRange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
@ -81,65 +76,14 @@ namespace CodexContractsPlugin
|
||||||
return balance.TstWei();
|
return balance.TstWei();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request[] GetStorageRequests(BlockInterval blockRange)
|
public ICodexContractsEvents GetEvents(TimeRange timeRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<StorageRequestedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
return GetEvents(gethNode.ConvertTimeRangeToBlockRange(timeRange));
|
||||||
var i = StartInteraction();
|
|
||||||
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(BlockInterval blockRange)
|
public ICodexContractsEvents GetEvents(BlockInterval blockInterval)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
return new CodexContractsEvents(log, gethNode, Deployment, blockInterval);
|
||||||
return events.Select(e =>
|
|
||||||
{
|
|
||||||
var result = e.Event;
|
|
||||||
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
||||||
return result;
|
|
||||||
}).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockInterval blockRange)
|
|
||||||
{
|
|
||||||
var events = gethNode.GetEvents<RequestCancelledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
|
||||||
return events.Select(e =>
|
|
||||||
{
|
|
||||||
var result = e.Event;
|
|
||||||
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
||||||
return result;
|
|
||||||
}).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlotFilledEventDTO[] GetSlotFilledEvents(BlockInterval blockRange)
|
|
||||||
{
|
|
||||||
var events = gethNode.GetEvents<SlotFilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
|
||||||
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(BlockInterval blockRange)
|
|
||||||
{
|
|
||||||
var events = gethNode.GetEvents<SlotFreedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
|
||||||
return events.Select(e =>
|
|
||||||
{
|
|
||||||
var result = e.Event;
|
|
||||||
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
|
||||||
return result;
|
|
||||||
}).ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex)
|
public EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex)
|
||||||
|
@ -170,17 +114,6 @@ 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)
|
|
||||||
{
|
|
||||||
var transaction = gethNode.GetTransaction(transactionHash);
|
|
||||||
return new EthAddress(transaction.From);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContractInteractions StartInteraction()
|
private ContractInteractions StartInteraction()
|
||||||
{
|
{
|
||||||
return new ContractInteractions(log, gethNode);
|
return new ContractInteractions(log, gethNode);
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
using CodexContractsPlugin.Marketplace;
|
||||||
|
using GethPlugin;
|
||||||
|
using Logging;
|
||||||
|
using Nethereum.Hex.HexTypes;
|
||||||
|
using NethereumWorkflow.BlockUtils;
|
||||||
|
using Utils;
|
||||||
|
|
||||||
|
namespace CodexContractsPlugin
|
||||||
|
{
|
||||||
|
public interface ICodexContractsEvents
|
||||||
|
{
|
||||||
|
Request[] GetStorageRequests();
|
||||||
|
RequestFulfilledEventDTO[] GetRequestFulfilledEvents();
|
||||||
|
RequestCancelledEventDTO[] GetRequestCancelledEvents();
|
||||||
|
SlotFilledEventDTO[] GetSlotFilledEvents();
|
||||||
|
SlotFreedEventDTO[] GetSlotFreedEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CodexContractsEvents : ICodexContractsEvents
|
||||||
|
{
|
||||||
|
private readonly ILog log;
|
||||||
|
private readonly IGethNode gethNode;
|
||||||
|
private readonly CodexContractsDeployment deployment;
|
||||||
|
private readonly BlockInterval blockInterval;
|
||||||
|
|
||||||
|
public CodexContractsEvents(ILog log, IGethNode gethNode, CodexContractsDeployment deployment, BlockInterval blockInterval)
|
||||||
|
{
|
||||||
|
this.log = log;
|
||||||
|
this.gethNode = gethNode;
|
||||||
|
this.deployment = deployment;
|
||||||
|
this.blockInterval = blockInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Request[] GetStorageRequests()
|
||||||
|
{
|
||||||
|
var events = gethNode.GetEvents<StorageRequestedEventDTO>(deployment.MarketplaceAddress, blockInterval);
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(deployment.MarketplaceAddress, blockInterval);
|
||||||
|
return events.Select(e =>
|
||||||
|
{
|
||||||
|
var result = e.Event;
|
||||||
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
||||||
|
return result;
|
||||||
|
}).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequestCancelledEventDTO[] GetRequestCancelledEvents()
|
||||||
|
{
|
||||||
|
var events = gethNode.GetEvents<RequestCancelledEventDTO>(deployment.MarketplaceAddress, blockInterval);
|
||||||
|
return events.Select(e =>
|
||||||
|
{
|
||||||
|
var result = e.Event;
|
||||||
|
result.Block = GetBlock(e.Log.BlockNumber.ToUlong());
|
||||||
|
return result;
|
||||||
|
}).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SlotFilledEventDTO[] GetSlotFilledEvents()
|
||||||
|
{
|
||||||
|
var events = gethNode.GetEvents<SlotFilledEventDTO>(deployment.MarketplaceAddress, blockInterval);
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
var events = gethNode.GetEvents<SlotFreedEventDTO>(deployment.MarketplaceAddress, blockInterval);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,8 +89,8 @@ namespace CodexTests.BasicTests
|
||||||
{
|
{
|
||||||
Time.Retry(() =>
|
Time.Retry(() =>
|
||||||
{
|
{
|
||||||
var blockRange = geth.ConvertTimeRangeToBlockRange(GetTestRunTimeRange());
|
var events = contracts.GetEvents(GetTestRunTimeRange());
|
||||||
var slotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
var slotFilledEvents = events.GetSlotFilledEvents();
|
||||||
|
|
||||||
Debug($"SlotFilledEvents: {slotFilledEvents.Length} - NumSlots: {purchase.MinRequiredNumberOfNodes}");
|
Debug($"SlotFilledEvents: {slotFilledEvents.Length} - NumSlots: {purchase.MinRequiredNumberOfNodes}");
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ namespace CodexTests.BasicTests
|
||||||
|
|
||||||
private Request GetOnChainStorageRequest(ICodexContracts contracts, IGethNode geth)
|
private Request GetOnChainStorageRequest(ICodexContracts contracts, IGethNode geth)
|
||||||
{
|
{
|
||||||
var requests = contracts.GetStorageRequests(geth.ConvertTimeRangeToBlockRange(GetTestRunTimeRange()));
|
var events = contracts.GetEvents(GetTestRunTimeRange());
|
||||||
|
var requests = events.GetStorageRequests();
|
||||||
Assert.That(requests.Length, Is.EqualTo(1));
|
Assert.That(requests.Length, Is.EqualTo(1));
|
||||||
return requests.Single();
|
return requests.Single();
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,11 +434,12 @@ namespace CodexTests.UtilityTests
|
||||||
var range = geth.ConvertTimeRangeToBlockRange(new TimeRange(start, stop));
|
var range = geth.ConvertTimeRangeToBlockRange(new TimeRange(start, stop));
|
||||||
|
|
||||||
|
|
||||||
LogEvents(nameof(contracts.GetStorageRequests), contracts.GetStorageRequests, range);
|
throw new Exception();
|
||||||
LogEvents(nameof(contracts.GetRequestFulfilledEvents), contracts.GetRequestFulfilledEvents, range);
|
//LogEvents(nameof(contracts.GetStorageRequests), contracts.GetStorageRequests, range);
|
||||||
LogEvents(nameof(contracts.GetRequestCancelledEvents), contracts.GetRequestCancelledEvents, range);
|
//LogEvents(nameof(contracts.GetRequestFulfilledEvents), contracts.GetRequestFulfilledEvents, range);
|
||||||
LogEvents(nameof(contracts.GetSlotFilledEvents), contracts.GetSlotFilledEvents, range);
|
//LogEvents(nameof(contracts.GetRequestCancelledEvents), contracts.GetRequestCancelledEvents, range);
|
||||||
LogEvents(nameof(contracts.GetSlotFreedEvents), contracts.GetSlotFreedEvents, range);
|
//LogEvents(nameof(contracts.GetSlotFilledEvents), contracts.GetSlotFilledEvents, range);
|
||||||
|
//LogEvents(nameof(contracts.GetSlotFreedEvents), contracts.GetSlotFreedEvents, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogEvents(string n, Func<BlockInterval, object> f, BlockInterval r)
|
private void LogEvents(string n, Func<BlockInterval, object> f, BlockInterval r)
|
||||||
|
|
|
@ -37,17 +37,19 @@ namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
this.historicState = historicState;
|
this.historicState = historicState;
|
||||||
|
|
||||||
NewRequests = contracts.GetStorageRequests(blockRange);
|
throw new Exception("This is getting a rewrite");
|
||||||
historicState.CleanUpOldRequests();
|
|
||||||
historicState.ProcessNewRequests(NewRequests);
|
|
||||||
historicState.UpdateStorageRequests(contracts);
|
|
||||||
|
|
||||||
StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
//NewRequests = contracts.GetStorageRequests(blockRange);
|
||||||
FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFinished).ToArray();
|
//historicState.CleanUpOldRequests();
|
||||||
RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
//historicState.ProcessNewRequests(NewRequests);
|
||||||
RequestCancelledEvents = contracts.GetRequestCancelledEvents(blockRange);
|
//historicState.UpdateStorageRequests(contracts);
|
||||||
SlotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
|
||||||
SlotFreedEvents = contracts.GetSlotFreedEvents(blockRange);
|
//StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
||||||
|
//FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFinished).ToArray();
|
||||||
|
//RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
||||||
|
//RequestCancelledEvents = contracts.GetRequestCancelledEvents(blockRange);
|
||||||
|
//SlotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
||||||
|
//SlotFreedEvents = contracts.GetSlotFreedEvents(blockRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChainState(
|
public ChainState(
|
||||||
|
|
Loading…
Reference in New Issue