-
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.
Merge pull request #5 from michielpost/feature/milestone-01
[WIP] Milestone 01
- Loading branch information
Showing
78 changed files
with
3,775 additions
and
1,356 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using aoWebWallet.Models; | ||
using aoWebWallet.Services; | ||
using ArweaveAO; | ||
using ArweaveAO.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace aoWebWallet.Tests | ||
{ | ||
[TestClass] | ||
public class StorageServiceTests | ||
{ | ||
[TestMethod] | ||
public async Task TestBuildInTokenData() | ||
{ | ||
List<Token> result = new(); | ||
|
||
StorageService.AddSystemTokens(result); | ||
|
||
TokenClient tokenClient = new TokenClient(Options.Create(new ArweaveConfig()), new HttpClient()); | ||
|
||
foreach(var token in result) | ||
{ | ||
//Get live data | ||
var data = await tokenClient.GetTokenMetaData(token.TokenId); | ||
|
||
Assert.IsNotNull(token.TokenData); | ||
Assert.IsNotNull(data); | ||
|
||
Assert.AreEqual(token.TokenId, data.TokenId); | ||
Assert.AreEqual(token.TokenData.TokenId, data.TokenId); | ||
Assert.AreEqual(token.TokenData.Name, data.Name); | ||
Assert.AreEqual(token.TokenData.Ticker, data.Ticker); | ||
Assert.AreEqual(token.TokenData.Denomination, data.Denomination); | ||
Assert.AreEqual(token.TokenData.Logo, data.Logo); | ||
|
||
} | ||
} | ||
} | ||
} |
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,30 @@ | ||
<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.9.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\aoWebWallet\aoWebWallet.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
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,17 @@ | ||
using aoWebWallet.Models; | ||
|
||
namespace aoWebWallet.Extensions | ||
{ | ||
public static class WalletExtensions | ||
{ | ||
public static string ToAutocompleteDisplay(this Wallet wallet) | ||
{ | ||
if (string.IsNullOrWhiteSpace(wallet.Name)) | ||
{ | ||
return wallet.Address; | ||
} | ||
|
||
return $"{wallet.Name} ({wallet.Address})"; | ||
} | ||
} | ||
} |
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,178 @@ | ||
| ||
using System.Text; | ||
|
||
namespace aoWebWallet.Models | ||
{ | ||
public class AoAction | ||
{ | ||
public List<ActionParam> Params { get; set; } = new(); | ||
|
||
public ActionParam? Target => Params.Where(x => x.ParamType == ActionParamType.Target).FirstOrDefault(); | ||
public IEnumerable<ActionParam> AllWithoutTarget => Params.Where(x => x.ParamType != ActionParamType.Target); | ||
public IEnumerable<ActionParam> Filled => Params.Where(x => x.ParamType == ActionParamType.Filled); | ||
public IEnumerable<ActionParam> AllInputs => Params.Where(x => | ||
x.ParamType != ActionParamType.Filled | ||
&& x.ParamType != ActionParamType.Target); | ||
|
||
public string? IsValid() | ||
{ | ||
if (Target == null) | ||
return "No Target process specified."; | ||
|
||
foreach(var input in AllInputs) | ||
{ | ||
if (string.IsNullOrEmpty(input.Value)) | ||
return $"Please enter a value for {input.Key}"; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public List<ArweaveBlazor.Models.Tag> ToEvalTags() | ||
{ | ||
return Params.Select(x => new ArweaveBlazor.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); | ||
} | ||
|
||
public List<ArweaveBlazor.Models.Tag> ToTags() | ||
{ | ||
return AllWithoutTarget.Select(x => new ArweaveBlazor.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); | ||
} | ||
|
||
public List<ArweaveAO.Models.Tag> ToDryRunTags() | ||
{ | ||
return AllWithoutTarget.Select(x => new ArweaveAO.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); | ||
} | ||
|
||
|
||
public string ToQueryString() | ||
{ | ||
if (Target == null) | ||
return string.Empty; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.Append($"{Target.Key}={Target.Value}&"); | ||
|
||
foreach (var param in this.Filled) | ||
{ | ||
sb.Append($"{param.Key}={param.Value}&"); | ||
} | ||
|
||
foreach (var param in this.AllInputs) | ||
{ | ||
var args = string.Join(';', param.Args); | ||
if (args.Length > 0) | ||
{ | ||
sb.Append($"X-{param.ParamType}={param.Key};{args}&"); | ||
} | ||
else | ||
{ | ||
sb.Append($"X-{param.ParamType}={param.Key}&"); | ||
} | ||
} | ||
|
||
return sb.ToString().TrimEnd('&'); | ||
} | ||
|
||
public static AoAction CreateFromQueryString(string qstring) | ||
{ | ||
// Parsing query string | ||
var queryStringValues = System.Web.HttpUtility.ParseQueryString(qstring); | ||
|
||
AoAction action = new AoAction(); | ||
|
||
foreach (var key in queryStringValues.AllKeys) | ||
{ | ||
if (key == null) | ||
continue; | ||
|
||
var values = queryStringValues.GetValues(key); | ||
if (values == null || !values.Any()) | ||
continue; | ||
|
||
foreach (var val in values) | ||
{ | ||
string actionKey = key; | ||
string? actionValue = val.ToString(); | ||
ActionParamType actionParamType = ActionParamType.Filled; | ||
|
||
var actionValueSplit = actionValue.Split(';', StringSplitOptions.RemoveEmptyEntries); | ||
actionValue = actionValueSplit.First(); | ||
List<string> args = actionValueSplit.Skip(1).ToList(); | ||
|
||
if (key.Equals("Target", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Target; | ||
if (key.Equals("X-Quantity", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Quantity; | ||
if (key.Equals("X-Balance", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Balance; | ||
else if (key.Equals("X-Process", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Process; | ||
else if (key.Equals("X-Integer", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Integer; | ||
else if (key.Equals("X-Input", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Input; | ||
|
||
if (actionParamType != ActionParamType.Filled | ||
&& actionParamType != ActionParamType.Target) | ||
{ | ||
actionKey = actionValue; | ||
actionValue = null; | ||
} | ||
|
||
action.Params.Add(new ActionParam | ||
{ | ||
Key = actionKey, | ||
Value = actionValue, | ||
Args = args, | ||
ParamType = actionParamType | ||
}); | ||
|
||
} | ||
} | ||
|
||
return action; | ||
} | ||
|
||
public static AoAction CreateForTokenTransaction(string tokenId) | ||
{ | ||
return new AoAction | ||
{ | ||
Params = new List<ActionParam> | ||
{ | ||
new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= tokenId }, | ||
new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Transfer" }, | ||
new ActionParam { Key= "Recipient", ParamType = ActionParamType.Process }, | ||
new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List<string> { tokenId } } | ||
} | ||
|
||
}; | ||
} | ||
} | ||
|
||
public class ActionParam | ||
{ | ||
public required string Key { get; set; } | ||
public string? Value { get; set; } | ||
|
||
/// <summary> | ||
/// Arguments (like TokenId) | ||
/// </summary> | ||
public List<string> Args { get; set; } = new(); | ||
|
||
public ActionParamType ParamType { get; set; } | ||
|
||
} | ||
|
||
public enum ActionParamType | ||
{ | ||
None = 0, | ||
Target, | ||
Filled, | ||
Input, | ||
Integer, | ||
Process, | ||
Balance, //Arg1: TokenId //Must have balance | ||
Quantity, //Arg1: TokenId //Does not care about balance | ||
} | ||
} |
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,7 @@ | ||
namespace aoWebWallet.Models | ||
{ | ||
public class GatewayConfig | ||
{ | ||
public string GatewayUrl { get; set; } = "https://arweave.net"; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/aoWebWallet/ViewModels/Transaction.cs → src/aoWebWallet/Models/Transaction.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace aoWebWallet.ViewModels | ||
namespace aoWebWallet.Models | ||
{ | ||
public class Transaction | ||
{ | ||
|
Oops, something went wrong.