code: func (msg *MsgTx) PkScriptLocs() []int {
  	numTxOut := len(msg.TxOut)
  	if numTxOut == 0 {
  		return nil
  	}
  
  	// The starting offset in the serialized transaction of the first
  	// transaction output is:
  	//
  	// Version 4 bytes + serialized varint size for the number of
  	// transaction inputs and outputs + serialized size of each transaction
  	// input.
  	n := 4 + VarIntSerializeSize(uint64(len(msg.TxIn))) +
  		VarIntSerializeSize(uint64(numTxOut))
  
  	// If this transaction has a witness input, the an additional two bytes
  	// for the marker, and flag byte need to be taken into account.
  	if len(msg.TxIn) > 0 && msg.TxIn[0].Witness != nil {
  		n += 2
  	}
  
  	for _, txIn := range msg.TxIn {
  		n += txIn.SerializeSize()
  	}
  
  	// Calculate and set the appropriate offset for each public key script.
  	pkScriptLocs := make([]int, numTxOut)
  	for i, txOut := range msg.TxOut {
  		// The offset of the script in the transaction output is:
  		//
  		// Value 8 bytes + serialized varint size for the length of
  		// PkScript.
  		n += 8 + VarIntSerializeSize(uint64(len(txOut.PkScript)))
  		pkScriptLocs[i] = n
  		n += len(txOut.PkScript)
  	}
  
  	return pkScriptLocs
  }
docs: // PkScriptLocs returns a slice containing the start of each public key script
  // within the raw serialized transaction.  The caller can easily obtain the
  // length of each script by using len on the script available via the
  // appropriate transaction output entry.