コード例 #1
0
 public static void WriteDataCoinPocket(CoinPocket pocket)
 {
     Console.WriteLine("______Welcome to wallet!______\n");
     Console.WriteLine("Your wallet is: {0}",
                       HexConvert.FromBytes(pocket.KeyPair.PublicKey));
     Console.WriteLine("On your account: {0} ACT", pocket.Amount);
 }
        public WindowPersonalArea(CoinPocket user)
        {
            InitializeComponent();

            _userCoinPocket = user;
            GroupBoxInformationAboutUser.Header = user.UserName;
            TextBlockId.Text = HexConvert.FromBytes(user.KeyPair.PublicKey);

            var blockchain = DataManager.UploadBlockchainDictionary();

/*            var amount = int.Parse(Executor
 *              .GetCash(DataManager.UploadBlockchainDictionary(), user.KeyPair.PublicKey).ToString());*/

            var amount = int.Parse(Executor
                                   .GetCashRec(blockchain, user.KeyPair.PublicKey, blockchain.Last().Key).ToString());

            Amount = amount;

            if (amount > -1)
            {
                TextBlockAct.Text = amount + " @";
            }
            else
            {
                TextBlockAct.Text = "Fail parse blockchain.";
            }

            TextBoxRecipientId.Text = "";
            TextBoxAmountAct.Text   = "";
        }
コード例 #3
0
        protected void LinkButtonUploadMiningUser_Click(object sender, EventArgs e)
        {
            var selectedUser = DropDownList1.SelectedValue;
            var user         = DataManager.UploadUser(selectedUser);
            //TextArea1.Value = JsonConvert.SerializeObject(user, Formatting.Indented);

            var        receiver = new UdpClient(9999);
            IPEndPoint remoteIp = null;

            try
            {
                var data        = receiver.Receive(ref remoteIp);
                var transaction = MessagePackSerializer.Deserialize <Transaction>(data);

                var additionalOutEntry = new OutEntry()
                {
                    RecipientHash = user.KeyPair.PublicKey,
                    Value         = 10
                };

                transaction.OutEntries.Add(additionalOutEntry);

                var block = Mining.ComputeBlock(transaction);

                var chain = new KeyValuePair <string, Block>(
                    HexConvert.FromBytes(DataManager.UploadBlockchainDictionary().Last().Value.Hash),
                    block);

                DataManager.UpdateBlockchain(chain);

                Session["last chain"] = chain;

                Thread.Sleep(500);

                var senderUdpClient = new UdpClient();
                var message         = MessagePackSerializer.Serialize(chain);
                senderUdpClient.Send(
                    message,
                    message.Length,
                    "127.0.0.1",
                    remoteIp.Port);
                senderUdpClient.Close();
            }

            finally
            {
                var json = JsonConvert.SerializeObject(
                    (KeyValuePair <string, Block>)Session["last chain"], Formatting.Indented);
                receiver.Close();

                TextArea1.Value = json;
                //Label1.Text = json;
                //Label1.Text = json.ToJonHtml();
            }
        }
コード例 #4
0
        public void HexConvert_FromBytes_ToBytes_GoodResult()
        {
            //Arrange
            var hash       = Hash.ComputeSha256(new byte[0]);
            var hashstring = HexConvert.FromBytes(hash);
            var str        = hashstring;

            //Act

            //Assert
            Assert.AreEqual(hash, HexConvert.ToBytes(str));
        }
コード例 #5
0
        public static void ReceiveMessage()
        {
            var        receiver = new UdpClient(ReceiverPort); // UdpClient для получения данных
            IPEndPoint remoteIp = null;                        // Адрес входящего подключения

            try
            {
                while (true)
                {
                    var data = receiver.Receive(ref remoteIp); // Получаем данные
                    Console.WriteLine($"Собеседник: {HexConvert.FromBytes(data)}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                receiver.Close();
            }
        }
        private void ButtonUploadRecipient_Click(object sender, RoutedEventArgs e)
        {
            var user = DataManager.UploadUser();

            TextBoxRecipientId.Text = HexConvert.FromBytes(user.KeyPair.PublicKey);
        }
コード例 #7
0
        private static void Main(string[] args)
        {
            //var projetsJson = Controller.GetAllProjets();
            //Console.WriteLine(projetsJson);

            var tranz1 = new Transaction()
            {
                Amount        = 485,
                Comment       = "No comment",
                Instant       = DateTime.Now,
                TransactionId = HexConvert.FromBytes(Hash.ComputeSha256FromString("transactionId1"))
            };

            var tranz2 = new Transaction()
            {
                Amount        = 685,
                Comment       = "No comment",
                Instant       = DateTime.Now,
                TransactionId = HexConvert.FromBytes(Hash.ComputeSha256FromString("transactionId2"))
            };

            var categ1 = new Category()
            {
                CategoryId   = HexConvert.FromBytes(Hash.ComputeSha256FromString("categoryId1")),
                CategoryName = "My Category 1",
                Transactions = new List <Transaction>()
                {
                    tranz1
                },
            };

            var categ2 = new Category()
            {
                CategoryId   = HexConvert.FromBytes(Hash.ComputeSha256FromString("categoryId2")),
                CategoryName = "My Category 2",
                Transactions = new List <Transaction>()
                {
                    tranz1
                },
            };

            var categ3 = new Category()
            {
                CategoryId   = HexConvert.FromBytes(Hash.ComputeSha256FromString("categoryId3")),
                CategoryName = "My Category 3",
                Transactions = new List <Transaction>()
                {
                    tranz1
                },
            };

            var categ4 = new Category()
            {
                CategoryId   = HexConvert.FromBytes(Hash.ComputeSha256FromString("categoryId4")),
                CategoryName = "My Category 4",
                Transactions = new List <Transaction>()
                {
                    tranz1
                },
            };

            var project = new Project()
            {
                Categories = new List <Category>()
                {
                    categ1, categ2, categ3, categ4
                },
                ProjectBudget = 25000,
                ProjectId     = HexConvert.FromBytes(Hash.ComputeSha256FromString("projectId1")),
                ProjectName   = "My Project 1"
            };


            var jsonProject = JsonConvert.SerializeObject(project, Formatting.Indented);

            File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\SimpleMoneyDB.txt", jsonProject);
        }