// ConvertedState returns an ExchangeBotState with a base of the provided
// currency code, if available.
494651
func (bot *ExchangeBot) ConvertedState(code string) (*ExchangeBotState, error) {
	bot.mtx.RLock()
	defer bot.mtx.RUnlock()
	fiatIndices := make(map[string]*ExchangeState)
	for token, indices := range bot.indexMap {
		for symbol, price := range indices {
			if symbol == code {
				fiatIndices[token] = &ExchangeState{Price: price}
			}
		}
	}

	dcrPrice, volume := bot.processState(bot.currentState.DcrBtc, true)
	btcPrice, _ := bot.processState(fiatIndices, false)
	if dcrPrice == 0 || btcPrice == 0 {
		bot.failed = true
		return nil, fmt.Errorf("Unable to process price for currency %s", code)
	}

	state := ExchangeBotState{
		BtcIndex:    code,
		Volume:      volume * btcPrice,
		Price:       dcrPrice * btcPrice,
		DcrBtc:      bot.currentState.DcrBtc,
		FiatIndices: fiatIndices,
	}

	return state.copy(), nil
}
1264613
func (_m *StateFetcher) FetchState() (validation.State, error) {
	ret := _m.Called()

	var r0 validation.State
	if rf, ok := ret.Get(0).(func() validation.State); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(validation.State)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
666625
func (s *State) RefreshState() error {
	s.mu.Lock()
	defer s.mu.Unlock()
	return s.refreshState()
}
1264094
func (self *stateObject) GetCommittedState(db Database, key common.Hash) common.Hash {
	// If we have the original value cached, return that
	value, cached := self.originStorage[key]
	if cached {
		return value
	}
	// Track the amount of time wasted on reading the storge trie
	if metrics.EnabledExpensive {
		defer func(start time.Time) { self.db.StorageReads += time.Since(start) }(time.Now())
	}
	// Otherwise load the value from the database
	enc, err := self.getTrie(db).TryGet(key[:])
	if err != nil {
		self.setError(err)
		return common.Hash{}
	}
	if len(enc) > 0 {
		_, content, _, err := rlp.Split(enc)
		if err != nil {
			self.setError(err)
		}
		value.SetBytes(content)
	}
	self.originStorage[key] = value
	return value
}
178122
func (d *decoder) pushState(s json.Delim) {
	d.parseState = append(d.parseState, s)
}
573549
func (d *ConsulStateDriver) ReadAllState(baseKey string, sType core.State,
	unmarshal func([]byte, interface{}) error) ([]core.State, error) {
	baseKey = processKey(baseKey)
	return readAllStateCommon(d, baseKey, sType, unmarshal)
}
320489
func (s *State) refreshState() error {
	payload, err := s.Client.Get()
	if err != nil {
		return err
	}

	// no remote state is OK
	if payload == nil {
		s.readState = nil
		s.lineage = ""
		s.serial = 0
		return nil
	}

	stateFile, err := statefile.Read(bytes.NewReader(payload.Data))
	if err != nil {
		return err
	}

	s.lineage = stateFile.Lineage
	s.serial = stateFile.Serial
	s.state = stateFile.State
	s.readState = s.state.DeepCopy() // our states must be separate instances so we can track changes
	return nil
}
129237
func (a *Allergy) convertStatus() string {
	var status string

	if a.NegationInd {
		return "refuted"
	}

	statusConcept := a.StatusCode.FHIRCodeableConcept("")
	switch {
	case statusConcept.MatchesCode("http://snomed.info/sct", "55561003"):
		status = "active"
	case statusConcept.MatchesCode("http://snomed.info/sct", "73425007"):
		status = "inactive"
	case statusConcept.MatchesCode("http://snomed.info/sct", "413322009"):
		status = "resolved"
	default:
		status = "active"
	}

	// In order to remain consistent, fix the status if there is an end date
	// and it doesn't match the start date (in which case we can't be sure it's really an end)
	if status == "" && a.EndTime != nil && a.StartTime != nil && *a.EndTime != *a.StartTime {
		status = "resolved"
	}

	return status
}
691027
func (bot *ExchangeBot) StateBytes() []byte {
	bot.mtx.RLock()
	defer bot.mtx.RUnlock()
	return bot.currentStateBytes
}
1357609
func (lc *LightningChannel) ResetState() {
	lc.Lock()
	lc.status = channelOpen
	lc.Unlock()
}
884357
func (state ExchangeBotState) copy() *ExchangeBotState {
	state.DcrBtc = copyStates(state.DcrBtc)
	state.FiatIndices = copyStates(state.FiatIndices)
	return &state
}
512142
func copyStates(m map[string]*ExchangeState) map[string]*ExchangeState {
	c := make(map[string]*ExchangeState)
	for k, v := range m {
		c[k] = v
	}
	return c
}
966421
func NewState(opts ...Options) *LState {
	var ls *LState
	if len(opts) == 0 {
		ls = newLState(Options{
			CallStackSize: CallStackSize,
			RegistrySize:  RegistrySize,
		})
		ls.OpenLibs()
	} else {
		if opts[0].CallStackSize < 1 {
			opts[0].CallStackSize = CallStackSize
		}
		if opts[0].RegistrySize < 128 {
			opts[0].RegistrySize = RegistrySize
		}
		ls = newLState(opts[0])
		if !opts[0].SkipOpenLibs {
			ls.OpenLibs()
		}
	}
	return ls
}
1224110
func (agent *ActionAgent) RefreshState(ctx context.Context) error {
	if err := agent.lock(ctx); err != nil {
		return err
	}
	defer agent.unlock()

	return agent.refreshTablet(ctx, "RefreshState")
}
763622
func fromState(r *http.Request) (br blob.Ref, xsrfToken string, err error) {
	params := strings.Split(r.FormValue("state"), ":")
	if len(params) != 2 {
		return br, "", fmt.Errorf("Invalid format for state parameter: %q, wanted blobRef:xsrfToken", r.FormValue("state"))
	}
	br, ok := blob.Parse(params[0])
	if !ok {
		return br, "", fmt.Errorf("Invalid blobRef in state parameter: %q", params[0])
	}
	token, err := hex.DecodeString(params[1])
	if err != nil {
		return br, "", fmt.Errorf("can't decode hex xsrftoken %q: %v", params[1], err)
	}
	return br, string(token), nil
}
619610
func WithState(ctx context.Context, s *State) context.Context {
	return context.WithValue(ctx, stateKey, s)
}
306815
func (f *FastTeamChainLoader) mutateState(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, groceries *groceries) (err error) {

	err = f.putName(m, arg, state, groceries.newLinks)
	if err != nil {
		return err
	}
	err = f.putLinks(m, arg, state, groceries.newLinks)
	if err != nil {
		return err
	}
	err = f.putRKMs(m, arg, state, groceries.rkms)
	if err != nil {
		return err
	}
	err = f.putSeeds(m, arg, state, groceries.latestKeyGen, groceries.seeds)
	if err != nil {
		return err
	}
	err = f.putMetadata(m, arg, state)
	if err != nil {
		return err
	}
	return nil
}