コード例 #1
0
ファイル: PhantasmaDemo.cs プロジェクト: merl111/PhantasmaSDK
    /// <summary>
    /// Returns the account name and balance of given address.
    /// </summary>
    /// <param name="address">String, base58 encoded - address to check for balance and name.</param>
    public void GetAccount(string address)
    {
        CanvasManager.Instance.ShowOperationPopup("Fetching account data from the blockchain...", false);

        StartCoroutine(PhantasmaApi.GetAccount(address,
                                               account =>
        {
            CanvasManager.Instance.accountMenu.SetBalance("Name: " + account.name);

            foreach (var balance in account.balances)
            {
                var isFungible = PhantasmaTokens[balance.symbol].flags.Contains("Fungible");

                var amount = isFungible ? decimal.Parse(balance.amount) / (decimal)Mathf.Pow(10f, 8) : decimal.Parse(balance.amount);
                CanvasManager.Instance.accountMenu.AddBalanceEntry("Chain: " + balance.chain + " - " + amount + " " + balance.symbol);

                if (balance.symbol.Equals(TOKEN_SYMBOL))
                {
                    TokenCurrentSupply = amount;

                    MyCars.Clear();

                    foreach (var tokenID in balance.ids)
                    {
                        StartCoroutine(PhantasmaApi.GetTokenData(TOKEN_SYMBOL, tokenID.ToString(),
                                                                 (tokenData =>
                        {
                            var ramBytes = Base16.Decode(tokenData.ram);
                            var carMutableData = Serialization.Unserialize <CarMutableData>(ramBytes);

                            var romBytes = Base16.Decode(tokenData.rom);
                            var carData = Serialization.Unserialize <CarData>(romBytes);

                            var newCar = new Car();
                            newCar.SetCar(Address.FromText(tokenData.ownerAddress), tokenID, carData, carMutableData);

                            MyCars.Add(newCar.TokenID, newCar);
                        }),
                                                                 (type, s) =>
                        {
                        }));
                    }
                }
            }

            CanvasManager.Instance.HideOperationPopup();

            LoggedIn(address);
        },
                                               (errorType, errorMessage) =>
        {
            CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, errorType + " - " + errorMessage);
        }
                                               ));
    }
コード例 #2
0
ファイル: PhantasmaDemo.cs プロジェクト: merl111/PhantasmaSDK
    /// <summary>
    /// Check if the auction purchase was successful
    /// </summary>
    private IEnumerator CheckTokenMint(CarData carData, CarMutableData carMutableData, string result)
    {
        CanvasManager.Instance.ShowOperationPopup("Checking token mint...", true);

        yield return(CheckOperation(EBLOCKCHAIN_OPERATION.MINT_TOKEN, result,
                                    (tx) =>
        {
            foreach (var evt in tx.events)
            {
                EventKind eKind;
                if (Enum.TryParse(evt.kind, out eKind))
                {
                    if (eKind == EventKind.TokenMint)
                    {
                        var bytes = Base16.Decode(evt.data);
                        var tokenData = Serialization.Unserialize <TokenEventData>(bytes);

                        var tokenID = tokenData.value;

                        var newCar = new Car();
                        newCar.SetCar(Key.Address, tokenID.ToString(), carData, carMutableData);

                        // Add new car to admin assets
                        MyCars.Add(tokenID.ToString(), newCar);

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

                        CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.SUCCESS, "Token mint with success.");

                        return;
                    }
                }
            }

            CanvasManager.Instance.HideOperationPopup();
            CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Something failed while executing a new token mint. Please try again.");
        },
                                    ((errorType, errorMessage) =>
        {
            CanvasManager.Instance.HideOperationPopup();
            CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, errorType + " - " + errorMessage);
        })));
    }