Ejemplo n.º 1
0
        private void Connect(object sender, EventArgs e)
        {
            if (_viewModel.SelectedWallet == null)
            {
                return;
            }

            _viewModel.ToggleLoading();
            _walletRepository.Get(_viewModel.SelectedWallet.Name, _viewModel.Password).ContinueWith((r) =>
            {
                try
                {
                    var result = r.Result;
                    WalletStore.Instance().SetAuthenticatedWallet(r.Result);
                    WalletStore.Instance().SetPassword(_viewModel.Password);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        NavigationService.Navigate(_walletPage);
                    });
                }
                catch (AggregateException)
                {
                    MainWindowStore.Instance().DisplayError("Cannot connect to the wallet");
                }
                finally
                {
                    _viewModel.ToggleLoading();
                }
            });
        }
Ejemplo n.º 2
0
        private void DisplayBlock(object sender, BlockEventArgs e)
        {
            var walletStore = WalletStore.Instance();
            var flyout      = new BlockFlyoutPage(e.Data, walletStore.GetAuthenticatedWallet().Network);

            MainWindowStore.Instance().DisplayFlyout(flyout, Position.Right, 400);
        }
Ejemplo n.º 3
0
        private void ListenSmartContract(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (_viewModel.SelectedSolidityContract == null)
            {
                MainWindowStore.Instance().DisplayError("Contract must be selected");
                return;
            }

            var rpcClient = new RpcClient(authenticatedWallet.Network);

            rpcClient.AddFilter(_viewModel.SelectedSolidityContract.Address.FromHexString()).ContinueWith((t) =>
            {
                try
                {
                    var addFilterResult = t.Result;
                    _solidityFilterRepository.Add(_viewModel.SelectedSolidityContract.Address, t.Result.ToHexString()).ContinueWith((s) =>
                    {
                        if (!s.Result)
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                MainWindowStore.Instance().DisplayMessage("The filter cannot be added");
                            });
                        }
                        else
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                MainWindowStore.Instance().DisplayMessage("The filter has been added");
                            });
                        }
                    });
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying add the filter"));
                }
            });
        }
Ejemplo n.º 4
0
        private void PublishTransactionCall(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (_viewModel.SelectedSolidityContract == null)
            {
                MainWindowStore.Instance().DisplayError("Contract must be selected");
                return;
            }

            if (_viewModel.SelectedFunctionDefinition == null)
            {
                MainWindowStore.Instance().DisplayError("Function must be selected");
                return;
            }

            var callValue = _viewModel.SelectedFunctionDefinition.FunctionAgg.GetCallValue(_viewModel.SelectedFunctionDefinition.Parameters.Select(p => p.Value));
            var rpcClient = new RpcClient(authenticatedWallet.Network);
            var smartContractTransaction = new SmartContractTransaction
            {
                To   = _viewModel.SelectedSolidityContract.Address.FromHexString(),
                Data = callValue.FromHexString()
            };

            rpcClient.SendRawTransaction(smartContractTransaction).ContinueWith((t) =>
            {
                try
                {
                    var txId = t.Result;
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        MainWindowStore.Instance().DisplayMessage(string.Format("A new transaction has been published : {0}", txId));
                    });
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to publish the transaction"));
                }
            });
        }
        private void OpenTransaction(object sender, EventArgs e)
        {
            var selectedTransaction = _viewModel.SelectedTransaction;

            if (selectedTransaction == null)
            {
                return;
            }

            var txId   = selectedTransaction.TxId.FromHexString();
            var flyout = new TransactionFlyout(txId, _network);

            MainWindowStore.Instance().DisplayFlyout(flyout, Position.Left, 400);
        }
Ejemplo n.º 6
0
 void Load(object sender, RoutedEventArgs e)
 {
     frame.Navigated          += PART_Frame_Navigated;
     frame.Navigating         += PART_Frame_Navigating;
     frame.NavigationFailed   += PART_Frame_NavigationFailed;
     frame.NavigationProgress += PART_Frame_NavigationProgress;
     frame.NavigationStopped  += PART_Frame_NavigationStopped;
     frame.LoadCompleted      += PART_Frame_LoadCompleted;
     frame.FragmentNavigation += PART_Frame_FragmentNavigation;
     PART_BackButton.Click    += PART_BackButton_Click;
     PART_ForwardButton.Click += PART_ForwardButton_Click;
     MainWindowStore.Instance().DisplayFlyoutEvt  += DisplayFlyout;
     MainWindowStore.Instance().DisplayErrorEvt   += DisplayError;
     MainWindowStore.Instance().DisplayMessageEvt += DisplayMessage;
 }
Ejemplo n.º 7
0
        private void GetLastLogs(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (_viewModel.SelectedFilter == null)
            {
                MainWindowStore.Instance().DisplayError("Please select a filter");
                return;
            }

            var rpcClient = new RpcClient(authenticatedWallet.Network);

            rpcClient.GetFilterChanges(_viewModel.SelectedFilter.Id.FromHexString()).ContinueWith((t) =>
            {
                try
                {
                    // _viewModel.SelectedSolidityContract.SolidityContractAgg
                    var addFilterResult = t.Result;
                    var displayedStr    = new StringBuilder();
                    if (addFilterResult != null && addFilterResult.Any())
                    {
                        foreach (var addFilter in addFilterResult)
                        {
                            var res = _viewModel.SelectedSolidityContract.SolidityContractAgg.GetLogs(addFilter.Topics.First().GetData(), addFilter.Data);
                            displayedStr.AppendLine(string.Format("{0} : {1}", res.Function.GetFullName(), string.Join(",", res.Data.Select(r => System.Text.Encoding.UTF8.GetString(r.ToArray())))));
                        }
                    }

                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayMessage(displayedStr.ToString()));
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying get the last changes"));
                }
            });
        }
Ejemplo n.º 8
0
        private void CallContract(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (_viewModel.SelectedSolidityContract == null)
            {
                MainWindowStore.Instance().DisplayError("Contract must be selected");
                return;
            }

            if (_viewModel.SelectedFunctionDefinition == null)
            {
                MainWindowStore.Instance().DisplayError("Function must be selected");
                return;
            }

            var callValue = _viewModel.SelectedFunctionDefinition.FunctionAgg.GetCallValue(_viewModel.SelectedFunctionDefinition.Parameters.Select(p => p.Value));
            var smartContractTransactionParameter = new SmartContractTransactionParameter(_viewModel.SelectedSolidityContract.Address.FromHexString());

            smartContractTransactionParameter.Data = callValue.FromHexString();
            var rpcClient = new RpcClient(authenticatedWallet.Network);

            rpcClient.CallSmartContract(smartContractTransactionParameter).ContinueWith((t) =>
            {
                try
                {
                    var smartContractResult = t.Result;
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayMessage(string.Format("Result of the operation : {0}", smartContractResult)));
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to call the contract"));
                }
            });
        }
Ejemplo n.º 9
0
        private void CompileContract(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (string.IsNullOrWhiteSpace(_viewModel.SmartContract))
            {
                MainWindowStore.Instance().DisplayError("The solidity contract must be filled in");
                return;
            }

            var rpcClient = new RpcClient(authenticatedWallet.Network);

            rpcClient.CompileSolidity(_viewModel.SmartContract).ContinueWith((t) =>
            {
                try
                {
                    var compilationResult = t.Result;
                    UpdateSmartContractDefinition(compilationResult);
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayMessage("The contract has been compiled"));
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to build the solidity contract"));
                }
            });
        }
Ejemplo n.º 10
0
        private void PersistSmartContract(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (string.IsNullOrWhiteSpace(_viewModel.TransactionId))
            {
                MainWindowStore.Instance().DisplayError("The transaction address must be filled in");
                return;
            }

            if (_publishedSolidityContract == null)
            {
                MainWindowStore.Instance().DisplayError("The smart contract must be published");
                return;
            }

            IEnumerable <byte> txId = null;

            try
            {
                txId = _viewModel.TransactionId.FromHexString();
            }
            catch (Exception)
            {
                MainWindowStore.Instance().DisplayError("The transaction address is not a valid hex");
                return;
            }

            var rpcClient = new RpcClient(authenticatedWallet.Network);

            rpcClient.GetTransactionReceipt(txId).ContinueWith((r) =>
            {
                try
                {
                    _publishedSolidityContract.Address = r.Result.ContractAddress;
                    _solidityContractsRepository.Insert(_publishedSolidityContract).ContinueWith((t) =>
                    {
                        try
                        {
                            if (t.Result)
                            {
                                Application.Current.Dispatcher.Invoke(() =>
                                {
                                    _viewModel.NewSmartContractAddress = r.Result.ContractAddress;
                                    _publishedSolidityContract         = null;
                                    MainWindowStore.Instance().DisplayMessage("The transaction has been inserted");
                                });
                            }
                            else
                            {
                                Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to insert the smart contract"));
                            }
                        }
                        catch
                        {
                            Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to insert the smart contract"));
                        }
                    });
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to insert the smart contract"));
                }
            });
        }
Ejemplo n.º 11
0
        private void PublishContract(object sender, EventArgs e)
        {
            if (_viewModel == null)
            {
                return;
            }
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            if (string.IsNullOrWhiteSpace(_viewModel.SmartContract))
            {
                MainWindowStore.Instance().DisplayError("The solidity contract must be filled in");
                return;
            }

            var rpcClient = new RpcClient(authenticatedWallet.Network);

            _publishedSolidityContract = null;
            rpcClient.CompileSolidity(_viewModel.SmartContract).ContinueWith((t) =>
            {
                try
                {
                    var compilationResult = t.Result;
                    if (compilationResult.Infos == null || !compilationResult.Infos.Any())
                    {
                        return;
                    }

                    UpdateSmartContractDefinition(compilationResult);
                    var newKey   = _walletHelper.CreateNewAddress();
                    var fromAddr = newKey.GetPublicKeyHashed();
                    var smartContractTransaction = new SmartContractTransaction
                    {
                        From  = fromAddr,
                        Data  = compilationResult.Infos.First().Code.FromHexString(),
                        Nonce = NonceHelper.GetNonceInt32()
                    };
                    rpcClient.SendRawTransaction(smartContractTransaction).ContinueWith((c) =>
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            _viewModel.TransactionId = c.Result;
                        });
                        _publishedSolidityContract = new SolidityContractAggregate
                        {
                            Abi  = compilationResult.Infos.First().AbiDefinition.ToString(),
                            Code = compilationResult.Infos.First().Code
                        };
                    });
                }
                catch (AggregateException)
                {
                    Application.Current.Dispatcher.Invoke(() => MainWindowStore.Instance().DisplayError("An error occured while trying to build the solidity contract"));
                }
            });
        }
        private void SendMoney(object sender, EventArgs e)
        {
            var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet();

            if (authenticatedWallet == null)
            {
                MainWindowStore.Instance().DisplayError("You're not authenticated");
                return;
            }

            var receiverValue       = _viewModel.SendValue;
            var addr                = _viewModel.SendAddress;
            var selectedTransaction = _viewModel.SelectedTransaction;

            if (selectedTransaction == null)
            {
                MainWindowStore.Instance().DisplayError("A transaction must be selected");
                return;
            }

            if (receiverValue > selectedTransaction.Amount)
            {
                return;
            }

            var txFee       = _transactionHelper.GetMinFee();
            var senderValue = selectedTransaction.Amount - receiverValue - txFee;
            var walletAddr  = authenticatedWallet.Addresses.FirstOrDefault(a => a.Hash == selectedTransaction.Hash);

            if (walletAddr == null)
            {
                MainWindowStore.Instance().DisplayError("The selected tranasction is not linked to your wallet");
                return;
            }

            BlockChainAddress bcAddr = null;

            try
            {
                bcAddr = BlockChainAddress.Deserialize(addr);
            }
            catch (Exception)
            {
                MainWindowStore.Instance().DisplayError("The address is not correct");
            }

            if (bcAddr == null)
            {
                MainWindowStore.Instance().DisplayError("The address is not correct");
                return;
            }

            var newKey = _walletHelper.CreateNewAddress();
            var kh     = new BigInteger(newKey.GetPublicKeyHashed());
            var script = _scriptBuilder.New()
                         .AddToStack(walletAddr.Key.GetSignature())
                         .AddToStack(walletAddr.Key.GetPublicKey())
                         .Build();
            var pp          = walletAddr.Key.GetPublicKeyHashed();
            var senderSript = _scriptBuilder.New() // SEND MONEY TO MY WALLET.
                              .AddOperation(OpCodes.OP_DUP)
                              .AddOperation(OpCodes.OP_HASH160)
                              .AddToStack(newKey.GetPublicKeyHashed())
                              .AddOperation(OpCodes.OP_EQUALVERIFY)
                              .AddOperation(OpCodes.OP_CHECKSIG)
                              .Build();
            var receiverScript = _scriptBuilder.New() // SEND MONEY TO THE SELLER.
                                 .AddOperation(OpCodes.OP_DUP)
                                 .AddOperation(OpCodes.OP_HASH160)
                                 .AddToStack(bcAddr.PublicKeyHash)
                                 .AddOperation(OpCodes.OP_EQUALVERIFY)
                                 .AddOperation(OpCodes.OP_CHECKSIG)
                                 .Build();
            var txBuilder = _transactionBuilder.NewNoneCoinbaseTransaction()
                            .Spend(selectedTransaction.TxId.FromHexString(), (uint)selectedTransaction.Vout, script.Serialize())
                            .AddOutput((long)receiverValue, receiverScript);

            if (senderValue > 0)
            {
                txBuilder.AddOutput((long)senderValue, senderSript);
            }

            var tx        = txBuilder.Build();
            var s         = tx.Serialize().Count();
            var rpcClient = new RpcClient(authenticatedWallet.Network);

            rpcClient.SendRawTransaction(tx).ContinueWith((r) =>
            {
                try
                {
                    var res = r.Result;
                }
                catch (AggregateException ex)
                {
                    var exx = ex.InnerExceptions;
                }
            });
        }