Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
1.1 Update
Browse files Browse the repository at this point in the history
- Updated token definition to support animations
- Updated token definition to support attributes
- Deprecated token definition properties ... should use attributes and animations now
  • Loading branch information
LodenDarkStar committed May 21, 2021
1 parent 00b470d commit b0fd74f
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 149 deletions.
67 changes: 57 additions & 10 deletions Package/Editor/EditorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ public static IEnumerator SyncSettings(Action callback = null)
{
var settings = BGSDKSettings.current;

//Remove any nulls
settings.contracts.RemoveAll(p => p == null);
foreach(var contract in settings.contracts)
{
contract.tokens.RemoveAll(p => p == null);
}

var authenticated = false;

WWWForm authForm = new WWWForm();
Expand Down Expand Up @@ -558,17 +565,37 @@ public static IEnumerator SyncSettings(Action callback = null)

foreach (var token in newTokens)
{
yield return CreateTokenType(arkaneContract, token, (result) =>
yield return null;

if (string.IsNullOrEmpty(BGSDKSettings.current.appId.clientSecret) || string.IsNullOrEmpty(BGSDKSettings.current.appId.clientId))
{
Debug.LogError("Failed to sync settings: you must populate the Client ID and Client Secret before you can sync settings.");
yield return null;
}
else if (string.IsNullOrEmpty(token.SystemName))
{
Debug.LogError("Failed to create token [" + token.SystemName + "] for contract [" + arkaneContract.SystemName + "], message: name required, null or empty name provided.");
yield return null;
}
else
{
if(result.hasError)
var request = new UnityWebRequest(BGSDKSettings.current.DefineTokenTypeUri(arkaneContract), "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(token.CreateTokenDefitionJson());
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Authorization", BGSDKSettings.user.authentication.token_type + " " + BGSDKSettings.user.authentication.access_token);
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();

if (!request.isNetworkError && !request.isHttpError)
{
Debug.LogError("Failed to create token [" + token.SystemName + "] for contract [" + arkaneContract.SystemName + "], error: " + result.httpCode + " message: " + result.message);
Debug.Log("Created token [" + token.SystemName + "] for contract [" + arkaneContract.SystemName + "]");
}
else
{
Debug.Log("Created token [" + token.SystemName + "] for contract [" + arkaneContract.SystemName + "]");
Debug.LogError("Failed to create token [" + token.SystemName + "] for contract [" + arkaneContract.SystemName + "], error: " + request.responseCode + " message: " + "Error:" + (request.isNetworkError ? " a network error occured while attempting to define the token type." : " a HTTP error occured while attempting to define the token type."));
}
});
}
}
#endregion
}
Expand Down Expand Up @@ -618,17 +645,37 @@ public static IEnumerator SyncSettings(Action callback = null)
**********************************************************************************/
foreach (var token in contract.tokens)
{
yield return CreateTokenType(contract, token, (r) =>
yield return null;

if (string.IsNullOrEmpty(BGSDKSettings.current.appId.clientSecret) || string.IsNullOrEmpty(BGSDKSettings.current.appId.clientId))
{
Debug.LogError("Failed to sync settings: you must populate the Client ID and Client Secret before you can sync settings.");
yield return null;
}
else if (string.IsNullOrEmpty(token.SystemName))
{
Debug.LogError("Failed to create token [" + token.SystemName + "] for contract [" + contract.SystemName + "], message: name required, null or empty name provided.");
yield return null;
}
else
{
if (r.hasError)
var request = new UnityWebRequest(BGSDKSettings.current.DefineTokenTypeUri(contract), "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(token.CreateTokenDefitionJson());
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Authorization", BGSDKSettings.user.authentication.token_type + " " + BGSDKSettings.user.authentication.access_token);
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();

if (!request.isNetworkError && !request.isHttpError)
{
Debug.LogError("Failed to create token [" + token.SystemName + "] for contract [" + contract.SystemName + "], error: " + r.httpCode + " message: " + r.message);
Debug.Log("Created token [" + token.SystemName + "] for contract [" + contract.SystemName + "]");
}
else
{
Debug.Log("Created token [" + token.SystemName + "] for contract [" + contract.SystemName + "]");
Debug.LogError("Failed to create token [" + token.SystemName + "] for contract [" + contract.SystemName + "], error: " + request.responseCode + " message: " + "Error:" + (request.isNetworkError ? " a network error occured while attempting to define the token type." : " a HTTP error occured while attempting to define the token type."));
}
});
}
}
}
else
Expand Down
12 changes: 12 additions & 0 deletions Package/Runtime/DataModel/TokenAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace HeathenEngineering.BGSDK.DataModel
{
[Serializable]
public struct TokenAttributes
{
public string name;
public string type;
public string value;
}
}

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

15 changes: 9 additions & 6 deletions Package/Runtime/DataModel/TokenDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace HeathenEngineering.BGSDK.DataModel
{

[Serializable]
public class TokenDefinition
{
Expand All @@ -21,11 +22,10 @@ public class TokenDefinition
/// </summary>
[Tooltip("Only applicable in case of a fungible token, this indicates the number of decimals the fungible token has")]
public uint decimals;
/// <summary>
/// Flag that indicates if this type is a non-fungible (true for non-fungible, false for fungible)
/// </summary>
[Tooltip("Flag that indicates if this type is a non-fungible (true for non-fungible, false for fungible)")]
public bool nft;
public ulong currentSupply;
public bool fungible;
public bool burnable;

/// <summary>
/// The backgroundcolor of the image
/// </summary>
Expand All @@ -35,7 +35,7 @@ public class TokenDefinition
/// The URL with more information about the token
/// </summary>
[Tooltip("The URL with more information about the token")]
public string url;
public string externalUrl;
/// <summary>
/// Image url of the token, 250x250, preferably svg
/// </summary>
Expand All @@ -52,6 +52,9 @@ public class TokenDefinition
[Tooltip("Image url of the token, 2000x2000, preferably svg")]
public string image;

public TypeValuePair[] animationUrls;
public TokenAttributes[] attributes;

public virtual string ToJson()
{
return JsonUtility.ToJson(this);
Expand Down
19 changes: 13 additions & 6 deletions Package/Runtime/Engine/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class ResultList : BGSDKBaseResult

public Contract contract;

[Obsolete("No longer used")]
[HideInInspector]
public TokeProperties properties;

public string Id
Expand Down Expand Up @@ -131,13 +133,13 @@ public bool IsNonFungible
{
get
{
return data != null ? data.nft : false;
return data != null ? !data.fungible : false;
}
set
{
if (data == null)
data = new TokenResponceData();
data.nft = value;
data.fungible = !value;
}
}
public string BackgroundColor
Expand All @@ -157,13 +159,13 @@ public string Url
{
get
{
return data == null ? "" : data.url;
return data == null ? "" : data.externalUrl;
}
set
{
if (data == null)
data = new TokenResponceData();
data.url = value;
data.externalUrl = value;
}
}
public string ImagePreview
Expand Down Expand Up @@ -214,6 +216,7 @@ public void Set(WebResults<TokenResponceData> webResults)
data = webResults.result;
}

[Obsolete("No longer used")]
public void Set<T>(WebResults<TokenResponceData<T>> webResults)
{
data = webResults.result;
Expand All @@ -225,6 +228,7 @@ public void Set<T>(WebResults<TokenResponceData<T>> webResults)
}
}

[Obsolete("No longer used")]
public T GetProperties<T>()
{
if (properties != null && properties.DataType == typeof(T))
Expand All @@ -241,6 +245,7 @@ public TokenDefinition GetTokenDefinition()
return data;
}

[Obsolete("No longer used")]
public TokenDefinition<T> GetTokenDefinition<T>()
{
TokenProperties<T> prop = null;
Expand All @@ -254,9 +259,9 @@ public TokenDefinition<T> GetTokenDefinition<T>()
name = data.name,
description = data.description,
decimals = data.decimals,
nft = data.nft,
fungible = data.fungible,
backgroundColor = data.backgroundColor,
url = data.url,
externalUrl = data.externalUrl,
imagePreview = data.imagePreview,
imageThumbnail = data.imageThumbnail,
image = data.image,
Expand Down Expand Up @@ -325,8 +330,10 @@ public IEnumerator Get(Action<ResultList> callback)
#if UNITY_EDITOR
public string CreateTokenDefitionJson()
{
#pragma warning disable CS0618 // Type or member is obsolete
if (properties != null)
return properties.ToJsonDef(data);
#pragma warning restore CS0618 // Type or member is obsolete
else
return data.ToJson();
}
Expand Down
9 changes: 5 additions & 4 deletions Package/Samples~/Demo/420 Test It Contract.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ MonoBehaviour:
m_Name: 420 Test It Contract
m_EditorClassIdentifier:
updatedFromServer: 1
updatedOn: -8585814649855800621
updatedOn: -8585800147389801052
data:
id: 188
name: 420 Test It Contract
description: A simple test
confirmed: 1
secretType: MATIC
address: 0xa37bebcd3ec7dcf3644a9c2c2a3c9a65179761c8
symbol:
url:
imageUrl:
type:
externalUrl:
image:
media: []
tokens: []
2 changes: 1 addition & 1 deletion Package/Samples~/Demo/BGSDK Settings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ MonoBehaviour:
imageUrl:
contracts:
- {fileID: 11400000, guid: df39c7d29288ccb449a2afa7385f9e7d, type: 2}
- {fileID: 11400000, guid: 1b2ea982fb964e8429dec82c2929dd27, type: 2}
- {fileID: 11400000, guid: 924374510d55f15429107adb1d2d841a, type: 2}
- {fileID: 11400000, guid: 2245fde78bf0bf948b977bcb8ee59d67, type: 2}
- {fileID: 11400000, guid: 1b2ea982fb964e8429dec82c2929dd27, type: 2}
- {fileID: 11400000, guid: 66126d82201639447a35b5519cf06143, type: 2}
19 changes: 0 additions & 19 deletions Package/Samples~/Demo/Example Properties Object.asset

This file was deleted.

60 changes: 0 additions & 60 deletions Package/Samples~/Demo/ExampleTokenProperties.cs

This file was deleted.

9 changes: 5 additions & 4 deletions Package/Samples~/Demo/Kaiden Contract.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ MonoBehaviour:
m_Name: Kaiden Contract
m_EditorClassIdentifier:
updatedFromServer: 1
updatedOn: -8585814649846249704
updatedOn: -8585800147379681814
data:
id: 171
name: Kaiden Contract
description:
confirmed: 1
secretType: MATIC
address: 0x2dc1049f2bed2ff4e163054831e1aad8932a7c21
symbol:
url:
imageUrl:
type:
externalUrl:
image:
media: []
tokens: []
Loading

0 comments on commit b0fd74f

Please sign in to comment.