コード例 #1
0
        public async Task <bool> SetTargetChain(int chainId)
        {
            if (ChainInfo != null && ChainInfo.ChainId != chainId)
            {
                ChainInfo = null;
            }

            if (ChainInfo == null)
            {
                ChainInfo = (await DownloadChainInfo(chainId)).Data;
            }

            var endPoints = ChainInfo?.GetPublicEndpoints() ?? new List <string>();

            if (!(_forceDefaults && chainId == _defaultChainId))
            {
                if (endPoints == null || endPoints.Count == 0)
                {
                    Log.Trace("Chain has no valid public endpoints.", this);
                    return(false);
                }
            }

            ChainId = chainId;

            var alreadyConnected = false;

            foreach (var endpoint in endPoints)
            {
                var uri = new Uri(endpoint);
                if (ChainEndPoint == uri)
                {
                    alreadyConnected = true;
                    break;
                }
            }

            if (!alreadyConnected && _forceDefaults && ChainId == _defaultChainId)
            {
                alreadyConnected = ChainEndPoint == _defaultEndPoint;
            }

            if (!alreadyConnected)
            {
                if (_forceDefaults && ChainId == _defaultChainId)
                {
                    ChainEndPoint = _defaultEndPoint;
                }
                else
                {
                    ChainEndPoint = new Uri(endPoints[Rand.NextInt(endPoints.Count)]);
                }

                await EndpointChanged();
            }

            return(true);
        }
コード例 #2
0
        protected override async Task QueryDoneAsync(int chainId, ChainInfo chainInfo)
        {
            _revenueInfo = null;
            if (chainInfo != null)
            {
                var endPoints = chainInfo.GetPublicEndpoints();
                if (endPoints.Count > 0)
                {
                    var client   = new ClientBase(new Uri(endPoints[0]), chainId);
                    var download = (await client.DownloadRevenueInfo(chainId, WalletApp.CurrentAccountId));
                    var data     = download.Data;
                    _revenueInfo = data?.Item;
                    if (_revenueInfo == null)
                    {
                        await ErrorAsync("QueryRevenueFailed");
                    }
                }
            }

            _revenueView.Update(_revenueInfo);
        }
コード例 #3
0
        public ChainPage(ChainInfo chainInfo, ChainKeyStore chainKey) : base("ChainPage")
        {
            ChainInfo = chainInfo;
            _chainKey = chainKey;
            Subscribe <ChainRegistrationEvent>(Chain);

            if (chainInfo != null)
            {
                var endPoints = chainInfo.GetPublicEndpoints();
                foreach (var endPoint in endPoints)
                {
                    _endPoints.Add(new ChainItem <string>(ChainItemStatus.Live, endPoint));
                }
                foreach (var key in chainInfo.GetRevokeableChainKeys())
                {
                    _chainKeys.Add(new ChainKeyItem(key.IsRevoked ? ChainItemStatus.Revoked : ChainItemStatus.Live, key.Item));
                }
                foreach (var purchase in chainInfo.GetChainPurchases())
                {
                    _purchases.Add(new ChainItem <PurchaseInfo>(purchase.IsRevoked ? ChainItemStatus.Revoked : ChainItemStatus.Live, purchase.Item));
                }
            }

            AddTitleRow("Title");

            AddHeaderRow("Info");
            _name = AddEntryRow(null, "Name");
            _name.SetDetailViewIcon(Icons.Pencil);
            if (chainInfo != null)
            {
                _name.Edit.Text = chainInfo.Name;
            }
            _website = AddEntryRow(null, "Website");
            _website.SetDetailViewIcon(Icons.RowLink);
            if (chainInfo != null)
            {
                _website.Edit.Text = chainInfo.Website;
            }
            AddFooterRow();

            AddHeaderRow("ChainKeys");
            _chainKeysButton = AddButtonRow("ChainKeysButton", NewChainKey);
            Status.AddBusyView(_chainKeysButton);
            AddFooterRow();

            AddHeaderRow("EndPoints");
            _endPointsButton = AddButtonRow("EndPointsButton", NewEndPoint);
            Status.AddBusyView(_endPointsButton);
            AddFooterRow();

            /*
             * AddHeaderRow("Purchases");
             * _purchasesButton = AddButtonRow("PurchasesButton", NewPurchase);
             * Status.AddBusyView(_purchasesButton);
             * AddFooterRow();
             */

            Status.Add(_name.Edit, T("NameStatus"), (view, entry, newText, oldTex) =>
            {
                if (string.IsNullOrEmpty(newText))
                {
                    return(false);
                }

                return(true);
            }).
            Add(_website.Edit, T("WebsiteStatus"), (view, entry, newText, oldText) =>
            {
                if (string.IsNullOrEmpty(newText))
                {
                    return(true);
                }

                return(newText.IsValdiUrl(true));
            });

            _adminKeyStatus = Status.Add(T("AdminKeyStatus"), (sv) =>
            {
                foreach (var key in _chainKeys)
                {
                    if ((key.Status == ChainItemStatus.Live || key.Status == ChainItemStatus.New) && ((key.Item.Flags & PublicChainKeyFlags.ChainAdminKey) != 0))
                    {
                        return(true);
                    }
                }

                return(false);
            });

            _endPointStatus = Status.Add(T("EndPointStatus"), (sv) =>
            {
                return(_endPoints.Any((a) => a.Status == ChainItemStatus.New || a.Status == ChainItemStatus.Live));
            });

            AddIndex       = AddSubmitRow("Submit", Submit);
            AddIndexBefore = true;
            if (_chainKey != null)
            {
                _keyPassword = AddPasswordRow("", "KeyPassword");

                Status.Add(_keyPassword.Edit, T("PasswordStatus"), (sv, entry, newText, oldText) =>
                {
                    return(_chainKey.IsPasswordValid(newText));
                });
            }

            AddIndex       = null;
            AddIndexBefore = false;

            UpdateChainKeys();
            UpdateEndpoints();
            UpdatePurchases();
        }