diff --git a/Samples~/CreatingAsas/TestNetAlgod.asset.meta b/Editor/Algorand.Unity.Editor/Editors.meta similarity index 52% rename from Samples~/CreatingAsas/TestNetAlgod.asset.meta rename to Editor/Algorand.Unity.Editor/Editors.meta index b88a15afa..b1f0b5e13 100644 --- a/Samples~/CreatingAsas/TestNetAlgod.asset.meta +++ b/Editor/Algorand.Unity.Editor/Editors.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: af39a1e2718154e34a8083b85fa44b8d -NativeFormatImporter: +guid: 826fead05f4ae430c932e30dfbfa10d0 +folderAsset: yes +DefaultImporter: externalObjects: {} - mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/Samples~/CreatingAsas/Editor/AssetObjectEditor.cs b/Editor/Algorand.Unity.Editor/Editors/AlgorandStandardAssetEditor.cs similarity index 57% rename from Samples~/CreatingAsas/Editor/AssetObjectEditor.cs rename to Editor/Algorand.Unity.Editor/Editors/AlgorandStandardAssetEditor.cs index 9b8c48090..4111c1d5f 100644 --- a/Samples~/CreatingAsas/Editor/AssetObjectEditor.cs +++ b/Editor/Algorand.Unity.Editor/Editors/AlgorandStandardAssetEditor.cs @@ -1,17 +1,17 @@ using UnityEditor; using UnityEngine; -namespace Algorand.Unity.Samples.CreatingAsas.Editor +namespace Algorand.Unity.Editor { - [CustomEditor(typeof(AssetObject))] - public class AssetObjectEditor : UnityEditor.Editor + [CustomEditor(typeof(AlgorandStandardAsset))] + public class AlgorandStandardAssetEditor : UnityEditor.Editor { public override void OnInspectorGUI() { base.OnInspectorGUI(); - var assetObject = (AssetObject)serializedObject.targetObject; - if (assetObject.Index == 0) + var assetObject = (AlgorandStandardAsset)serializedObject.targetObject; + if (assetObject.index == 0) { EditorGUILayout.Space(); if (GUILayout.Button("Create Asset")) @@ -21,4 +21,4 @@ public override void OnInspectorGUI() } } } -} \ No newline at end of file +} diff --git a/Samples~/CreatingAsas/Runtime/AlgodClientObject.cs.meta b/Editor/Algorand.Unity.Editor/Editors/AlgorandStandardAssetEditor.cs.meta similarity index 83% rename from Samples~/CreatingAsas/Runtime/AlgodClientObject.cs.meta rename to Editor/Algorand.Unity.Editor/Editors/AlgorandStandardAssetEditor.cs.meta index bdda79cd8..05028ea32 100644 --- a/Samples~/CreatingAsas/Runtime/AlgodClientObject.cs.meta +++ b/Editor/Algorand.Unity.Editor/Editors/AlgorandStandardAssetEditor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1b18fa56602714cbf9292caea3984246 +guid: d7f569af3e0084ebbb962cebfb46b9b1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Samples~/CreatingAsas/Editor/AssetCreateWindow.cs b/Editor/Algorand.Unity.Editor/Editors/AssetCreateWindow.cs similarity index 75% rename from Samples~/CreatingAsas/Editor/AssetCreateWindow.cs rename to Editor/Algorand.Unity.Editor/Editors/AssetCreateWindow.cs index 63652a686..111284e2e 100644 --- a/Samples~/CreatingAsas/Editor/AssetCreateWindow.cs +++ b/Editor/Algorand.Unity.Editor/Editors/AssetCreateWindow.cs @@ -5,17 +5,17 @@ using UnityEngine; using UnityEngine.UIElements; -namespace Algorand.Unity.Samples.CreatingAsas.Editor +namespace Algorand.Unity.Editor { public class AssetCreateWindow : EditorWindow { - [SerializeField] private AssetObject asset; + public AlgorandStandardAsset asset; - [SerializeField] private AccountObject creatorAccount; + public AccountAsset creatorAccount; - [SerializeField] private AlgodClientObject algod; + public AlgodClientAsset algod; - public static void Show(AssetObject asset) + public static void Show(AlgorandStandardAsset asset) { var window = GetWindow("Create ASA"); window.asset = asset; @@ -50,12 +50,12 @@ private async UniTaskVoid CreateAsaAsync() throw new ArgumentNullException(nameof(algod)); // check algod health - var healthResponse = await algod.Client.HealthCheck(); + var healthResponse = await algod.client.HealthCheck(); if (healthResponse.Error) throw new Exception($"Algod health check failed: {healthResponse.Error}"); // get txn params - var (txnParamsErr, txnParams) = await algod.Client.TransactionParams(); + var (txnParamsErr, txnParams) = await algod.client.TransactionParams(); if (txnParamsErr) throw new Exception(txnParamsErr); @@ -63,26 +63,27 @@ private async UniTaskVoid CreateAsaAsync() var txn = Transaction.AssetCreate( sender: creatorAccount.Address, txnParams: txnParams, - assetParams: asset.Params + assetParams: asset.assetParams ); - var signedTxn = creatorAccount.SignTxn(txn); + var txns = new AssetConfigTxn[] { txn }; + var signedTxns = await creatorAccount.SignTxnsAsync(txns, TxnIndices.All); // send the transaction - var (submitTxnErr, txnId) = await algod.Client.SendTransaction(signedTxn); + var (submitTxnErr, txnId) = await algod.client.SendTransaction(signedTxns[0]); if (submitTxnErr) throw new Exception(submitTxnErr); Debug.Log($"Submitted txn with id: {txnId.TxId}"); // wait for confirmation - var (txnConfirmErr, confirmedTxn) = await algod.Client.WaitForConfirmation(txnId.TxId); + var (txnConfirmErr, confirmedTxn) = await algod.client.WaitForConfirmation(txnId.TxId); if (txnConfirmErr) throw new Exception(txnConfirmErr); // Apply index and network to the ASA var serializedObject = new SerializedObject(asset); serializedObject.Update(); - asset.Index = confirmedTxn.AssetIndex.Value; - asset.Network = algod.Network; + asset.index = confirmedTxn.AssetIndex.Value; + asset.network = algod.network; serializedObject.ApplyModifiedPropertiesWithoutUndo(); Debug.Log("Asset Created!"); diff --git a/Samples~/CreatingAsas/Editor/AssetCreateWindow.cs.meta b/Editor/Algorand.Unity.Editor/Editors/AssetCreateWindow.cs.meta similarity index 83% rename from Samples~/CreatingAsas/Editor/AssetCreateWindow.cs.meta rename to Editor/Algorand.Unity.Editor/Editors/AssetCreateWindow.cs.meta index ba12730bd..3ccb2fa50 100644 --- a/Samples~/CreatingAsas/Editor/AssetCreateWindow.cs.meta +++ b/Editor/Algorand.Unity.Editor/Editors/AssetCreateWindow.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7eee0865f34834ac997941c9fc058db3 +guid: 42ddf656beea44dc1bbc0560c242f03d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Algorand.Unity/AlgorandStandardAssets/AlgorandStandardAsset.cs b/Runtime/Algorand.Unity/AlgorandStandardAssets/AlgorandStandardAsset.cs new file mode 100644 index 000000000..448bf52ec --- /dev/null +++ b/Runtime/Algorand.Unity/AlgorandStandardAssets/AlgorandStandardAsset.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace Algorand.Unity +{ + [HelpURL(DocUrl.Api + "Algorand.Unity.AlgorandStandardAsset.html")] + [CreateAssetMenu(menuName = "Algorand/ASA")] + public class AlgorandStandardAsset : ScriptableObject + { + public AssetIndex index; + public AlgorandNetwork network; + public AssetParams assetParams; + } +} diff --git a/Samples~/CreatingAsas/Runtime/AssetObject.cs.meta b/Runtime/Algorand.Unity/AlgorandStandardAssets/AlgorandStandardAsset.cs.meta similarity index 83% rename from Samples~/CreatingAsas/Runtime/AssetObject.cs.meta rename to Runtime/Algorand.Unity/AlgorandStandardAssets/AlgorandStandardAsset.cs.meta index cf27fe65e..af1f8cc80 100644 --- a/Samples~/CreatingAsas/Runtime/AssetObject.cs.meta +++ b/Runtime/Algorand.Unity/AlgorandStandardAssets/AlgorandStandardAsset.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 05e26971ff71046669b85452782df82d +guid: 94a78558742ae4d1180896214d3a5bbb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Samples~/CreatingAsas/Editor/AssetObjectEditor.cs.meta b/Samples~/CreatingAsas/Editor/AssetObjectEditor.cs.meta deleted file mode 100644 index 8c05e64b7..000000000 --- a/Samples~/CreatingAsas/Editor/AssetObjectEditor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6190dd8f39f5545dfaf3dedc55558df2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Samples~/CreatingAsas/Editor/AccountObjectEditor.cs b/Samples~/CreatingAsas/Editor/UnsafeAccountAssetEditor.cs similarity index 88% rename from Samples~/CreatingAsas/Editor/AccountObjectEditor.cs rename to Samples~/CreatingAsas/Editor/UnsafeAccountAssetEditor.cs index a5eb932c6..b6b40004f 100644 --- a/Samples~/CreatingAsas/Editor/AccountObjectEditor.cs +++ b/Samples~/CreatingAsas/Editor/UnsafeAccountAssetEditor.cs @@ -3,7 +3,7 @@ namespace Algorand.Unity.Samples.CreatingAsas.Editor { - [CustomEditor(typeof(AccountObject))] + [CustomEditor(typeof(UnsafeAccountAsset))] public class AccountObjectEditor : UnityEditor.Editor { public override void OnInspectorGUI() @@ -12,7 +12,7 @@ public override void OnInspectorGUI() "This asset should only be used for sample purposes. Storing private keys in an asset is not safe for production.", MessageType.Warning); DrawDefaultInspector(); - var accountObject = (AccountObject)serializedObject.targetObject; + var accountObject = (UnsafeAccountAsset)serializedObject.targetObject; using (new GUILayout.HorizontalScope()) { if (GUILayout.Button("Generate new Account")) diff --git a/Samples~/CreatingAsas/Editor/AccountObjectEditor.cs.meta b/Samples~/CreatingAsas/Editor/UnsafeAccountAssetEditor.cs.meta similarity index 100% rename from Samples~/CreatingAsas/Editor/AccountObjectEditor.cs.meta rename to Samples~/CreatingAsas/Editor/UnsafeAccountAssetEditor.cs.meta diff --git a/Samples~/CreatingAsas/Runtime/AlgodClientObject.cs b/Samples~/CreatingAsas/Runtime/AlgodClientObject.cs deleted file mode 100644 index 221cc679a..000000000 --- a/Samples~/CreatingAsas/Runtime/AlgodClientObject.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEngine; - -namespace Algorand.Unity.Samples.CreatingAsas -{ - [CreateAssetMenu] - public class AlgodClientObject - : ScriptableObject - { - public AlgodClient Client; - public AlgorandNetwork Network; - } -} diff --git a/Samples~/CreatingAsas/Runtime/AssetObject.cs b/Samples~/CreatingAsas/Runtime/AssetObject.cs deleted file mode 100644 index 8cc635fd3..000000000 --- a/Samples~/CreatingAsas/Runtime/AssetObject.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEngine; - -namespace Algorand.Unity.Samples.CreatingAsas -{ - [CreateAssetMenu] - public class AssetObject : ScriptableObject - { - public AssetIndex Index; - public AlgorandNetwork Network; - public AssetParams Params; - } -} \ No newline at end of file diff --git a/Samples~/CreatingAsas/Runtime/AccountObject.cs b/Samples~/CreatingAsas/Runtime/UnsafeAccountAsset.cs similarity index 71% rename from Samples~/CreatingAsas/Runtime/AccountObject.cs rename to Samples~/CreatingAsas/Runtime/UnsafeAccountAsset.cs index e7b75cc24..1e82d1d80 100644 --- a/Samples~/CreatingAsas/Runtime/AccountObject.cs +++ b/Samples~/CreatingAsas/Runtime/UnsafeAccountAsset.cs @@ -1,14 +1,15 @@ using System; +using System.Threading; +using Cysharp.Threading.Tasks; using UnityEngine; namespace Algorand.Unity.Samples.CreatingAsas { [CreateAssetMenu] - public class AccountObject - : ScriptableObject - , IAccount - , ISigner - , ISerializationCallbackReceiver + public class UnsafeAccountAsset + : AccountAsset + , ISigner + , ISerializationCallbackReceiver { [SerializeField] private Mnemonic mnemonic; @@ -16,7 +17,7 @@ public class AccountObject private Account account; - public Address Address => account.Address; + public override Address Address => account.Address; public SignedTxn SignTxn(T txn) where T : ITransaction, IEquatable => account.SignTxn(txn); @@ -24,6 +25,11 @@ public SignedTxn SignTxn(T txn) public SignedTxn[] SignTxns(T[] txns, TxnIndices txnsToSign) where T : ITransaction, IEquatable => account.SignTxns(txns, txnsToSign); + public override UniTask[]> SignTxnsAsync(T[] txns, TxnIndices txnsToSign, CancellationToken cancellationToken = default) + { + return account.SignTxnsAsync(txns, txnsToSign, cancellationToken); + } + [System.Diagnostics.Conditional("UNITY_EDITOR")] [ContextMenu(nameof(GenerateNewAccount))] public void GenerateNewAccount() diff --git a/Samples~/CreatingAsas/Runtime/AccountObject.cs.meta b/Samples~/CreatingAsas/Runtime/UnsafeAccountAsset.cs.meta similarity index 100% rename from Samples~/CreatingAsas/Runtime/AccountObject.cs.meta rename to Samples~/CreatingAsas/Runtime/UnsafeAccountAsset.cs.meta diff --git a/Samples~/CreatingAsas/TestNetAlgod.asset b/Samples~/CreatingAsas/TestNetAlgod.asset deleted file mode 100644 index 40b817087..000000000 --- a/Samples~/CreatingAsas/TestNetAlgod.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:67f5bfab2c5873562f23ce74c07194b660e873b466d077df30196f759228f2cc -size 500