// computeTxEnv returns the execution environment of a certain transaction.
776346
func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) {
	// Create the parent state database
	block := api.eth.blockchain.GetBlockByHash(blockHash)
	if block == nil {
		return nil, vm.Context{}, nil, fmt.Errorf("block %#x not found", blockHash)
	}
	parent := api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
	if parent == nil {
		return nil, vm.Context{}, nil, fmt.Errorf("parent %#x not found", block.ParentHash())
	}
	statedb, err := api.computeStateDB(parent, reexec)
	if err != nil {
		return nil, vm.Context{}, nil, err
	}
	// Recompute transactions up to the target index.
	signer := types.MakeSigner(api.eth.blockchain.Config(), block.Number())

	for idx, tx := range block.Transactions() {
		// Assemble the transaction call message and return if the requested offset
		msg, _ := tx.AsMessage(signer)
		context := core.NewEVMContext(msg, block.Header(), api.eth.blockchain, nil)
		if idx == txIndex {
			return msg, context, statedb, nil
		}
		// Not yet the searched for transaction, execute on top of the current state
		vmenv := vm.NewEVM(context, statedb, api.eth.blockchain.Config(), vm.Config{})
		if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
			return nil, vm.Context{}, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
		}
		// Ensure any modifications are committed to the state
		// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
		statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number()))
	}
	return nil, vm.Context{}, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, blockHash)
}
182795
func ReplaceEnv(arg string, environments ...map[string]string) string {
	return envRe.ReplaceAllStringFunc(arg, func(arg string) string {
		stripped := arg[2 : len(arg)-1]
		for _, env := range environments {
			if value, ok := env[stripped]; ok {
				return value
			}
		}

		return arg
	})
}
1221148
func Env(e *Config) Option {
	return func(o *options) {
		o.env = append(o.env, e)
	}
}
245924
func (e *EnvironmentLoader) PrintEnvs(s interface{}) {
	strct := structs.New(s)
	strctMap := strct.Map()
	prefix := e.getPrefix(strct)

	keys := make([]string, 0, len(strctMap))
	for key := range strctMap {
		keys = append(keys, key)
	}
	sort.Strings(keys)

	for _, key := range keys {
		field := strct.Field(key)
		e.printField(prefix, field, key, strctMap[key])
	}
}
62240
func ProcessLogxiFormatEnv(env string) {
	logxiFormat = env
	m := parseKVList(logxiFormat, ",")
	formatterFormat := ""
	tFormat := ""
	for key, value := range m {
		switch key {
		default:
			formatterFormat = key
		case "t":
			tFormat = value
		case "pretty":
			isPretty = value != "false" && value != "0"
		case "maxcol":
			col, err := strconv.Atoi(value)
			if err == nil {
				maxCol = col
			} else {
				maxCol = defaultMaxCol
			}
		case "context":
			lines, err := strconv.Atoi(value)
			if err == nil {
				contextLines = lines
			} else {
				contextLines = defaultContextLines
			}
		case "LTSV":
			formatterFormat = "text"
			AssignmentChar = ltsvAssignmentChar
			Separator = ltsvSeparator
		}
	}
	if formatterFormat == "" || formatterCreators[formatterFormat] == nil {
		formatterFormat = defaultFormat
	}
	logxiFormat = formatterFormat
	if tFormat == "" {
		tFormat = defaultTimeFormat
	}
	timeFormat = tFormat
}
928801
func copyEnvVarSlice(in []corev1.EnvVar) []corev1.EnvVar {
	out := make([]corev1.EnvVar, len(in))
	copy(out, in)
	return out
}
917736
func NewEnv() *Env {
	return &Env{
		env:    make(map[string]reflect.Value),
		typ:    make(map[string]reflect.Type),
		parent: nil,
	}
}
112896
func env(key string, defaultValue string) string {
	val := os.Getenv(key)
	if len(val) == 0 {
		return defaultValue
	}
	return val
}
305520
func loadTemplateEnv(tmpls []*structs.Template, taskDir string, taskEnv *taskenv.TaskEnv) (map[string]string, error) {
	all := make(map[string]string, 50)
	for _, t := range tmpls {
		if !t.Envvars {
			continue
		}

		dest := filepath.Join(taskDir, taskEnv.ReplaceEnv(t.DestPath))
		f, err := os.Open(dest)
		if err != nil {
			return nil, fmt.Errorf("error opening env template: %v", err)
		}
		defer f.Close()

		// Parse environment fil
		vars, err := envparse.Parse(f)
		if err != nil {
			return nil, fmt.Errorf("error parsing env template %q: %v", dest, err)
		}
		for k, v := range vars {
			all[k] = v
		}
	}
	return all, nil
}
1192175
func (c *Configuration) CheckEnv() error {
	if c.ActiveEnv == "" {
		return fmt.Errorf("No active environment chosen. Please choose an environment using the \"env\" flag in config.toml or the $%s_ENV environment variable", c.AppEnvName)
	}
	return nil
}
1246241
func GetEnv(envName, defaultValue string) string {
	value := os.Getenv(envName)
	if value == "" {
		return defaultValue
	}
	return value
}
301353
func (t *TaskEnv) ReplaceEnv(arg string) string {
	return hargs.ReplaceEnv(arg, t.EnvMap, t.NodeAttrs)
}
169113
func NewEnv(v interface{}) (*Env, error) {
	e := &Env{}

	if reflect.TypeOf(v).Kind() != reflect.Ptr {
		return nil, errInvalidValue
	}
	if reflect.ValueOf(v).Elem().Kind() != reflect.Struct {
		return nil, errInvalidValue
	}

	e.SetValue(v)

	if err := e.Parse(); err != nil {
		return e, err
	}

	return e, nil
}
932307
func setupEnv(args []string) (retArgs []string, format string, outputCurlString bool) {
	var nextArgFormat bool

	for _, arg := range args {
		if nextArgFormat {
			nextArgFormat = false
			format = arg
			continue
		}

		if arg == "--" {
			break
		}

		if len(args) == 1 && (arg == "-v" || arg == "-version" || arg == "--version") {
			args = []string{"version"}
			break
		}

		if arg == "-output-curl-string" {
			outputCurlString = true
			continue
		}

		// Parse a given flag here, which overrides the env var
		if strings.HasPrefix(arg, "--format=") {
			format = strings.TrimPrefix(arg, "--format=")
		}
		if strings.HasPrefix(arg, "-format=") {
			format = strings.TrimPrefix(arg, "-format=")
		}
		// For backwards compat, it could be specified without an equal sign
		if arg == "-format" || arg == "--format" {
			nextArgFormat = true
		}
	}

	envVaultFormat := os.Getenv(EnvVaultFormat)
	// If we did not parse a value, fetch the env var
	if format == "" && envVaultFormat != "" {
		format = envVaultFormat
	}
	// Lowercase for consistency
	format = strings.ToLower(format)
	if format == "" {
		format = "table"
	}

	return args, format, outputCurlString
}
707569
func Getenv(ctx context.Context, key string) string {
	val, _ := LookupEnv(ctx, key)
	return val
}
552917
func (r *Env) RunTxn(flags uint, op lmdb.TxnOp) (err error) {
	readonly := flags&lmdb.Readonly != 0
	return r.runHandler(readonly, func() error { return r.Env.RunTxn(flags, op) }, r.Handlers)
}
12148
func FromEnv() (*Configuration, error) {
	c := &Configuration{}

	if e := os.Getenv(envServiceName); e != "" {
		c.ServiceName = e
	}

	if e := os.Getenv(envRPCMetrics); e != "" {
		if value, err := strconv.ParseBool(e); err == nil {
			c.RPCMetrics = value
		} else {
			return nil, errors.Wrapf(err, "cannot parse env var %s=%s", envRPCMetrics, e)
		}
	}

	if e := os.Getenv(envDisabled); e != "" {
		if value, err := strconv.ParseBool(e); err == nil {
			c.Disabled = value
		} else {
			return nil, errors.Wrapf(err, "cannot parse env var %s=%s", envDisabled, e)
		}
	}

	if e := os.Getenv(envTags); e != "" {
		c.Tags = parseTags(e)
	}

	if s, err := samplerConfigFromEnv(); err == nil {
		c.Sampler = s
	} else {
		return nil, errors.Wrap(err, "cannot obtain sampler config from env")
	}

	if r, err := reporterConfigFromEnv(); err == nil {
		c.Reporter = r
	} else {
		return nil, errors.Wrap(err, "cannot obtain reporter config from env")
	}

	return c, nil
}