Ejemplo n.º 1
0
        private int GetFirstBlockNumberForDate(DateTime workDate)
        {
            double averageBlockTime = this.GetAverageBlockTime();

            Business.EthBlock latestBlock          = this.m_GethAPI.GetLatestBlock();
            double            secondsInADay        = 86400;
            double            days                 = (DateTime.Today - workDate).TotalDays;
            double            numberOfBlocksInADay = secondsInADay / averageBlockTime;

            return(Convert.ToInt32(latestBlock.Number - (numberOfBlocksInADay * days)));
        }
Ejemplo n.º 2
0
        private double GetAverageBlockTime()
        {
            Business.EthBlock latestBlock = this.m_GethAPI.GetLatestBlock();
            List <double>     blockTimes  = new List <double>();

            Business.EthBlock lastBlock = this.m_GethAPI.GetBlockByNumber(latestBlock.Number - 100);
            for (int i = latestBlock.Number - 99; i < latestBlock.Number; i++)
            {
                Business.EthBlock thisBlock = this.m_GethAPI.GetBlockByNumber(i);
                blockTimes.Add(thisBlock.TimeStamp.Subtract(lastBlock.TimeStamp).TotalSeconds);
                lastBlock = thisBlock;
            }

            return(blockTimes.Average());
        }
Ejemplo n.º 3
0
        private void LoopTheChain()
        {
            Business.EthBlock latestBlock = this.m_GethAPI.GetLatestBlock();
            int startingBlockNumber       = this.GetFirstBlockNumberForDate(DateTime.Today.AddDays(-2));

            for (int i = startingBlockNumber; i < latestBlock.Number; i++)
            {
                int transactionCount = this.m_GethAPI.GetBlockTransactionCountByNumber(i);
                if (transactionCount > 0)
                {
                    Business.EthBlock block = this.m_GethAPI.GetBlockByNumber(i);
                    foreach (string transactionHash in block.TransactionHashes)
                    {
                        string contractAddress = this.m_GethAPI.GetContractAddress(transactionHash);
                        if (string.IsNullOrEmpty(contractAddress) == false)
                        {
                            int containerCount            = this.m_GethAPI.GetContainerCount(contractAddress);
                            Business.EthContract contract = new Business.EthContract(contractAddress, containerCount, block.TimeStamp);
                            this.m_ContractCollection.Add(contract);
                        }
                    }
                }
            }
        }