コード例 #1
0
ファイル: PhantasmaDemo.cs プロジェクト: merl111/PhantasmaSDK
    public IEnumerator CheckOperation(EBLOCKCHAIN_OPERATION operation, string transactionHash, Action <Transaction> callback, Action <EPHANTASMA_SDK_ERROR_TYPE, string> errorHandlingCallback = null)
    {
        if (_pendingTxCoroutine != null)
        {
            StopCoroutine(_pendingTxCoroutine);

            _pendingTxCoroutine = null;
        }

        _pendingTxCoroutine = CheckOperationCoroutine(operation, transactionHash, callback, errorHandlingCallback);

        yield return(StartCoroutine(_pendingTxCoroutine));
    }
コード例 #2
0
ファイル: PhantasmaDemo.cs プロジェクト: merl111/PhantasmaSDK
    /// <summary>
    /// Check if the creation of a new token on Phantasma Blockchain was successful
    /// </summary>
    public IEnumerator CheckTokenCreation(EBLOCKCHAIN_OPERATION operation, string result)
    {
        CanvasManager.Instance.ShowOperationPopup("Checking token creation...", true);

        yield return(CheckOperation(operation, result,
                                    (tx) =>
        {
            foreach (var evt in tx.events)
            {
                EventKind eKind;
                if (Enum.TryParse(evt.kind, out eKind))
                {
                    if (eKind == EventKind.TokenCreate)
                    {
                        var bytes = Base16.Decode(evt.data);
                        var tokenSymbol = Serialization.Unserialize <string>(bytes);

                        Debug.Log(evt.kind + " - " + tokenSymbol);

                        if (tokenSymbol.Equals(TOKEN_SYMBOL))
                        {
                            IsTokenCreated = true;
                            IsTokenOwner = true;

                            CheckTokens(() =>
                            {
                                CanvasManager.Instance.adminMenu.SetContent();
                            });

                            CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.SUCCESS, "New token created with success.");
                        }

                        return;
                    }
                }
            }

            CanvasManager.Instance.HideOperationPopup();
            CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Something failed on the connection to the blockchain. Please try again.");
        },
                                    ((errorType, errorMessage) =>
        {
            CanvasManager.Instance.HideOperationPopup();
            CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, errorType + " - " + errorMessage);
        })));
    }
コード例 #3
0
ファイル: PhantasmaDemo.cs プロジェクト: merl111/PhantasmaSDK
    private IEnumerator CheckOperationCoroutine(EBLOCKCHAIN_OPERATION operation, string transactionHash, Action <Transaction> callback, Action <EPHANTASMA_SDK_ERROR_TYPE, string> errorHandlingCallback = null)
    {
        _lastTransactionType = operation;
        _lastTransactionHash = transactionHash;

        var isTransactionCompleted = false;

        while (!isTransactionCompleted)
        {
            yield return(PhantasmaApi.GetTransaction(transactionHash,
                                                     (tx) =>
            {
                isTransactionCompleted = true;

                if (callback != null)
                {
                    callback(tx);
                }
            },
                                                     (errorType, errorMessage) =>
            {
                if (errorType == EPHANTASMA_SDK_ERROR_TYPE.API_ERROR && errorMessage.Equals("pending"))
                {
                    // Pending
                }
                else
                {
                    isTransactionCompleted = true;

                    if (errorHandlingCallback != null)
                    {
                        errorHandlingCallback(errorType, errorMessage);
                    }
                }
            }));

            yield return(new WaitForSecondsRealtime(_TRANSACTION_CONFIRMATION_DELAY));
        }
    }