Esempio n. 1
0
 public CBlock(CHeader Header, Transaction Transaction, ulong Nonce, DateTime Timestamp, ushort Difficulty)
 {
     this.Header = Header;
     this.Transactions.Add(Transaction);
     this.Nonce      = Nonce;
     this.Timestamp  = Timestamp;
     this.Difficulty = Difficulty;
 }
Esempio n. 2
0
 public CGenesisBlock()
 {
     this.Difficulty   = 1;
     Header            = new CHeader(0, "GENESISBLOCK", "");
     this.Transactions = new List <Transaction>();
     this.Nonce        = 0;
     this.Timestamp    = new DateTime(1, 1, 1);
 }
Esempio n. 3
0
 public CBlock(ulong numBlock, string previusBlockHash, ushort difficulty, int txLimit)
 {
     this.Transactions = new List <Transaction>();
     this.Transactions.Add(new CoinbaseTransaction(CServer.rsaKeyPair));
     this.Transactions.AddRange(MemPool.Instance.GetUTX(txLimit - 1));
     this.GenerateMerkleRoot();
     Header          = new CHeader(numBlock, previusBlockHash);
     this.Difficulty = difficulty;
     this.Nonce      = 0;
 }
Esempio n. 4
0
 //public CBlock(ulong NumBlock, string Hash, string PreviusBlockHash, string Transiction, ulong Nonce, DateTime Timestamp, ushort Difficulty)
 public CBlock(ulong NumBlock, string Hash, string PreviusBlockHash, int TxLimit, ulong Nonce, DateTime Timestamp, ushort Difficulty, List <Transaction> transactions)
 {
     Header            = new CHeader(NumBlock, Hash, PreviusBlockHash);
     this.TxLimit      = TxLimit;
     this.Transactions = transactions;
     this.GenerateMerkleRoot();
     this.Nonce      = Nonce;
     this.Timestamp  = Timestamp;
     this.Difficulty = Difficulty;
 }
Esempio n. 5
0
        public CHeader[] DistribuiteDownloadHeaders(ulong initialIndex, ulong finalIndex, CPeer[] Peers = null)
        {
            if (finalIndex < initialIndex)
            {
                return(new CHeader[0]);
            }
            if (Peers == null)
            {
                Peers = mPeers;
            }
            ulong          module = 0, rangeDim = 10, totalHeaders = finalIndex - initialIndex;
            Queue <Thread> threadQueue       = new Queue <Thread>();
            Queue <CRange> queueRange        = new Queue <CRange>();
            ulong          rangeInitialIndex = initialIndex;

            CHeader[] ris = new CHeader[totalHeaders];
            foreach (CPeer p in Peers)
            {
                if (p != null)
                {
                    threadQueue.Enqueue(new Thread(new ParameterizedThreadStart(DownloadHeaders)));
                }
            }

            //creazione gruppi di blocchi
            //(!) genera 1-10/11-20 p 1-10/10-20? è giusto il secondo
            //1-10 scarica i blocchi dall'1 compreso al 10 non compreso(1-2-3-4-5-6-7-8-9)
            module = totalHeaders % rangeDim;
            queueRange.Enqueue(new CRange(finalIndex - module, finalIndex));
            finalIndex -= module;
            while (rangeInitialIndex < finalIndex)
            {
                queueRange.Enqueue(new CRange(rangeInitialIndex, rangeInitialIndex += rangeDim));
            }

            //creazione ed avvio thread
            //(!) si blocca se qualcuno si disconnette mentre fa il ciclo credo(perchè un thread non farà mai finire il join)
            foreach (CPeer p in Peers)
            {
                if (p != null)
                {
                    threadQueue.Peek().Start(new object[] { p, queueRange, ris, initialIndex });
                    threadQueue.Peek().Name = "DownloadHeaders " + p.IP;
                    threadQueue.Enqueue(threadQueue.Dequeue());
                }
            }

            while (threadQueue.Count > 0)
            {
                threadQueue.Dequeue().Join();
            }

            return(ris);
        }
Esempio n. 6
0
        public CHeader[] RetriveHeaders(ulong initialIndex, ulong finalIndex)
        {
            CHeader[] ris = new CHeader[finalIndex - initialIndex];
            int       c   = 0;

            while (initialIndex < finalIndex)
            {
                ris[c++] = RetriveBlock(initialIndex).Header;
                initialIndex++;
            }
            return(ris);
        }