garethjns / PyBC

Bitcoin blockchain parser for Python 2 and 3. Includes handy examples.
BSD 3-Clause "New" or "Revised" License
29 stars 17 forks source link

Hash calculated incorrectly for transactions #4

Open garethjns opened 5 years ago

garethjns commented 5 years ago

In transaction class, hash is calculated from incomplete header that contains only the first input and output. This needs to be updated to handle all inputs and outputs.

from pybt.py3.block.Transaction:

    def prep_header(self) -> bytes:
        """Return transaction header bytes.
        Only works for single input and output transactions for now
        """
        header = self._version \
            + self._nInputs \
            + self.txIn[0]._prevOutput \
            + self.txIn[0]._prevIndex \
            + self.txIn[0]._scriptLength \
            + self.txIn[0]._scriptSig \
            + self.txIn[0]._sequence \
            + self._nOutputs \
            + self.txOut[0]._value \
            + self.txOut[0]._pkScriptLen \
            + self.txOut[0]._pkScript \
            + self._lockTime

        return header