internal CheckPointBlock(Stream stream)
 {
     using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
     {
         BlockNumber = br.ReadUInt32();
         AccountKey  = new ECKeyPair();
         AccountKey.LoadFromStream(stream, false);
         Reward            = br.ReadUInt64();
         Fee               = br.ReadUInt64();
         ProtocolVersion   = br.ReadUInt16();
         AvailableProtocol = br.ReadUInt16();
         Timestamp         = br.ReadUInt32();
         CompactTarget     = br.ReadUInt32();
         Nonce             = br.ReadInt32();
         ushort len = br.ReadUInt16();
         Payload         = br.ReadBytes(len);
         len             = br.ReadUInt16();
         CheckPointHash  = br.ReadBytes(len);
         len             = br.ReadUInt16();
         TransactionHash = br.ReadBytes(len);
         len             = br.ReadUInt16();
         ProofOfWork     = br.ReadBytes(len);
         for (int i = 0; i < 5; i++)
         {
             Account acc = new Account(stream);
             Accounts.Add(acc);
         }
         BlockHash       = Hash.ReadFromStream(br);
         AccumulatedWork = br.ReadUInt64();
     }
 }
Example #2
0
        private void importKeys_ItemClick(object sender, ItemClickEventArgs e)
        {
            using (var openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter          = keyfilefilter;
                openFileDialog.CheckFileExists = true;
                openFileDialog.Multiselect     = false;
                if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    var walletKeys = new List <ECKeyPair>();
                    using (var fs = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        while (fs.Position < fs.Length - 1)
                        {
                            var keyPair = new ECKeyPair();
                            keyPair.LoadFromStream(fs, false, true, true);
                            walletKeys.Add(keyPair);
                        }

                        Node.Keys.Clear();
                        Node.Keys = walletKeys;
                        XtraMessageBox.Show($"Sikeresen importáltunk {walletKeys.Count} kulcsot!", "Importálás",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
        public override void LoadFromStream(Stream s)
        {
            using (BinaryReader br = new BinaryReader(s, Encoding.Default, true))
            {
                SignerAccount = br.ReadUInt32();
                switch (TransactionType)
                {
                case TransactionType.ChangeKey:
                    TargetAccount = SignerAccount;
                    break;

                case TransactionType.ChangeKeySigned:
                    TargetAccount = br.ReadUInt32();
                    break;
                }

                NumberOfOperations = br.ReadUInt32();
                Fee        = br.ReadUInt64();
                Payload    = ByteString.ReadFromStream(br);
                AccountKey = new ECKeyPair();
                AccountKey.LoadFromStream(s, false);
                NewAccountKey = new ECKeyPair();
                NewAccountKey.LoadFromStream(s);
                Signature = new ECSignature(s);
            }
        }
Example #4
0
 public void LoadFromStream(Stream stream)
 {
     using (BinaryReader br = new BinaryReader(stream, Encoding.ASCII, true))
     {
         ServerPort = br.ReadUInt16();
         AccountKey = new ECKeyPair();
         AccountKey.LoadFromStream(stream);
         Timestamp   = br.ReadUInt32();
         Block       = new Block(stream);
         NodeServers = NodeServerList.LoadFromStream(stream, ServerPort);
         Version     = ByteString.ReadFromStream(br);
         WorkSum     = br.ReadUInt64();
     }
 }
Example #5
0
 public override void LoadFromStream(Stream stream)
 {
     using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
     {
         SignerAccount      = br.ReadUInt32();
         TargetAccount      = br.ReadUInt32();
         NumberOfOperations = br.ReadUInt32();
         Fee        = br.ReadUInt64();
         Payload    = ByteString.ReadFromStream(br);
         AccountKey = new ECKeyPair();
         AccountKey.LoadFromStream(stream, false);
         ChangeType    = br.ReadByte();
         NewAccountKey = new ECKeyPair();
         NewAccountKey.LoadFromStream(stream, false);
         NewName   = ByteString.ReadFromStream(br);
         NewType   = br.ReadUInt16();
         Signature = new ECSignature(stream);
     }
 }
Example #6
0
 internal BlockBase(Stream s)
 {
     using (var br = new BinaryReader(s, Encoding.ASCII, true))
     {
         BlockSignature = br.ReadByte();
         if (BlockSignature > 0)
         {
             ProtocolVersion   = br.ReadUInt16();
             AvailableProtocol = br.ReadUInt16();
         }
         BlockNumber = br.ReadUInt32();
         AccountKey  = new ECKeyPair();
         AccountKey.LoadFromStream(s);
         Reward        = br.ReadUInt64();
         Fee           = br.ReadUInt64();
         Timestamp     = br.ReadUInt32();
         CompactTarget = br.ReadUInt32();
         Nonce         = br.ReadInt32();
         ushort pl = br.ReadUInt16();
         if (pl > 0)
         {
             Payload = br.ReadBytes(pl);
         }
         pl = br.ReadUInt16();
         if (pl > 0)
         {
             CheckPointHash = br.ReadBytes(pl);
         }
         pl = br.ReadUInt16();
         if (pl > 0)
         {
             TransactionHash = br.ReadBytes(pl);
         }
         pl = br.ReadUInt16();
         if (pl > 0)
         {
             ProofOfWork = br.ReadBytes(pl);
         }
     }
 }
Example #7
0
        public override void LoadFromStream(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream, Encoding.ASCII, true))
            {
                SignerAccount      = br.ReadUInt32();
                NumberOfOperations = br.ReadUInt32();
                TargetAccount      = br.ReadUInt32();
                Amount             = br.ReadUInt64();
                Fee        = br.ReadUInt64();
                Payload    = ByteString.ReadFromStream(br);
                AccountKey = new ECKeyPair();
                AccountKey.LoadFromStream(stream, false);
                //stream.Position -= 1;
                byte b = br.ReadByte();
                TransactionStyle = (TransferType)b;
                if (b > 2)
                {
                    stream.Position -= 1; TransactionStyle = TransferType.Transaction; TransactionType = TransactionType.Transaction;
                }
                if (b > 0 && b < 3)
                {
                    AccountPrice  = br.ReadUInt64();
                    SellerAccount = br.ReadUInt32();
                    NewAccountKey = new ECKeyPair();
                    NewAccountKey.LoadFromStream(stream, false);
                    switch (TransactionStyle)
                    {
                    case TransferType.BuyAccount: TransactionType = TransactionType.BuyAccount; break;

                    case TransferType.TransactionAndBuyAccount: TransactionType = TransactionType.BuyAccount; break;

                    default: TransactionType = TransactionType.Transaction; break;
                    }
                }
                Signature = new ECSignature(stream);
            }
        }
        public override void LoadFromStream(Stream s)
        {
            using (BinaryReader br = new BinaryReader(s, Encoding.Default, true))
            {
                SignerAccount      = br.ReadUInt32();
                TargetAccount      = br.ReadUInt32();
                TransactionType    = (TransactionType)br.ReadUInt16();
                NumberOfOperations = br.ReadUInt32();
                if (TransactionType == TransactionType.ListAccountForSale)
                {
                    AccountPrice = br.ReadUInt64();
                    AccountToPay = br.ReadUInt32();
                    AccountKey   = new ECKeyPair();
                    AccountKey.LoadFromStream(s, false);
                    NewPublicKey = new ECKeyPair();
                    NewPublicKey.LoadFromStream(s);
                    LockedUntilBlock = br.ReadUInt32();
                }

                Fee       = br.ReadUInt64();
                Payload   = ByteString.ReadFromStream(br);
                Signature = new ECSignature(s);
            }
        }
Example #9
0
        internal void LoadFromStream(BinaryReader br)
        {
            ushort unused         = br.ReadUInt16();
            ushort stateOrKeyType = br.ReadUInt16();

            switch (stateOrKeyType)
            {
            case (ushort)CurveType.Secp256K1:
            case (ushort)CurveType.Secp384R1:
            case (ushort)CurveType.Secp521R1:
            case (ushort)CurveType.Sect283K1:
                br.BaseStream.Position -= 2;
                State      = AccountState.Normal;
                AccountKey = new ECKeyPair();
                AccountKey.LoadFromStream(br.BaseStream, false);
                LockedUntilBlock  = 0;
                Price             = 0;
                AccountToPayPrice = 0;
                //NewPublicKey = new ECKeyPair();
                break;

            case 1000:
                State      = AccountState.Sale;
                AccountKey = new ECKeyPair();
                AccountKey.LoadFromStream(br.BaseStream, false);
                LockedUntilBlock  = br.ReadUInt32();
                Price             = br.ReadUInt64();
                AccountToPayPrice = br.ReadUInt32();
                NewPublicKey      = new ECKeyPair();
                NewPublicKey.LoadFromStream(br.BaseStream, false);
                break;

            default:
                throw new Exception("Invalid account info");
            }
        }
Example #10
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!Directory.Exists(Node.NetParams.DataDirectory))
            {
                Directory.CreateDirectory(Node.NetParams.DataDirectory);
            }
            string password = "";

            if (File.Exists(Node.NetParams.KeysFileName))
            {
                var fs = File.Open(Node.NetParams.KeysFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                using (var br = new BinaryReader(fs))
                {
                    if (fs.Length > 0)
                    {
                        var magic   = ByteString.ReadFromStream(br);
                        var version = br.ReadUInt32();
                        var count   = br.ReadUInt32();
                        for (var i = 0; i < count; i++)
                        {
                            var keyPair = new ECKeyPair();
                            keyPair.LoadFromStream(fs, false, true, true);
                            Keys.Add(keyPair);
                            if (version < 110)
                            {
                                while (true)
                                {
                                    try
                                    {
                                        keyPair.DecriptKey(password);
                                        break;
                                    }
                                    catch (Exception exception)
                                    {
                                        if (password == "")
                                        {
                                            password = Prompt.ShowDialog("Add meg a tárca jelszavát", "Jelszó szükséges");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (Keys.Count == 0)
            {
                var fs      = File.Open(Node.NetParams.KeysFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                var keyPair = ECKeyPair.CreateNew(false, DateTime.Now.ToString());
                Keys.Add(keyPair);
                using (BinaryWriter bw = new BinaryWriter(fs, Encoding.ASCII, true))
                {
                    ByteString magic = "WalletKeys";
                    magic.SaveToStream(bw);
                    bw.Write((uint)110);
                    bw.Write((uint)Keys.Count);
                    foreach (var key in Keys)
                    {
                        key.SaveToStream(fs, false, true, true);
                    }
                }
                fs.Dispose();
            }
            Node.Instance.NodeKey = Keys.First();
            Node.Instance.NodeServers.NodesChanged += (ob, ev) =>
            {
                Invoke((Action)(() =>
                {
                    var i = 0;
                    connectionCount.Caption = Node.Instance.NodeServers.Count.ToString();
                    connectionCount.SuperTip.Items.Clear();
                    foreach (var nodeServer in Node.Instance.NodeServers)
                    {
                        connectionCount.SuperTip.Items.Add(nodeServer.Value.EndPoint.ToString()).Image =
                            Resources.network_connect;
                        i++;
                    }

                    if (i > Node.Instance.NodeServers.Count)
                    {
                        i = 0;
                    }
                }));
            };
            Node.Instance.BlockDownloadProgress += (o, ev) =>
            {
                Invoke((Action)(() =>
                {
                    progressBar.Caption = "Blokklánc";
                    progressPanel.Description = "Blokklánc letöltése";
                    repositoryItemProgressBar1.Maximum = ev.BlocksToDownload;
                    progressBar.EditValue = ev.DownloadedBlocks;
                }));
            };
            CheckPoints.CheckPointBuilding += (oo, ee) =>
            {
                Invoke((Action)(() =>
                {
                    progressBar.Caption = "Checkpointok";
                    progressPanel.Description = "Checkpointok számítása";
                    repositoryItemProgressBar1.Maximum = ee.BlocksNeeded;
                    progressBar.EditValue = ee.BlocksDone;
                }));
            };

            ribbon.Enabled      = false;
            transaction.Enabled = false;
            Task.Run(async() =>
            {
                var node = await Node.Instance.StartNode(Keys);
                if (node == null)
                {
                    return;
                }
                Invoke((Action)(() =>
                {
                    ribbon.Enabled = true;
                    transaction.Enabled = true;
                    progressPanel.Visible = false;
                }));

                Action action = () =>
                {
                    //repositoryItemMarqueeProgressBar1.Paused = true;
                    accountBindingSource.DataSource = Node.Instance.Accounts.Where(p => Keys.Contains(p.AccountInfo.AccountKey));

                    var myAccounts      = Node.Instance.Accounts.Where(p => Keys.Contains(p.AccountInfo.AccountKey));
                    accountCount.Text   = myAccounts.Count().ToString("N0") + " db";
                    currentBalance.Text = myAccounts.Sum(p => p.VisibleBalance).ToString("N") + " " + Node.NetParams.CoinTicker;
                    var timer           = new Timer
                    {
                        Interval = 5000
                    };
                    timer.Tick += (o, ev) =>
                    {
                        var lastBlock         = Node.Instance.BlockChain.GetLastBlock();
                        lastBlockTime.Caption = "Utolsó blokk " + Math.Round(DateTime.Now.Subtract(lastBlock.Timestamp).TotalMinutes).ToString() + " perce";
                        minerCount.Caption    = $"{Node.Instance.MinerServer.Clients.Count} bányászó kliens";
                        difficulty.Caption    = Node.Instance.BlockChain.GetNewTarget().Item2.ToString("X");
                    };
                    timer.Enabled = true;
                };
                Invoke(action);
            });
        }