code: func calcHashPrevOuts(tx *wire.MsgTx) chainhash.Hash {
  	var b bytes.Buffer
  	for _, in := range tx.TxIn {
  		// First write out the 32-byte transaction ID one of whose
  		// outputs are being referenced by this input.
  		b.Write(in.PreviousOutPoint.Hash[:])
  
  		// Next, we'll encode the index of the referenced output as a
  		// little endian integer.
  		var buf [4]byte
  		binary.LittleEndian.PutUint32(buf[:], in.PreviousOutPoint.Index)
  		b.Write(buf[:])
  	}
  
  	return chainhash.DoubleHashH(b.Bytes())
  }
docs: // calcHashPrevOuts calculates a single hash of all the previous outputs
  // (txid:index) referenced within the passed transaction. This calculated hash
  // can be re-used when validating all inputs spending segwit outputs, with a
  // signature hash type of SigHashAll. This allows validation to re-use previous
  // hashing computation, reducing the complexity of validating SigHashAll inputs
  // from  O(N^2) to O(N).