示例#1
0
        protected APIResultCodes VerifyBlock(TransactionBlock block, TransactionBlock previousBlock)
        {
            if (NodeGlobalParameters.Network_Id != block.NetworkId)
            {
                return(APIResultCodes.InvalidNetworkId);
            }

            if (!block.IsBlockValid(previousBlock))
            {
                return(APIResultCodes.BlockValidationFailed);
            }

            //if (!Signatures.VerifySignature(block.Hash, block.AccountID, block.Signature))
            //    return APIResultCodes.BlockSignatureValidationFailed;

            if (!block.VerifySignature(block.AccountID))
            {
                return(APIResultCodes.BlockSignatureValidationFailed);
            }

            // check if this Index already exists (double-spending, kind of)
            if (_accountCollection.FindBlockByIndex(block.AccountID, block.Index) != null)
            {
                return(APIResultCodes.BlockWithThisIndexAlreadyExists);
            }

            // This is the double-spending check for send block!
            if (!string.IsNullOrEmpty(block.PreviousHash) && _accountCollection.FindBlockByPreviousBlockHash(block.PreviousHash) != null)
            {
                return(APIResultCodes.BlockWithThisPreviousHashAlreadyExists);
            }

            if (block.Index <= 0)
            {
                return(APIResultCodes.InvalidIndexSequence);
            }

            if (block.Index > 1 && previousBlock == null)
            {
                return(APIResultCodes.CouldNotFindLatestBlock);
            }

            if (block.Index == 1 && previousBlock != null)
            {
                return(APIResultCodes.InvalidIndexSequence);
            }

            if (previousBlock != null && block.Index != previousBlock.Index + 1)
            {
                return(APIResultCodes.InvalidIndexSequence);
            }

            if (!ValidateRenewalDate(block, previousBlock))
            {
                return(APIResultCodes.TokenExpired);
            }

            return(APIResultCodes.Success);
        }
 public TransactionBlock FindBlockByPreviousBlockHash(string previousBlockHash) => _store.FindBlockByPreviousBlockHash(previousBlockHash);