-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bad4268
commit 27aeaff
Showing
10 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
@using aoww.ProcesModels.Metadata | ||
@using aoww.ProcesModels.SchemaProtocol | ||
@inject SchemaProtocolClient schemaProtocolClient | ||
@inject NavigationManager NavigationManager | ||
|
||
@if (actions != null && actions.Any()) | ||
{ | ||
<MudItem xs="12" sm="6"> | ||
<MudPaper Class="pa-4"> | ||
<MudText Typo="Typo.h6">Schema Protocol Actions</MudText> | ||
<br /> | ||
@if (actions.Any()) | ||
{ | ||
@foreach (var action in actions) | ||
{ | ||
<MudCard> | ||
<MudCardContent> | ||
<MudText>@action.Title</MudText> | ||
<MudText Typo="Typo.body2">@action.Description</MudText> | ||
</MudCardContent> | ||
<MudCardActions> | ||
<MudButton ButtonType="ButtonType.Button" Color="Color.Secondary" OnClick="() => GoToSend(action.AoAction)">@action.Name</MudButton> | ||
</MudCardActions> | ||
</MudCard> | ||
} | ||
} | ||
|
||
</MudPaper> | ||
</MudItem> | ||
} | ||
|
||
|
||
@code { | ||
[Parameter] | ||
public required string ProcessId { get; set; } | ||
|
||
private List<ActionMetadata> actions = new(); | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
actions = new(); | ||
|
||
actions = await schemaProtocolClient.GetSchemaProtocolActions(ProcessId); | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
private void GoToSend(AoAction aoAction) | ||
{ | ||
NavigationManager.NavigateTo($"/action?{aoAction.ToQueryString()}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using aoww.ProcesModels.SchemaProtocol; | ||
using ArweaveAO; | ||
using ArweaveAO.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace aoww.ProcesModels.Tests | ||
{ | ||
[TestClass] | ||
public sealed class SchemaProtocolClientTests | ||
{ | ||
[TestMethod] | ||
public async Task GetActionsTests() | ||
{ | ||
var processId = "ptvbacSmqJPfgCXxPc9bcobs5Th2B_SxTf81vRNkRzk"; | ||
|
||
var client = new SchemaProtocolClient(new AODataClient(Options.Create<ArweaveConfig>(new()), new HttpClient())); | ||
|
||
var result = await client.GetSchemaProtocolActions(processId); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsTrue(result.Any()); | ||
} | ||
|
||
[TestMethod] | ||
public async Task NoActionsTests() | ||
{ | ||
var processId = "YCH7ugqKwIo_bQebG_eT_7QY0sxVXbnv7BTgmRi7FZk"; | ||
|
||
var client = new SchemaProtocolClient(new AODataClient(Options.Create<ArweaveConfig>(new()), new HttpClient())); | ||
|
||
var result = await client.GetSchemaProtocolActions(processId); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsFalse(result.Any()); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/aoww.ProcesModels.Tests/aoww.ProcesModels.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.6.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\aoww.ProcesModels\aoww.ProcesModels.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/aoww.ProcesModels/SchemaProtocol/Extensions/SchemaProtocolExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using aoww.ProcesModels.Action; | ||
using aoww.ProcesModels.Metadata; | ||
using aoww.ProcesModels.SchemaProtocol.Models; | ||
|
||
namespace aoww.ProcesModels.SchemaProtocol.Extensions | ||
{ | ||
public static class SchemaProtocolExtensions | ||
{ | ||
public static ActionMetadata? ToActionMetadata(this KeyValuePair<string, SchemaProtocolActionModel> input, string targetProcessId) | ||
{ | ||
AoAction? aoAction = input.Value.ToAoAction(); | ||
if (aoAction == null) | ||
return null; | ||
|
||
if(!aoAction.Params.Where(x => x.ParamType == ActionParamType.Target).Any()) | ||
aoAction.Params.Add(new ActionParam() { Key = "Target", Value = targetProcessId, ParamType = ActionParamType.Target }); | ||
|
||
ActionMetadata result = new ActionMetadata | ||
{ | ||
Name = input.Key, | ||
Title = input.Value.Title, | ||
Description = input.Value.Description, | ||
ActionType = ActionType.Message, | ||
AoAction = aoAction | ||
}; | ||
|
||
|
||
return result; | ||
} | ||
|
||
public static AoAction? ToAoAction(this SchemaProtocolActionModel input) | ||
{ | ||
var props = input?.Schema?.Tags?.Properties; | ||
if (props == null) | ||
return null; | ||
|
||
List<ActionParam> paramList = props.Select(x => x.ToParams()) | ||
.Where(x => x != null) | ||
.Select(x => x!).ToList(); | ||
|
||
AoAction result = new AoAction | ||
{ | ||
Params = paramList | ||
}; | ||
|
||
|
||
return result; | ||
} | ||
|
||
public static ActionParam? ToParams(this KeyValuePair<string, SchemaProtocolPropertyModel> input) | ||
{ | ||
ActionParam result = new ActionParam | ||
{ | ||
Key = input.Key, | ||
Value = input.Value.Const, | ||
ParamType = ActionParamType.Input | ||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(result.Value)) | ||
result.ParamType = ActionParamType.Filled; | ||
else if(input.Value.Type == "integer") | ||
result.ParamType = ActionParamType.Integer; | ||
|
||
|
||
return result; | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/aoww.ProcesModels/SchemaProtocol/Models/SchemaProtocolModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace aoww.ProcesModels.SchemaProtocol.Models | ||
{ | ||
public class SchemaProtocolModel : Dictionary<string, SchemaProtocolActionModel> | ||
{ | ||
|
||
|
||
} | ||
|
||
public class SchemaProtocolActionModel | ||
{ | ||
[JsonPropertyName("Title")] | ||
public string? Title { get; set; } | ||
|
||
[JsonPropertyName("Description")] | ||
public string? Description { get; set; } | ||
|
||
[JsonPropertyName("Schema")] | ||
public SchemaProtocolSchemaModel? Schema { get; set; } | ||
|
||
|
||
} | ||
|
||
public class SchemaProtocolSchemaModel | ||
{ | ||
[JsonPropertyName("Tags")] | ||
public SchemaProtocolTagsModel? Tags { get; set; } | ||
|
||
//[JsonPropertyName("Data")] | ||
//public string? Data { get; set; } | ||
|
||
} | ||
|
||
|
||
|
||
public class SchemaProtocolTagsModel | ||
{ | ||
[JsonPropertyName("type")] | ||
public string? Type { get; set; } | ||
|
||
[JsonPropertyName("required")] | ||
public List<string> Required { get; set; } = new(); | ||
|
||
[JsonPropertyName("properties")] | ||
public Dictionary<string, SchemaProtocolPropertyModel> Properties { get; set; } = new(); | ||
} | ||
|
||
public class SchemaProtocolPropertyModel | ||
{ | ||
[JsonPropertyName("type")] | ||
public string? Type { get; set; } | ||
|
||
[JsonPropertyName("const")] | ||
public string? Const { get; set; } | ||
|
||
[JsonPropertyName("title")] | ||
public string? Title { get; set; } | ||
|
||
[JsonPropertyName("description")] | ||
public string? Description { get; set; } | ||
|
||
[JsonPropertyName("minimum")] | ||
public int? Minimum { get; set; } | ||
|
||
[JsonPropertyName("maximum")] | ||
public int? Maximum { get; set; } | ||
|
||
[JsonPropertyName("$comment")] | ||
public string? Comment { get; set; } | ||
|
||
[JsonPropertyName("maxLength")] | ||
public int? MaxLength { get; set; } | ||
|
||
public List<string>? Enum { get; set; } | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/aoww.ProcesModels/SchemaProtocol/SchemaProtocolClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using aoww.ProcesModels.Metadata; | ||
using aoww.ProcesModels.SchemaProtocol.Extensions; | ||
using aoww.ProcesModels.SchemaProtocol.Models; | ||
using ArweaveAO; | ||
using ArweaveAO.Extensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace aoww.ProcesModels.SchemaProtocol | ||
{ | ||
public class SchemaProtocolClient(AODataClient aoDataClient) | ||
{ | ||
public async Task<List<ActionMetadata>> GetSchemaProtocolActions(string processId) | ||
{ | ||
try | ||
{ | ||
var result = await aoDataClient.DryRun(processId, new ArweaveAO.Requests.DryRunRequest | ||
{ | ||
Target = processId, | ||
Tags = new List<ArweaveAO.Models.Tag> | ||
{ | ||
new ArweaveAO.Models.Tag() { Name = "Action", Value = "Schema" } | ||
} | ||
}); | ||
|
||
var data = result?.GetFirstDataValue(); | ||
|
||
if (data != null) | ||
{ | ||
var model = System.Text.Json.JsonSerializer.Deserialize<SchemaProtocolModel>(data); | ||
|
||
if (model != null) | ||
{ | ||
List<ActionMetadata> actionList = model.Select(x => x.ToActionMetadata(processId)).Where(x => x != null).Select(x => x!).ToList(); | ||
return actionList; | ||
} | ||
} | ||
} | ||
catch { } | ||
|
||
return new(); | ||
} | ||
} | ||
} |