implements writers for codex marketplace transcript events

This commit is contained in:
Ben 2024-08-20 12:13:42 +02:00
parent 09d2f418eb
commit 5170699ae4
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
5 changed files with 81 additions and 7 deletions

View File

@ -26,15 +26,16 @@ namespace CodexPlugin
public CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group)
{
var ethAccount = GetEthAccount(access);
var marketplaceAccess = GetMarketplaceAccess(access, ethAccount);
var hooks = codexHooksFactory.CreateHooks(access.Container.Name);
var marketplaceAccess = GetMarketplaceAccess(access, ethAccount, hooks);
return new CodexNode(tools, access, group, marketplaceAccess, hooks, ethAccount);
}
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAccount? ethAccount)
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAccount? ethAccount, ICodexNodeHooks hooks)
{
if (ethAccount == null) return new MarketplaceUnavailable();
return new MarketplaceAccess(tools.GetLog(), codexAccess);
return new MarketplaceAccess(tools.GetLog(), codexAccess, hooks);
}
private EthAccount? GetEthAccount(CodexAccess access)

View File

@ -1,4 +1,5 @@
using Utils;
using GethPlugin;
using Utils;
namespace CodexPlugin.Hooks
{
@ -47,12 +48,24 @@ namespace CodexPlugin.Hooks
{
}
public void OnNodeStarting(DateTime startUtc, string image)
public void OnNodeStarting(DateTime startUtc, string image, EthAccount? ethAccount)
{
}
public void OnNodeStopping()
{
}
public void OnStorageAvailabilityCreated(StorageAvailability response)
{
}
public void OnStorageContractSubmitted(StoragePurchaseContract storagePurchaseContract)
{
}
public void OnStorageContractUpdated(StoragePurchase purchaseStatus)
{
}
}
}

View File

@ -14,5 +14,6 @@ namespace CodexPlugin.Hooks
void OnFileDownloaded(ByteSize size, ContentId cid);
void OnStorageContractSubmitted(StoragePurchaseContract storagePurchaseContract);
void OnStorageContractUpdated(StoragePurchase purchaseStatus);
void OnStorageAvailabilityCreated(StorageAvailability response);
}
}

View File

@ -1,4 +1,5 @@
using CodexPlugin.Hooks;
using GethPlugin;
using OverwatchTranscript;
using Utils;
@ -19,13 +20,14 @@ namespace CodexPlugin.OverwatchSupport
this.name = name;
}
public void OnNodeStarting(DateTime startUtc, string image)
public void OnNodeStarting(DateTime startUtc, string image, EthAccount? ethAccount)
{
WriteCodexEvent(startUtc, e =>
{
e.NodeStarting = new NodeStartingEvent
{
Image = image
Image = image,
EthAddress = ethAccount != null ? ethAccount.ToString() : ""
};
});
}
@ -106,6 +108,40 @@ namespace CodexPlugin.OverwatchSupport
});
}
public void OnStorageContractSubmitted(StoragePurchaseContract storagePurchaseContract)
{
WriteCodexEvent(e =>
{
e.StorageContractSubmitted = new StorageContractSubmittedEvent
{
PurchaseId = storagePurchaseContract.PurchaseId,
PurchaseRequest = storagePurchaseContract.Purchase
};
});
}
public void OnStorageContractUpdated(StoragePurchase purchaseStatus)
{
WriteCodexEvent(e =>
{
e.StorageContractUpdated = new StorageContractUpdatedEvent
{
StoragePurchase = purchaseStatus
};
});
}
public void OnStorageAvailabilityCreated(StorageAvailability response)
{
WriteCodexEvent(e =>
{
e.StorageAvailabilityCreated = new StorageAvailabilityCreatedEvent
{
StorageAvailability = response
};
});
}
private void WriteCodexEvent(Action<OverwatchCodexEvent> action)
{
WriteCodexEvent(DateTime.UtcNow, action);

View File

@ -24,6 +24,9 @@ namespace CodexPlugin.OverwatchSupport
public BlockReceivedEvent? BlockReceived { get; set; }
public PeerDialSuccessfulEvent? DialSuccessful { get; set; }
public PeerDroppedEvent? PeerDropped { get; set; }
public StorageContractSubmittedEvent? StorageContractSubmitted { get; set; }
public StorageContractUpdatedEvent? StorageContractUpdated { get; set; }
public StorageAvailabilityCreatedEvent? StorageAvailabilityCreated { get; set; }
public void Write(DateTime utc, ITranscriptWriter writer)
{
@ -68,6 +71,7 @@ namespace CodexPlugin.OverwatchSupport
public class NodeStartingEvent
{
public string Image { get; set; } = string.Empty;
public string EthAddress { get; set; } = string.Empty;
}
[Serializable]
@ -114,6 +118,25 @@ namespace CodexPlugin.OverwatchSupport
public long ByteSize { get; set; }
}
[Serializable]
public class StorageAvailabilityCreatedEvent
{
public StorageAvailability StorageAvailability { get; set; } = null!;
}
[Serializable]
public class StorageContractUpdatedEvent
{
public StoragePurchase StoragePurchase { get; set; } = null!;
}
[Serializable]
public class StorageContractSubmittedEvent
{
public string PurchaseId { get; set; } = string.Empty;
public StoragePurchaseRequest PurchaseRequest { get; set; } = null!;
}
#endregion
#region Codex Generated Events