Example #1
0
        private void LoadAccounts()
        {
            Accounts = new List <Account>();

            var accounts = EthereumService.GetAccounts();



            foreach (var account in accounts)
            {
                var a = new Account();
                a.Address = account;

                var filter = new Filter(fromBlock: "0x01")
                {
                    Address = a.Address
                };

                a.FilterId = EthereumService.NewFilter(filter);
                Accounts.Add(a);
                ListViewItem item = new ListViewItem(a.Address);
                var          sign = EthereumService.Sign(a.Address, "Pass@123");
                lstboxAccountList.Items.Add(a.Address);

                a.Unlocked = sign != null;
                EthereumService.UnlockAccount(a.Address, "Pass@123");
            }
        }
Example #2
0
 /// <summary>
 /// Event handler for Used Addresses Updated by Ethereum Service.
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event.</param>
 protected void OnUsedAddressesUpdated(object sender, EthereumServiceEventArgs args)
 {
     this.InvokeOnUiThreadIfRequired(() => {
         this.usedAddressesValueLinkLabel.Text  = args.UsedAccounts;
         this.propabilityPerPageValueLabel.Text = Convert.ToString(25 * EthereumService.PercentageUsed(args.UsedAccounts, EthereumService.TotalAddresses));
     });
 }
Example #3
0
        private string SendTransaction(string fromAccount, string ToAccount, string ethvalue)
        {
            //var value = txtAmount.Text.ToBigInteger(NumberStyles.Integer);
            SendTxHistoryList = new List <SendTxHistory>();

            var privateConnection = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://localhost"
            };

            ethereumService = new EthereumService(privateConnection);

            var value = ethvalue.ToBigInteger(NumberStyles.Integer) * 1000000000000000000;

            var transaction = new Transaction()
            {
                To    = ToAccount,
                From  = fromAccount,
                Value = value.ToHexString()
            };



            var txHash = ethereumService.SendTransaction(transaction);

            return(txHash);
        }
Example #4
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            var value = txtAmount.Text.ToBigInteger(NumberStyles.Integer);

            value = value * 1000000000000000000;

            var transaction = new Transaction()
            {
                To    = txtSendTo.Text,
                From  = cmdAccounts.SelectedItem.ToString(),
                Value = value.ToHexString()
            };


            var txHash = EthereumService.SendTransaction(transaction);

            var sendTxHistory = new SendTxHistory()
            {
                DateTime = DateTime.Now.ToString(),
                Amount   = transaction.Value.ToBigInteger().WeiToEther(),
                Hash     = txHash
            };

            SendTxHistoryList.Add(sendTxHistory);

            dgSendTransactions.DataSource = null;
            dgSendTransactions.DataSource = SendTxHistoryList;
            SetGridWidth();

            txtTransactionHash.Text = txHash;
            // MessageBox.Show(txHash, "Transaction");
        }
Example #5
0
        private void LoadAccounts()
        {
            Accounts = new List <Account>();

            var accounts = EthereumService.GetAccounts();

            cmdAccounts.Items.Clear();

            foreach (var account in accounts)
            {
                var a = new Account();
                a.Address = account;

                var filter = new Filter(fromBlock: "0x01")
                {
                    Address = a.Address
                };

                a.FilterId = EthereumService.NewFilter(filter);
                Accounts.Add(a);

                var sign = EthereumService.Sign(a.Address, "Pass@123");

                a.Unlocked = sign != null;

                cmdAccounts.Items.Add(a);
                EthereumService.UnlockAccount(a.Address, "Pass@123");
            }

            if (accounts.Any())
            {
                cmdAccounts.SelectedIndex = 0;
            }
        }
Example #6
0
        public async Task ShouldReturnEthApiBlockService()
        {
            var ethereumService = new EthereumService(Configuration, Mapper);

            ethereumService.EthApiBlockService.Should().NotBeNull();
            ethereumService.EthApiBlockService.Should().BeOfType <EthApiBlockService>();
        }
Example #7
0
        public async Task <APIGatewayCustomAuthorizerResponse> FunctionHandler(APIGatewayCustomAuthorizerRequest authEvent, ILambdaContext context)
        {
            context.Logger.LogLine(JsonConvert.SerializeObject(authEvent));
            VerificationEventType verificationType;

            if (authEvent.Path.StartsWith("/upload/"))
            {
                verificationType = VerificationEventType.VerificationUpload;
            }
            else if (authEvent.Path.StartsWith("/download/"))
            {
                verificationType = VerificationEventType.VerificationSale;
            }
            else
            {
                return(GetDenyResponse(authEvent.AuthorizationToken));
            }

            string secret  = null;
            string txnHash = null;

            authEvent.QueryStringParameters.TryGetValue("soarSecret", out secret);
            authEvent.QueryStringParameters.TryGetValue("txnHash", out txnHash);

            if (string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(txnHash))
            {
                return(GetDenyResponse(authEvent.AuthorizationToken));
            }

            string           infuraAddress       = authEvent.StageVariables["infura_address"];
            string           soarContractAddress = authEvent.StageVariables["soar_contract_address"];
            IEthereumService ethereumService     = new EthereumService(infuraAddress, soarContractAddress);

            using (var storageService = _storageService == null ? new DynamoDbStorageService(context.Logger.LogLine) : _storageService)
            {
                var sdDb = await storageService.GetSecretDetails(secret);

                var sdEth = await ethereumService.GetSecretDetails(txnHash, verificationType);

                if (sdDb == null || sdEth == null)
                {
                    return(GetDenyResponse(authEvent.AuthorizationToken));
                }

                context.Logger.LogLine($"secret: {secret}");
                context.Logger.LogLine($"address: {sdDb.Address} addressEth: {sdEth.Address}");
                context.Logger.LogLine($"challenge: {sdDb.Challenge} challengeEth: {sdEth.Challenge}");
                context.Logger.LogLine($"fileHash: {sdDb.FileHash} fileHashEth: {sdEth.FileHash}");
                if (sdDb.Challenge.Equals(sdEth.Challenge) && sdDb.Address.EqualsIgnoreCase(sdEth.Address) && sdDb.FileHash.Equals(sdEth.FileHash))
                {
                    context.Logger.LogLine("Success");
                    //todo mark secret as used one in db to disable to use it again
                    return(GetAllowResponse(authEvent.AuthorizationToken));
                }
                return(GetDenyResponse(authEvent.AuthorizationToken));
            }
        }
Example #8
0
        private async Task InitConstructor()
        {
            _requestProvider = new RequestProvider();
            _ethereumService = new EthereumService();

            LockApp      = (bool)Settings.Get(Settings.Key.IsLockApp);
            Notification = (bool)Settings.Get(Settings.Key.IsNotification);

            InitSettings();
        }
 public EthereumLikeStoreController(StoreRepository storeRepository,
                                    BTCPayNetworkProvider btcPayNetworkProvider, InvoiceRepository invoiceRepository,
                                    EthereumService ethereumService, IAuthorizationService authorizationService)
 {
     _storeRepository       = storeRepository;
     _btcPayNetworkProvider = btcPayNetworkProvider;
     _invoiceRepository     = invoiceRepository;
     _ethereumService       = ethereumService;
     _authorizationService  = authorizationService;
 }
Example #10
0
        private bool StopMining()
        {
            var privateConnection = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://localhost"
            };

            ethereumService = new EthereumService(privateConnection);
            return(ethereumService.StopMining());
        }
Example #11
0
        public FrmUnlock(string account, EthereumService ethereumService)
        {
            EthereumService = ethereumService;
            Account         = account;


            InitializeComponent();


            this.txtPassword.HandleCreated += TxtPassword_HandleCreated;
        }
Example #12
0
        private static void Main(string[] args)
        {
            var privateConnection = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://127.0.0.1"
            };


            var ethereumService = new EthereumService(privateConnection);

            var accounts = ethereumService.GetAccounts();

            foreach (var account in accounts)
            {
                var balance = ethereumService.GetBalance(account, BlockTag.Latest);
                Console.WriteLine("account {0}: {1}", account, EtherCurrencyConverter.Convert(balance));
            }

            var blockNumber = ethereumService.GetBlockNumber();

            Console.WriteLine("BlockNumber : {0}", blockNumber);

            for (var i = 0; i < blockNumber; i++)
            {
                var block = ethereumService.GetBlockByNumber(i, BlockTag.Quantity, true);
                var txNum = ethereumService.GetBlockTransactionCountByNumber(BlockTag.Quantity, i);
                if (txNum > 0)
                {
                    Console.WriteLine("{0} - {1}", i, txNum);
                }
            }

            var res = ethereumService.UnlockAccount(accounts[0], "");

            Console.WriteLine(res);
            //var tx = new Transaction
            //{
            //    From = accounts[0],
            //    To = accounts[1],
            //    Value = "2"
            //};
            //var hash = ethereumService.SendTransaction(accounts[0], accounts[1], 90000, ByteString.ConvertStringToHexUnicode("This is my test data"), 1, 2);

            Console.WriteLine(ByteString.ConvertStringToHexUnicode("This is my test data"));

            //Thread.Sleep(5000);
            //Console.WriteLine(hash);
            var tx = ethereumService.GetTransactionByHash("0xf48d237256ab63872d093fc0bcb4c9ea4a205c5dd6ad47a37558e11dd9d1f5df");

            //var tx = ethereumService.GetTransactionByHash(hash);
            Console.WriteLine("Tx: {0}", tx.Input);
            Console.WriteLine("Tx: {0}", ByteString.ConvertHexToStringUnicode(tx.Input.Substring(2)));
        }
Example #13
0
        public AccountBalance()
        {
            InitializeComponent();

            var privateConnection = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://localhost"
            };

            EthereumService = new EthereumService(privateConnection);
        }
Example #14
0
        private async Task InitConstructor()
        {
            _token = null;

            string databasePath = DependencyService.Get <ISQLite>().GetDatabasePath(GlobalSetting.Instance.DbName);

            _tokenService    = new TokenService(new Web3(GlobalSetting.Account, GlobalSetting.Instance.EthereumNetwork));
            _ethereumService = new EthereumService(new Web3(GlobalSetting.Account, GlobalSetting.Instance.EthereumNetwork));
            _repository      = new Repository <Token>(new SQLiteAsyncConnection(databasePath));

            InitializeTokens();
        }
Example #15
0
        public async Task ShouldReturnTransactions()
        {
            ulong block = 9148873;

            var ethereumService = new EthereumService(Configuration, Mapper);

            var txns = await ethereumService.GetTxns(block).ConfigureAwait(false);

            txns.Should <TransactionVewModel>();
            txns.Count().Should().BeGreaterOrEqualTo(0);
            // You can add more test conditions here..........
        }
Example #16
0
        public CreateAccountViewModel(Page context)
        {
            _context = context;

            _requestProvider = new RequestProvider();
            _ethereumService = new EthereumService();

            string databasePath = DependencyService.Get <ISQLite>().GetDatabasePath(GlobalSetting.Instance.DbName);

            _repository = new Repository <Token>(new SQLiteAsyncConnection(databasePath));
            _message    = DependencyService.Get <IMessage>();
        }
Example #17
0
        private async Task InitConstructor()
        {
            _token        = GlobalSetting.Instance.Ethereum;
            RequestString = GlobalSetting.Account.Address;

            _ethereumService = new EthereumService(new Web3(GlobalSetting.Account, GlobalSetting.Instance.EthereumNetwork));
            _tokenService    = new TokenService(new Web3(GlobalSetting.Account, GlobalSetting.Instance.EthereumNetwork));

            if (CrossConnectivity.Current.IsConnected)
            {
                OnRefreshBalance();
            }
        }
Example #18
0
        private void btnUnlock_Click(object sender, EventArgs e)
        {
            var result = EthereumService.UnlockAccount(Account, txtPassword.Text);

            if (!result)
            {
                MessageBox.Show("Incorrect password");
            }
            else
            {
                this.Close();
            }
        }
Example #19
0
        private void RefreshAccount(string account)
        {
            var balance = EthereumService.GetBalance(account, BlockTag.Latest);
            var pending = EthereumService.GetBalance(account, BlockTag.Pending);
            var txCount = EthereumService.GetTransactionCount(account, BlockTag.Latest);
            var changes = EthereumService.GetFilterChanges(GetCurrentAccount().FilterId);

            BeginInvoke((MethodInvoker) delegate
            {
                lblBalance.Text = string.Format("{0} Eth", balance.WeiToEther());
                lblPending.Text = string.Format("{0} Eth", pending.WeiToEther());
                lblTxCount.Text = txCount.ToString();
            });
        }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Stats"/> class.
        /// </summary>
        public Stats()
        {
            InitializeComponent();

            service = new EthereumService();

            this.usedAddressesValueLinkLabel.Text  = "0";
            this.totalAddressesValueLabel.Text     = EthereumService.TotalAddresses;
            this.propabilityPerPageValueLabel.Text = "0";

            service.UsedAddressesRetrieved += OnUsedAddressesUpdated;
            service.ParsedPagesRetrieved   += OnTotalPagesParsedUpdated;

            service.GetUsedAddresses();
            service.GetParsedPages();
        }
Example #21
0
        private void btnShowBalance_Click(object sender, EventArgs e)
        {
            string account = lstboxAccountList.SelectedItem.ToString();
            bool   result  = EthereumService.UnlockAccount(account, "Pass@123");

            if (result)
            {
                var balance = EthereumService.GetBalance(account, BlockTag.Latest);

                MessageBox.Show(account + " - " + string.Format("{0} Eth", balance.WeiToEther()));
            }
            else
            {
                MessageBox.Show("No Balance in this account");
            }
        }
Example #22
0
        private void btnUnlock_Click(object sender, EventArgs e)
        {
            bool result = false;

            try
            {
                result = EthereumService.UnlockAccount(Account, txtPassword.Text);
            }
            catch (Exception ex)
            { }
            if (!result)
            {
                MessageBox.Show("Incorrect password");
            }
            else
            {
                this.Close();
            }
        }
Example #23
0
        private List <EthAccount> LoadAccounts()
        {
            var privateConnection = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://localhost"
            };

            ethereumService = new EthereumService(privateConnection);
            Accounts        = new List <EthAccount>();

            var accounts = ethereumService.GetAccounts();



            foreach (var account in accounts)
            {
                var a = new EthAccount();
                a.Address = account;

                var filter = new Filter(fromBlock: "0x01")
                {
                    Address = a.Address
                };

                a.FilterId = ethereumService.NewFilter(filter);
                Accounts.Add(a);
                var sign = ethereumService.Sign(a.Address, "Pass@123");
                a.Unlocked = sign != null;

                ethereumService.UnlockAccount(a.Address, "Pass@123");

                bool result = ethereumService.UnlockAccount(account, "Pass@123");
                if (result)
                {
                    var balance = ethereumService.GetBalance(account, BlockTag.Latest);
                    //var specifier = "0,0.000";
                    a.Balance = balance.WeiToEther();//string.Format("{0} Eth", balance.WeiToEther().ToString("0,0.000"));
                }
            }
            return(Accounts);
        }
Example #24
0
        private async Task OnCreateAccount()
        {
            var words         = EthereumService.MnenonicPhraseGenerate();
            var inputMnemonic = await BuildInputMnemonicPhrasePage(
                "Enter your mnenonic phrase below to create your wallet.",
                "The mnenonic phrase was an exatact match.\nYour wallet has been created.\nCheck out the dashboard.",
                s => string.Join(" ", words) == s);

            var mnemonicPage = new MnemonicPhrasePage(
                new CommonPageSettings
            {
                HasNavigation = false,
                HeaderText    = "Mnemonic Phrase"
            });

            mnemonicPage.viewModel.Action = async() => await _context.Navigation.PushSingleAsync(inputMnemonic);

            mnemonicPage.viewModel.Words = words;

            await _context.Navigation.PushSingleAsync(mnemonicPage);
        }
        private void TestConnection()
        {
            var savedConnection = (Connection)pgOptions.SelectedObject;

            if (savedConnection.ConnectionType == ConnectionType.Instance)
            {
                var getInstanceState = GethService.GetPortAndInstanceUse(savedConnection.RpcPort);
                if (getInstanceState == GethInstanceState.InstanceRunning)
                {
                    MessageBoxEx.Show(this, string.Format("RpcPort {0} currently in use", savedConnection.RpcPort), "Block Studio", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    GethService.RunGethInstance(savedConnection, true);
                }
            }
            else
            {
                var url             = savedConnection.Url;
                var port            = savedConnection.RpcPort;
                var ethereumService = new EthereumService(url, port);

                try
                {
                    var version = ethereumService.GetWeb3ClientVersion();
                    var result  = MessageBoxEx.Show(this, "_connection Successful", "Block Studio", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                }
                catch (Exception)
                {
                    var result = MessageBoxEx.Show(this, string.Format("Could not connect, is Ethereum running on port {0}?", savedConnection.RpcPort), "Block Studio", MessageBoxButtons.RetryCancel,
                                                   MessageBoxIcon.Error);

                    if (result == DialogResult.Retry)
                    {
                        TestConnection();
                    }
                }
            }
        }
Example #26
0
        public Form1()
        {
            InitializeComponent();
            SendTxHistoryList = new List <SendTxHistory>();


            var privateConnection = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://localhost"
            };

            EthereumService = new EthereumService(privateConnection);

            LoadAccounts();

            //BackgroundWorker bgWorker = new BackgroundWorker();
            //bgWorker.DoWork += BgWorker_DoWork;
            //bgWorker.RunWorkerAsync();

            cmbSendUnit.DataSource   = Enum.GetValues(typeof(EtherUnit));
            cmbSendUnit.SelectedItem = "Ether";
        }
Example #27
0
        public static void Main()
        {
            Console.WriteLine("Bitcoin Hannover Meetup Price Guesser ETH Smart Contract Replacement");
            decimal btcUsdPrice = 0;

            do
            {
                // Check every 15 minutes
                if (btcUsdPrice > 0)
                {
                    Thread.Sleep(15 * 60 * 1000);
                }
                btcUsdPrice = GrabBtcUsdPrice();
                Console.WriteLine("Current BTC price: $" + btcUsdPrice);
            } while (btcUsdPrice >= 12500 && btcUsdPrice < 25000);
            Guess  bestGuess = null;
            double bestGuesserDaysDistance = 10000.0;

            foreach (var guess in guesses)
            {
                double daysDistance = Math.Abs((guess.Date - DateTime.UtcNow.Date).TotalDays);
                if (daysDistance > bestGuesserDaysDistance)
                {
                    continue;
                }
                bestGuess = guess;
                bestGuesserDaysDistance = daysDistance;
            }
            Console.WriteLine("Ending at " + DateTime.UtcNow + ", price=$" + btcUsdPrice +
                              " reached ending condition, will pay out contract now to " + bestGuess.Name + ": " +
                              bestGuess.EthAddress);
            var service = new EthereumService("http://localhost:8545/");

            Console.WriteLine("Final outgoing tx: " + service.SendSmartContractWinner(bestGuess.EthAddress));
            Console.ReadLine();
        }
Example #28
0
        public static void Run(string file)
        {
            if (string.IsNullOrEmpty(file) || !File.Exists(file))
            {
                Console.WriteLine("File required");
                return;
            }

            object            console           = new object();
            ConnectionOptions connectionOptions = new ConnectionOptions()
            {
                Port = "8545",
                Url  = "http://127.0.0.1"
            };

            long            count = 0, have = 0;
            EthereumService ethereumService = new EthereumService(connectionOptions);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Start checking accounts");
            Console.WriteLine("");

            Parallel.ForEach(File.ReadAllLines(file), (address) =>
                             //foreach(string address in File.ReadAllLines(file))
            {
                string endAddress = address;

                if (!address.StartsWith("0x"))
                {
                    endAddress = "0x" + address;
                }

                Interlocked.Increment(ref count);

                string sammout;
                try
                {
                    long tx = ethereumService.GetTransactionCount(endAddress, BlockTag.Latest);
                    if (tx == 0)
                    {
                        return;
                    }

                    BigInteger ammout = ethereumService.GetBalance(endAddress, BlockTag.Latest);

                    sammout = ammout.ToString();
                    Interlocked.Increment(ref have);
                }
                catch (Exception ex)
                {
                    sammout = "ERROR " + ex.Message;
                }

                lock (console)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("[" + endAddress + "] ");
                    Console.ForegroundColor = sammout.StartsWith("ERROR ") ? ConsoleColor.Red : ConsoleColor.Yellow;
                    Console.WriteLine(sammout);
                }
            });

            // END

            lock (console)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                Console.WriteLine("*****************************************");
                Console.WriteLine("Checked accounts [" + count + "] ");
                Console.WriteLine("Accounts with balance [" + have + "] ");
            }
        }
Example #29
0
        private void button1_Click(object sender, EventArgs e)
        {
            var tx = EthereumService.GetTransactionByHash(txtTransactionHash.Text);

            int i = 100;
        }
 public EthereumLikePaymentMethodHandler(BTCPayNetworkProvider networkProvider, EthereumService ethereumService)
 {
     _networkProvider = networkProvider;
     _ethereumService = ethereumService;
 }