code: func PayToAddrScript(addr btcutil.Address) ([]byte, error) {
  	const nilAddrErrStr = "unable to generate payment script for nil address"
  
  	switch addr := addr.(type) {
  	case *btcutil.AddressPubKeyHash:
  		if addr == nil {
  			return nil, scriptError(ErrUnsupportedAddress,
  				nilAddrErrStr)
  		}
  		return payToPubKeyHashScript(addr.ScriptAddress())
  
  	case *btcutil.AddressScriptHash:
  		if addr == nil {
  			return nil, scriptError(ErrUnsupportedAddress,
  				nilAddrErrStr)
  		}
  		return payToScriptHashScript(addr.ScriptAddress())
  
  	case *btcutil.AddressPubKey:
  		if addr == nil {
  			return nil, scriptError(ErrUnsupportedAddress,
  				nilAddrErrStr)
  		}
  		return payToPubKeyScript(addr.ScriptAddress())
  
  	case *btcutil.AddressWitnessPubKeyHash:
  		if addr == nil {
  			return nil, scriptError(ErrUnsupportedAddress,
  				nilAddrErrStr)
  		}
  		return payToWitnessPubKeyHashScript(addr.ScriptAddress())
  	case *btcutil.AddressWitnessScriptHash:
  		if addr == nil {
  			return nil, scriptError(ErrUnsupportedAddress,
  				nilAddrErrStr)
  		}
  		return payToWitnessScriptHashScript(addr.ScriptAddress())
  	}
  
  	str := fmt.Sprintf("unable to generate payment script for unsupported "+
  		"address type %T", addr)
  	return nil, scriptError(ErrUnsupportedAddress, str)
  }
docs: // PayToAddrScript creates a new script to pay a transaction output to a the
  // specified address.