public void StorageData(BlockByNumberDto input)
 {
     if (input != null)
     {
         lock (_blockInfoQueue)
         {
             _blockInfoQueue.Enqueue(input);
             Console.WriteLine($"区块高度:{new HexBigInteger(input.Number).Value},存入区块数据为:{ _blockInfoQueue.Dequeue().ToString().ToObject<BlockByNumberDto>().Hash}");
             Console.WriteLine("-----------------------------------------------------------");
             Thread.Sleep(1000);
         }
         if (input.Transactions != null)
         {
             var tempList = input.Transactions.ToList();
             for (int i = 0; i < tempList.Count; i++)
             {
                 lock (_transcationInfoQueue)
                 {
                     _transcationInfoQueue.Enqueue(tempList[i]);
                     Console.WriteLine($"存入交易数据为:{ _transcationInfoQueue.Dequeue().ToJson()}");
                     Console.WriteLine("-----------------------------------------------------------");
                     Thread.Sleep(1000);
                 }
             }
         }
     }
 }
示例#2
0
        public void StorageData(BlockByNumberDto input)
        {
            if (input != null)
            {
                db.HashSet(new RedisKey("BlockNumberInfo"), long.Parse(new HexBigInteger(input.Number).Value.ToString()), input.ToJson());//将当前区块存入指定的数据库
                Console.WriteLine($"区块高度:{new HexBigInteger(input.Number).Value},存入区块数据为:{db.HashGet(new RedisKey("BlockNumberInfo"), long.Parse(new HexBigInteger(input.Number).Value.ToString())).ToString().ToObject<BlockByNumberDto>().Hash }");
                Console.WriteLine("-----------------------------------------------------------");
                Thread.Sleep(1000);
            }

            if (input.Transactions != null)
            {
                var tempList = input.Transactions.ToList();
                for (int i = 0; i < tempList.Count; i++)
                {
                    db.HashSet(new RedisKey("TranscationInfo"), tempList[i].Hash, tempList[i].ToJson());
                    Console.WriteLine($"存入交易数据为:{ db.HashGet(new RedisKey("TranscationInfo"), tempList[i].Hash)}");
                    Console.WriteLine("-----------------------------------------------------------");
                    if (sub != null)
                    { //发布订阅的pub
                        sub.Publish("RedisTranscationInfoSub", tempList[i].ToJson());
                    }
                    Thread.Sleep(1000);
                }
            }
        }