Пример #1
0
        public async Task <KeyStore> StoreAccount(string name, PublicChainKey publicChainKey, Key key, string password)
        {
            return(await Task.Run(async() =>
            {
                var keyStore = new ChainKeyStore(name, publicChainKey, key, password);

                await StoreAccount(keyStore);
                await keyStore.DecryptKeyAsync(password, false);
                return keyStore;
            }));
        }
Пример #2
0
        public static async Task UpdateChain(ChainKeyStore chainKey, string password, string chainName, string chainWebsite, WalletClient.ChainKey[] chainKeys, Uri[] endPoints, PurchaseInfo[] purchases, short[] revokedChainKeys, Uri[] revokedEndPoints, int[] revokedPurchases)
        {
            if (CurrentCoreAccount == null)
            {
                return;
            }


            HeleusClientResponse result    = null;
            ChainInfo            chainInfo = null;

            if (_busy)
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.Busy);
                goto end;
            }
            _busy = true;

            try
            {
                await chainKey.DecryptKeyAsync(password, true);

                await Client.SetChainAccount(chainKey, password);
            }
            catch
            {
                result = new HeleusClientResponse(HeleusClientResultTypes.PasswordError);
                goto end;
            }

            try
            {
                var transaction = Client.NewChainUpdateTransaction(true);
                if (chainKeys != null)
                {
                    foreach (var ck in chainKeys)
                    {
                        transaction.AddChainKey(ck.SignedPublicKey);
                    }
                }
                if (endPoints != null)
                {
                    foreach (var ep in endPoints)
                    {
                        transaction.AddPublicEndpoint(ep.AbsoluteUri);
                    }
                }
                if (purchases != null)
                {
                    foreach (var p in purchases)
                    {
                        transaction.AddPurchase(p);
                    }
                }

                if (revokedChainKeys != null)
                {
                    foreach (var key in revokedChainKeys)
                    {
                        transaction.RevokeChainKey(key);
                    }
                }

                if (revokedEndPoints != null)
                {
                    foreach (var ep in revokedEndPoints)
                    {
                        transaction.RemovePublicEndPoint(ep.AbsoluteUri);
                    }
                }

                if (revokedPurchases != null)
                {
                    foreach (var p in revokedPurchases)
                    {
                        transaction.RemovePurchase(p);
                    }
                }

                transaction.UpdateChainName(chainName);
                transaction.UpdateChainWebsite(chainWebsite);

                if (!await Client.SetTargetChain(Protocol.CoreChainId))
                {
                    result = new HeleusClientResponse(HeleusClientResultTypes.EndpointConnectionError);
                    goto end;
                }

                result = await Client.UpdateChain(transaction, chainKeys);

                if (result.TransactionResult == TransactionResultTypes.Ok)
                {
                    chainInfo = (await Client.DownloadChainInfo((result.Transaction as ChainInfoOperation).ChainId)).Data;
                }
            }
            catch (Exception ex)
            {
                Log.IgnoreException(ex);
            }

end:
            await UIApp.PubSub.PublishAsync(new ChainRegistrationEvent(result, chainInfo));

            if (result.ResultType != HeleusClientResultTypes.Busy)
            {
                _busy = false;
            }
        }