@ -1168,9 +1168,13 @@ uint256 GetOutputsHash(const CTransaction& txTo) {
PrecomputedTransactionData : : PrecomputedTransactionData ( const CTransaction & txTo )
PrecomputedTransactionData : : PrecomputedTransactionData ( const CTransaction & txTo )
{
{
// Cache is calculated only for transactions with witness
if ( txTo . HasWitness ( ) ) {
hashPrevouts = GetPrevoutHash ( txTo ) ;
hashPrevouts = GetPrevoutHash ( txTo ) ;
hashSequence = GetSequenceHash ( txTo ) ;
hashSequence = GetSequenceHash ( txTo ) ;
hashOutputs = GetOutputsHash ( txTo ) ;
hashOutputs = GetOutputsHash ( txTo ) ;
ready = true ;
}
}
}
uint256 SignatureHash ( const CScript & scriptCode , const CTransaction & txTo , unsigned int nIn , int nHashType , const CAmount & amount , SigVersion sigversion , const PrecomputedTransactionData * cache )
uint256 SignatureHash ( const CScript & scriptCode , const CTransaction & txTo , unsigned int nIn , int nHashType , const CAmount & amount , SigVersion sigversion , const PrecomputedTransactionData * cache )
@ -1181,18 +1185,19 @@ uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsig
uint256 hashPrevouts ;
uint256 hashPrevouts ;
uint256 hashSequence ;
uint256 hashSequence ;
uint256 hashOutputs ;
uint256 hashOutputs ;
const bool cacheready = cache & & cache - > ready ;
if ( ! ( nHashType & SIGHASH_ANYONECANPAY ) ) {
if ( ! ( nHashType & SIGHASH_ANYONECANPAY ) ) {
hashPrevouts = cache ? cache - > hashPrevouts : GetPrevoutHash ( txTo ) ;
hashPrevouts = cacheready ? cache - > hashPrevouts : GetPrevoutHash ( txTo ) ;
}
}
if ( ! ( nHashType & SIGHASH_ANYONECANPAY ) & & ( nHashType & 0x1f ) ! = SIGHASH_SINGLE & & ( nHashType & 0x1f ) ! = SIGHASH_NONE ) {
if ( ! ( nHashType & SIGHASH_ANYONECANPAY ) & & ( nHashType & 0x1f ) ! = SIGHASH_SINGLE & & ( nHashType & 0x1f ) ! = SIGHASH_NONE ) {
hashSequence = cache ? cache - > hashSequence : GetSequenceHash ( txTo ) ;
hashSequence = cacheready ? cache - > hashSequence : GetSequenceHash ( txTo ) ;
}
}
if ( ( nHashType & 0x1f ) ! = SIGHASH_SINGLE & & ( nHashType & 0x1f ) ! = SIGHASH_NONE ) {
if ( ( nHashType & 0x1f ) ! = SIGHASH_SINGLE & & ( nHashType & 0x1f ) ! = SIGHASH_NONE ) {
hashOutputs = cache ? cache - > hashOutputs : GetOutputsHash ( txTo ) ;
hashOutputs = cacheready ? cache - > hashOutputs : GetOutputsHash ( txTo ) ;
} else if ( ( nHashType & 0x1f ) = = SIGHASH_SINGLE & & nIn < txTo . vout . size ( ) ) {
} else if ( ( nHashType & 0x1f ) = = SIGHASH_SINGLE & & nIn < txTo . vout . size ( ) ) {
CHashWriter ss ( SER_GETHASH , 0 ) ;
CHashWriter ss ( SER_GETHASH , 0 ) ;
ss < < txTo . vout [ nIn ] ;
ss < < txTo . vout [ nIn ] ;