Esempio n. 1
0
        private void LoginButtonClicked(object sender, RoutedEventArgs e)
        {
            string address = AddressComboBox.Text;;
            string hashPw  = Sha.GenerateSha256String(PasswordBox1.Password);

            //check Private key and public Key
            var walletBank = new WalletBank();
            var wallet     = walletBank.FindWallet(address, hashPw);

            if (wallet == null)
            {
                Errormessage.Text = "First import your wallet";
                return;
            }

            if (!wallet.IsValid())
            {
                Errormessage.Text = "Wallet isn't valid";
                return;
            }

            //check inside DB
            var context = new UserContext();
            var user    = context.Users.FirstOrDefault(n => n.Address == address && n.Password == hashPw);

            if (user != null)
            {
                NavigationService?.Navigate(new WalletPage(user));
            }
            else
            {
                Errormessage.Text = "Passwords doesn't match or connection is lost";
            }
        }
Esempio n. 2
0
        //ver1
        public static Transaction NewTransaction(string from, string to, int amount, UTXOSet set)
        {
            var inputs  = new List <TxInput>();
            var outputs = new List <TxOutput>();

            var walletBank = new WalletBank();
            var wallet     = walletBank.FindWallet(from);
            var pubKeyHash = wallet.PublicKeyHash;

            var spendableOutputs = set.FindSpendableOutputs(pubKeyHash, amount);
            var account          = spendableOutputs.Item2;
            var validOutputs     = spendableOutputs.Item1;

            if (account < amount)
            {
                Console.WriteLine("Insufficient funds");
                return(null);
            }
            else
            {
                foreach (var output in validOutputs.Keys)
                {
                    var txId = (output);

                    if (validOutputs.ContainsKey(txId))
                    {
                        foreach (var @out in validOutputs[txId])
                        {
                            var input = new TxInput()
                            {
                                Id = HexadecimalEncoding.FromHexStringToByte(txId), Out = @out, Signature = null, PubKey = wallet.PublicKey
                            };
                            inputs.Add(input);
                        }
                    }
                }

                outputs.Add(TxOutput.NewTxOutput(amount, to));

                if (account > amount)
                {
                    outputs.Add(TxOutput.NewTxOutput(account - amount, from));
                }
            }

            var tx = new Transaction()
            {
                Id        = null,
                Inputs    = inputs,
                Outputs   = outputs,
                TimeStamp = DateTime.Now
            };

            tx.Id = tx.CalculateHash();
            set.Chain.SignTransaction(tx, wallet.PrivateKey);
            return(tx);
        }
Esempio n. 3
0
        public WalletPage(User user)
        {
            InitializeComponent();
            InitializeLogger();
            TryCreateShortcut(); // create shortcut, so i will be able to show toasts

            //INITIALIZE CHAIN, ETC
            _loggedUser = user;
            var bank = new WalletBank();

            _loggedUserWallet = bank.FindWallet(user.Address);
            _friChain         = new BlockChain(LayerBlockchainNetwork.GetIpAddress());

            //REGISTER CLOSING EVENET
            Application.Current.MainWindow.Closing += new CancelEventHandler(AppClosing);

            //SET GUI PROPERTIES
            InitializeProfile();
            UpdateBalance();
            UpdateRawChain();
            UpdatePeerList();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var startTime = DateTime.Now;

            //var wBank = new WalletBank();

            //for (var i = 0; i < 100; i++) wBank.CreateWallet();


            //foreach (var wallet in wBank)
            //{
            //    var isOk = wallet.VerifyAddress(wallet.Address);
            //    Console.WriteLine(isOk);
            //}


            //var blockChain = new BlockChain();
            //blockChain.Print();


            //var txList = new List<Transaction>();
            //for(var i = 0; i<10000; i++) {
            //Transaction tx1 = new Transaction()
            //{
            //   Id = null,
            //   Inputs = new List<TxInput>()
            //   {
            //       new TxInput() {
            //           Id = new byte[] {},
            //           PubKey = new byte[]{0x01},
            //           Out = i
            //       }
            //   } ,
            //   Outputs = new List<TxOutput>() { new TxOutput()
            //   {
            //       Value = i,
            //   } }
            //};
            //tx1.CalculateHash();

            //    txList.Add(tx1);
            //}

            //var  merkleTree = new MerkleTree(txList);
            //merkleTree.LevelOrder();

            var list = new List <Transaction>();

            var bank = new WalletBank();
            var _loggedUserWallet = bank.FindWallet("112H2TcYAvxWGPSWXz4bzGvm5RXEdFDCms");
            var _friChain         = new BlockChain("x");
            var utxoSet           = new UTXOSet(_friChain);

            for (int i = 0; i < 20; i++)
            {
                var tx = Transaction.NewTransaction("112H2TcYAvxWGPSWXz4bzGvm5RXEdFDCms", "1fp9JwtnMMnYVLaABMEQuKGtpXUnJm7Cz", 2, utxoSet);
                if (tx == null)
                {
                    return;
                }
                list.Add(tx);
            }

            var block = _friChain.MineBlock(list);

            utxoSet.Update(block);
            _friChain.GetBalance("112H2TcYAvxWGPSWXz4bzGvm5RXEdFDCms");

            var endTime = DateTime.Now;

            Console.WriteLine($"Duration: {endTime - startTime}");
            Console.Read();
        }