예제 #1
0
    def Verify(self, completely=False):

        self.__log.debug("Verifying BLOCK!!")
        from neo.Blockchain import GetBlockchain,GetConsensusAddress

        res = super(Block, self).Verify()
        if not res: return False

        #first TX has to be a miner transaction. other tx after that cant be miner tx
        if self.Transactions[0].Type != TransactionType.MinerTransaction: return False
        for tx in self.Transactions[1:]:
            if tx.Type == TransactionType.MinerTransaction: return False


        if completely:
            bc = GetBlockchain()

            if self.NextConsensus != GetConsensusAddress(bc.GetValidators(self.Transactions).ToArray()):
                return False
            
            for tx in self.Transactions:
                if not tx.Verify():
                    pass
            self.__log.debug("Blocks cannot be fully validated at this moment.  please pass completely=False")
            raise NotImplementedError()
            ## do this below!
            #foreach(Transaction tx in Transactions)
            #if (!tx.Verify(Transactions.Where(p = > !p.Hash.Equals(tx.Hash)))) return false;
            #Transaction tx_gen = Transactions.FirstOrDefault(p= > p.Type == TransactionType.MinerTransaction);
            #if (tx_gen?.Outputs.Sum(p = > p.Value) != CalculateNetFee(Transactions)) return false;

        return True
            
            
예제 #2
0
파일: Block.py 프로젝트: yodash/neo-python
    def Verify(self, completely=False):
        """
        Verify the integrity of the block.

        Args:
            completely: (Not functional at this time).

        Returns:
            bool: True if valid. False otherwise.
        """
        res = super(Block, self).Verify()
        if not res:
            return False

        from neo.Blockchain import GetBlockchain, GetConsensusAddress

        # first TX has to be a miner transaction. other tx after that cant be miner tx
        if self.Transactions[0].Type != TransactionType.MinerTransaction:
            return False
        for tx in self.Transactions[1:]:
            if tx.Type == TransactionType.MinerTransaction:
                return False

        if completely:
            bc = GetBlockchain()

            if self.NextConsensus != GetConsensusAddress(
                    bc.GetValidators(self.Transactions).ToArray()):
                return False

            for tx in self.Transactions:
                if not tx.Verify():
                    pass
            logger.error(
                "Blocks cannot be fully validated at this moment.  please pass completely=False"
            )
            raise NotImplementedError()
            # do this below!
            # foreach(Transaction tx in Transactions)
            # if (!tx.Verify(Transactions.Where(p = > !p.Hash.Equals(tx.Hash)))) return false;
            # Transaction tx_gen = Transactions.FirstOrDefault(p= > p.Type == TransactionType.MinerTransaction);
            # if (tx_gen?.Outputs.Sum(p = > p.Value) != CalculateNetFee(Transactions)) return false;

        return True