// StoreUTXOs stores the AddressTxnOutput slice for the given address in cache.
// The current best block data is required to determine cache freshness.
495185
func (ac *AddressCache) StoreUTXOs(addr string, utxos []apitypes.AddressTxnOutput, block *BlockID) bool {
	if ac.cap < 1 || ac.capAddr < 1 {
		return false
	}

	// Only allow storing maxUTXOsPerAddr.
	if len(utxos) > maxUTXOsPerAddr && addr != ac.ProjectAddress {
		return false
	}

	ac.mtx.Lock()
	defer ac.mtx.Unlock()
	aci := ac.a[addr]

	if block != nil && utxos == nil {
		utxos = []apitypes.AddressTxnOutput{}
	}

	if aci == nil || aci.BlockHash() != block.Hash {
		return ac.addCacheItem(addr, &AddressCacheItem{
			utxos:  utxos,
			height: block.Height,
			hash:   block.Hash,
		})
	}

	// cache is current, so just set the utxos.
	aci.mtx.Lock()
	aci.utxos = utxos
	aci.mtx.Unlock()
	return true
}
709871
func (exp *explorerUI) StoreMPData(_ *mempool.StakeData, _ []types.MempoolTx, inv *types.MempoolInfo) {
	// Get exclusive access to the Mempool field.
	exp.invsMtx.Lock()
	exp.invs = inv
	exp.invsMtx.Unlock()
	log.Debugf("Updated mempool details for the explorerUI.")
}
740552
func WriteTxLookupEntries(db ethdb.Writer, block *types.Block) {
	for _, tx := range block.Transactions() {
		if err := db.Put(txLookupKey(tx.Hash()), block.Number().Bytes()); err != nil {
			log.Crit("Failed to store transaction lookup entry", "err", err)
		}
	}
}
214917
func (i *Int32) Store(n int32) {
	atomic.StoreInt32(&i.v, n)
}
339668
func StoreKey(dir, auth string, scryptN, scryptP int) (common.Address, error) {
	_, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP, false}, rand.Reader, auth)
	return a.Address, err
}
1337186
func (k cursorKind) storePrevCursor(c context.Context, pkg, cursor, prev string) {
	itm := memcache.NewItem(c, k.cursorKey(pkg, cursor))
	itm.SetValue([]byte(prev))
	itm.SetExpiration(24 * time.Hour)
	if err := memcache.Set(c, itm); err != nil {
		logging.WithError(err).Errorf(c, "Failed to store prev cursor %q in memcache", k)
	}
}
1160656
func Store(s storage.Store) func(r *Rego) {
	return func(r *Rego) {
		r.store = s
	}
}
525768
func (db *NodeSet) Store(target ethdb.Writer) {
	db.lock.RLock()
	defer db.lock.RUnlock()

	for key, value := range db.nodes {
		target.Put([]byte(key), value)
	}
}
197322
func (s *FileStorage) StoreSite(domain string, data *SiteData) error {
	err := os.MkdirAll(s.site(domain), 0700)
	if err != nil {
		return fmt.Errorf("making site directory: %v", err)
	}
	err = ioutil.WriteFile(s.siteCertFile(domain), data.Cert, 0600)
	if err != nil {
		return fmt.Errorf("writing certificate file: %v", err)
	}
	err = ioutil.WriteFile(s.siteKeyFile(domain), data.Key, 0600)
	if err != nil {
		return fmt.Errorf("writing key file: %v", err)
	}
	err = ioutil.WriteFile(s.siteMetaFile(domain), data.Meta, 0600)
	if err != nil {
		return fmt.Errorf("writing cert meta file: %v", err)
	}
	return nil
}
1084088
func (daemon *Daemon) StoreHosts(hosts []string) {
	if daemon.hosts == nil {
		daemon.hosts = make(map[string]bool)
	}
	for _, h := range hosts {
		daemon.hosts[h] = true
	}
}
421394
func (ts *TokenStore) storeCommon(ctx context.Context, entry *logical.TokenEntry, writeSecondary bool) error {
	tokenNS, err := NamespaceByID(ctx, entry.NamespaceID, ts.core)
	if err != nil {
		return err
	}
	if tokenNS == nil {
		return namespace.ErrNoNamespace
	}

	saltCtx := namespace.ContextWithNamespace(ctx, tokenNS)
	saltedID, err := ts.SaltID(saltCtx, entry.ID)
	if err != nil {
		return err
	}

	// Marshal the entry
	enc, err := json.Marshal(entry)
	if err != nil {
		return errwrap.Wrapf("failed to encode entry: {{err}}", err)
	}

	if writeSecondary {
		// Write the secondary index if necessary. This is done before the
		// primary index because we'd rather have a dangling pointer with
		// a missing primary instead of missing the parent index and potentially
		// escaping the revocation chain.
		if entry.Parent != "" {
			// Ensure the parent exists
			parent, err := ts.Lookup(ctx, entry.Parent)
			if err != nil {
				return errwrap.Wrapf("failed to lookup parent: {{err}}", err)
			}
			if parent == nil {
				return fmt.Errorf("parent token not found")
			}

			parentNS, err := NamespaceByID(ctx, parent.NamespaceID, ts.core)
			if err != nil {
				return err
			}
			if parentNS == nil {
				return namespace.ErrNoNamespace
			}

			parentCtx := namespace.ContextWithNamespace(ctx, parentNS)

			// Create the index entry
			parentSaltedID, err := ts.SaltID(parentCtx, entry.Parent)
			if err != nil {
				return err
			}

			path := parentSaltedID + "/" + saltedID
			if tokenNS.ID != namespace.RootNamespaceID {
				path = fmt.Sprintf("%s.%s", path, tokenNS.ID)
			}

			le := &logical.StorageEntry{Key: path}
			if err := ts.parentView(parentNS).Put(ctx, le); err != nil {
				return errwrap.Wrapf("failed to persist entry: {{err}}", err)
			}
		}
	}

	// Write the primary ID
	le := &logical.StorageEntry{Key: saltedID, Value: enc}
	if len(entry.Policies) == 1 && entry.Policies[0] == "root" {
		le.SealWrap = true
	}
	if err := ts.idView(tokenNS).Put(ctx, le); err != nil {
		return errwrap.Wrapf("failed to persist entry: {{err}}", err)
	}
	return nil
}
971842
func (ac *AddressCache) StoreBalance(addr string, balance *dbtypes.AddressBalance, block *BlockID) bool {
	if ac.cap < 1 || ac.capAddr < 1 {
		return false
	}

	ac.mtx.Lock()
	defer ac.mtx.Unlock()
	aci := ac.a[addr]

	if block != nil && balance == nil {
		balance = &dbtypes.AddressBalance{
			Address: addr,
		}
	}

	if aci == nil || aci.BlockHash() != block.Hash {
		return ac.addCacheItem(addr, &AddressCacheItem{
			balance: balance,
			height:  block.Height,
			hash:    block.Hash,
		})
	}

	// cache is current, so just set the balance.
	aci.mtx.Lock()
	aci.balance = balance
	aci.mtx.Unlock()
	return true
}
674220
func retrieveAddressTxsCount(ctx context.Context, db *sql.DB, address, interval string) (count int64, err error) {
	err = db.QueryRowContext(ctx, internal.MakeSelectAddressTimeGroupingCount(interval), address).Scan(&count)
	return
}
290044
func (s *MemoryStore) Save(tx ReadTx) (*pb.StoreSnapshot, error) {
	var snapshot pb.StoreSnapshot
	for _, os := range objectStorers {
		if err := os.Save(tx, &snapshot); err != nil {
			return nil, err
		}
	}

	return &snapshot, nil
}
370126
func (req *CodeRequest) StoreResult(db ethdb.Database) {
	db.Put(req.Hash[:], req.Data)
}
693734
func (p *BlockPrefetchClient) RetrieveAndStoreNext(nextHash *chainhash.Hash) {
	p.Lock()
	defer p.Unlock()

	// Fetch the next block, if needed.
	if p.haveBlockHash(*nextHash) {
		return
	}

	msgBlock, headerResult, _, err := p.retrieveBlockAndHeaderResult(nextHash)
	if err != nil {
		if strings.HasPrefix(err.Error(), outOfRangeErr) {
			log.Errorf("retrieveBlockAndHeaderResult(%v): %v",
				nextHash, err)
		}
		return
	}

	// Store this block's data.
	p.storeNext(msgBlock, headerResult)
}
1072923
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error) {
	var proof proofList
	trie := self.StorageTrie(a)
	if trie == nil {
		return proof, errors.New("storage trie for requested address does not exist")
	}
	err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
	return [][]byte(proof), err
}