Example #1
0
        public void CreateHigherLevelBlock(object source, ElapsedEventArgs e)
        {
            if (bank.s_LowerLevelBlockPool.Count == 0)
                return;
            //Construct high level block
            HigherLevelBlock block = new HigherLevelBlock();
            block.LowLevelBlockCounter = 0;

            //Construct the block header
            //block.blockHeader.hashPrevBlock = GetPreviousTransactionHash();
            block.blockHeader.Time = GetTime(DateTime.Now);
            block.blockHeader.Version = bank.version;

            while (bank.s_LowerLevelBlockPool.Count != 0 && block.LowLevelBlockCounter < MAX_LOWERLEVELBLOCK)
            {
                LowerLevelBlock llb = bank.s_LowerLevelBlockPool.Dequeue();
                if (CheckingLedger(llb) == true)
                {
                    block.LowerLevelBlockSet.Add(llb);
                    block.LowLevelBlockCounter++;
                }
            }

            //Add the hash & size of this block
            block.Hash = CryptoHelper.Hash(JsonHelper.Serialize(block));
            block.blockSize = Marshal.SizeOf(block);

            //TODO: Call api to send ACK message to Issuer
        }
Example #2
0
 public HigherLevelBlock AddHigherLevelBlock(HigherLevelBlock newHigherLevelBlock)
 {
     var result = QueryStoreProcedure("AddLowerLevelBlock", new Dictionary<string, object>
                                                 {
                                                     {"@blockSize", newHigherLevelBlock.blockSize },
                                                     {"@blockHeader", newHigherLevelBlock.blockHeader },
                                                     {"@LowerLevelBlockSet", newHigherLevelBlock.LowerLevelBlockSet },
                                                     {"@period", newHigherLevelBlock.Period },
                                                     {"@hash", newHigherLevelBlock.Hash },
                                                     {"@signature", newHigherLevelBlock.Signature },
                                                 });
     if (result.Tables[0].Rows.Count > 0)
     {
         var hlb = new HigherLevelBlock().FromRow(result.Tables[0].Rows[0]);
         return hlb;
     }
     return null;
 }
Example #3
0
        /// <summary>
        /// Verify HigherLevelBlock
        /// </summary>
        /// <param name="block"></param>
        /// <param name="hashPrev"></param>
        /// <param name="publicKey">PublicKey of the bank.</param>
        /// <returns></returns>
        public static bool VerifyHigherLevelBlock(HigherLevelBlock block, string hashPrev, string publicKey)
        {
            string hash = CryptoHelper.Hash(hashPrev + JsonHelper.Serialize(block.LowerLevelBlockSet[0].TransactionSet));

            if (block.Hash == hash)
            {
                return CryptoHelper.Verify(publicKey, hash, block.Signature);
            }

            return false;
        }