Beispiel #1
0
    /// <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);
        }
                                               ));
    }
Beispiel #2
0
    public void LogOut()
    {
        IsTokenCreated = false;
        IsTokenOwner   = false;

        TokenCurrentSupply = 0;

        MyCars.Clear();

        CanvasManager.Instance.mainMenu.SetAdminButton();

        CanvasManager.Instance.myAssetsMenu.ClearContent();
        CanvasManager.Instance.marketMenu.ClearContent();

        CanvasManager.Instance.ClearAddress();
        CanvasManager.Instance.OpenLogin();
    }