Skip to content

Commit

Permalink
refactor(dotnet): move all dotnet conversions to Algorand.Unity.Net
Browse files Browse the repository at this point in the history
this enforces that `Algorand.Unity.Net` can't be used in WebGL

BREAKING CHANGE: Removed all explicit/implicit operators to convert Algorand.Unity types to Algorand
types. All conversions now can be done with `ToUnity` and `ToDotnet` extension methods by
referencing the `Algorand.Unity.Net` assembly.
  • Loading branch information
jasonboukheir committed Dec 10, 2022
1 parent 345a52a commit b0f7124
Show file tree
Hide file tree
Showing 43 changed files with 2,901 additions and 1,903 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Runtime/Algorand.Unity.Net/Algorand.Unity.Net.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Algorand.Unity.Net",
"rootNamespace": "Algorand.Unity.Net",
"references": [
"GUID:45ab5c0c2cb4a0e4ba897b731349c490",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:9f8c967ec86c9324c9b2928ff73b4cf1"
],
"includePlatforms": [],
"excludePlatforms": [
"WebGL"
],
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"Algorand_1.0.0.14.dll",
"BouncyCastle.Crypto_1.8.8.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Runtime/Algorand.Unity.Net/Algorand.Unity.Net.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Runtime/Algorand.Unity.Net/Extensions/AddressExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Algorand.Unity.Net
{
public static class AddressExtensions
{
public static Algorand.Address ToDotnet(this Address from)
{
return new Algorand.Address(from);
}

public static Address ToUnity(this Algorand.Address from)
{
return from.EncodeAsString();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;

namespace Algorand.Unity.Net
{
public static class AlgoApiClientExtensions
{
public static UnityHttpClient ToHttpClient<T>(this T client)
where T : IAlgoApiClient
{
var timeout = System.Threading.Timeout.InfiniteTimeSpan;
return client.ToHttpClient(timeout);
}

public static UnityHttpClient ToHttpClient<T>(this T client, TimeSpan timeout)
where T : IAlgoApiClient
{
var address = client.Address;
(string headers, string value)[] headers;
if (client.Headers == null)
{
if (string.IsNullOrEmpty(client.Token))
{
return new UnityHttpClient(address, timeout);
}

headers = new (string headers, string value)[1];
headers[0] = (client.TokenHeader, client.Token);
return new UnityHttpClient(address, timeout, headers);
}

if (string.IsNullOrEmpty(client.Token))
{
headers = new (string headers, string value)[client.Headers.Length];
for (var i = 0; i < headers.Length; i++)
headers[i] = client.Headers[i];
return new UnityHttpClient(address, timeout, headers);
}

headers = new (string headers, string value)[client.Headers.Length + 1];
for (var i = 0; i < client.Headers.Length; i++)
headers[i] = client.Headers[i];
headers[client.Headers.Length] = (client.TokenHeader, client.Token);
return new UnityHttpClient(address, timeout, headers);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Algorand.Algod;

namespace Algorand.Unity.Net
{
public static class AlgodClientExtensions
{
/// <summary>
/// Convert <see cref="AlgodClient"/> to the Algorand2 <see cref="CommonApi"/>.
/// </summary>
/// <param name="algod">The Unity Serializable <see cref="AlgodClient"/>.</param>
/// <returns>An Algorand2 <see cref="CommonApi"/></returns>
public static CommonApi ToCommonApi(this AlgodClient algod)
{
return new CommonApi(algod.ToHttpClient());
}

/// <summary>
/// Convert <see cref="AlgodClient"/> to the Algorand2 <see cref="DefaultApi"/>.
/// </summary>
/// <param name="algod">The Unity Serializable <see cref="AlgodClient"/>.</param>
/// <returns>An Algorand2 <see cref="DefaultApi"/></returns>
public static DefaultApi ToDefaultApi(this AlgodClient algod)
{
return new DefaultApi(algod.ToHttpClient());
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Algorand.Indexer;

namespace Algorand.Unity.Net
{
public static class IndexerClientExtensions
{
public static CommonApi ToCommonApi(this IndexerClient indexer)
{
return new CommonApi(indexer.ToHttpClient());
}

public static SearchApi ToSearchApi(this IndexerClient indexer)
{
return new SearchApi(indexer.ToHttpClient());
}

public static LookupApi ToLookupApi(this IndexerClient indexer)
{
return new LookupApi(indexer.ToHttpClient());
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Runtime/Algorand.Unity.Net/Extensions/CompiledTealExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Algorand.Unity.Net
{
public static class CompiledTealExtensions
{
public static TEALProgram ToDotnet(this CompiledTeal from)
{
return new TEALProgram(from.Bytes);
}

public static CompiledTeal ToUnity(this TEALProgram from)
{
return from.Bytes;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b0f7124

Please sign in to comment.