// GetECBalance returns the balance in factoshi (factoid * 1e8) of a given Entry
// Credit Public Address.
430021
func GetECBalance(addr string) (int64, error) {
	type balanceResponse struct {
		Balance int64 `json:"balance"`
	}

	params := addressRequest{Address: addr}
	req := NewJSON2Request("entry-credit-balance", APICounter(), params)
	resp, err := factomdRequest(req)
	if err != nil {
		return -1, err
	}
	if resp.Error != nil {
		return -1, resp.Error
	}

	balance := new(balanceResponse)
	if err := json.Unmarshal(resp.JSONResult(), balance); err != nil {
		return -1, err
	}

	return balance.Balance, nil
}
33461
func GetBalanceTransaction(id string, params *stripe.BalanceTransactionParams) (*stripe.BalanceTransaction, error) {
	return getC().GetBalanceTransaction(id, params)
}
534886
func FullAccount(name string) GenesisSpec {
	// Inheriting from the arbitrary figures used by monax tool for now
	amount := uint64(99999999999999)
	Power := uint64(9999999999)
	return GenesisSpec{
		Accounts: []TemplateAccount{{
			Name:        name,
			Amounts:     balance.New().Native(amount).Power(Power),
			Permissions: []string{permission.AllString},
		},
		},
	}
}
1013854
func (api *API) GetAccountData(seed Trytes, options GetAccountDataOptions) (*AccountData, error) {
	options = getAccountDAtaDefaultOptions(options)
	if err := Validate(ValidateSeed(seed), ValidateSecurityLevel(options.Security),
		ValidateStartEndOptions(options.Start, options.End)); err != nil {
		return nil, err
	}

	var total *uint64
	if options.End != nil {
		t := *options.End - options.Start
		total = &t
	}

	addresses, err := api.GetNewAddress(seed, GetNewAddressOptions{
		Index: options.Start, Total: total,
		ReturnAll: true, Security: options.Security,
	})
	if err != nil {
		return nil, err
	}

	var err1, err2, err3 error
	var bundles bundle.Bundles
	var balances *Balances
	var spentState []bool

	wg := sync.WaitGroup{}
	wg.Add(3)
	go func() {
		defer wg.Done()
		bundles, err1 = api.GetBundlesFromAddresses(addresses, true)
	}()

	go func() {
		defer wg.Done()
		balances, err2 = api.GetBalances(addresses, 100)
	}()

	go func() {
		defer wg.Done()
		spentState, err3 = api.WereAddressesSpentFrom(addresses...)
	}()

	wg.Wait()
	if err := firstNonNilErr(err1, err2, err3); err != nil {
		return nil, err
	}

	// extract tx hashes which operated on the account's addresses
	// as input or output tx
	var txsHashes Hashes
	for i := range bundles {
		bndl := &bundles[i]
		for j := range *bndl {
			tx := &(*bndl)[j]
			for x := range addresses {
				if tx.Address == addresses[x] {
					txsHashes = append(txsHashes, tx.Hash)
					break
				}
			}
		}
	}

	// compute balances
	inputs := []Input{}
	var totalBalance uint64
	for i := range addresses {
		value := balances.Balances[i]
		// this works because the balances and spent states are ordered
		if spentState[i] || value <= 0 {
			continue
		}
		totalBalance += value

		addr := Input{
			Address: addresses[i], Security: options.Security,
			KeyIndex: options.Start + uint64(i), Balance: value,
		}
		inputs = append(inputs, addr)
	}

	account := &AccountData{
		Transfers:     bundles,
		Transactions:  txsHashes,
		Inputs:        inputs,
		Balance:       totalBalance,
		LatestAddress: addresses[len(addresses)-1],
		Addresses:     addresses,
	}

	return account, nil
}
546243
func NewAccountBalanceNtfn(account string, balance float64, confirmed bool) *AccountBalanceNtfn {
	return &AccountBalanceNtfn{
		Account:   account,
		Balance:   balance,
		Confirmed: confirmed,
	}
}
1233970
func (a *Amount) GetAmount(now time.Time) (int32, error) {
	for _, s := range a.GetChange() {
		start, err := s.mostRecentStart(now)
		if err != nil {
			return 0, errors.Annotate(err, "invalid start time").Err()
		}
		if start.Before(now) || start.Equal(now) {
			sec, err := s.Length.ToSeconds()
			if err != nil {
				return 0, errors.Annotate(err, "invalid length").Err()
			}
			end := start.Add(time.Second * time.Duration(sec))
			if now.Before(end) {
				return s.Amount, nil
			}
		}
	}
	return a.GetDefault(), nil
}
97076
func NewGetBalanceCmd(account *string, minConf *int) *GetBalanceCmd {
	return &GetBalanceCmd{
		Account: account,
		MinConf: minConf,
	}
}
1182909
func (c Client) Get(params *stripe.BalanceParams) (*stripe.Balance, error) {
	balance := &stripe.Balance{}
	err := c.B.Call(http.MethodGet, "/v1/balance", c.Key, params, balance)
	return balance, err
}
1307836
func (self *AccountingApi) BalanceCredit() (int64, error) {
	if self.metrics == nil {
		return 0, errNoAccountingMetrics
	}
	return mBalanceCredit.Count(), nil
}
562279
func (pgb *ChainDB) AddressBalance(address string) (bal *dbtypes.AddressBalance, cacheUpdated bool, err error) {
	// Check the cache first.
	bestHash, height := pgb.BestBlock()
	var validHeight *cache.BlockID
	bal, validHeight = pgb.AddressCache.Balance(address)
	if bal != nil && *bestHash == validHeight.Hash {
		return
	}

	busy, wait, done := pgb.CacheLocks.bal.TryLock(address)
	if busy {
		// Let others get the wait channel while we wait.
		// To return stale cache data if it is available:
		// utxos, _ := pgb.AddressCache.UTXOs(address)
		// if utxos != nil {
		// 	return utxos, nil
		// }
		<-wait

		// Try again, starting with the cache.
		return pgb.AddressBalance(address)
	}

	// We will run the DB query, so block others from doing the same. When query
	// and/or cache update is completed, broadcast to any waiters that the coast
	// is clear.
	defer done()

	// Cache is empty or stale, so query the DB.
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	bal, err = RetrieveAddressBalance(ctx, pgb.db, address)
	if err != nil {
		err = pgb.replaceCancelError(err)
		return
	}

	// Update the address cache.
	cacheUpdated = pgb.AddressCache.StoreBalance(address, bal,
		cache.NewBlockID(bestHash, height))
	return
}
434013
func (self *StateDB) AddBalance(addr common.Address, amount *big.Int) {
	stateObject := self.GetOrNewStateObject(addr)
	if stateObject != nil {
		stateObject.AddBalance(amount)
	}
}
851127
func (c *Client) GetAccount(address btcutil.Address) (string, error) {
	return c.GetAccountAsync(address).Receive()
}
1060583
func (s *AccountsService) GetAccount(account string) (*AccountInfo, *Response, error) {
	u := fmt.Sprintf("accounts/%s", account)

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	v := new(AccountInfo)
	resp, err := s.client.Do(req, v)
	if err != nil {
		return nil, resp, err
	}

	return v, resp, err
}
552250
func (cs *CSCloud) GetLoadBalancerName(ctx context.Context, clusterName string, service *v1.Service) string {
	return cloudprovider.DefaultLoadBalancerName(service)
}
286992
func (r Billing_Info) GetCurrency() (resp datatypes.Billing_Currency, err error) {
	err = r.Session.DoRequest("SoftLayer_Billing_Info", "getCurrency", nil, &r.Options, &resp)
	return
}
723598
func (c *Client) GetBalancesWithOptions(accessToken string, options GetBalancesOptions) (resp GetBalancesResponse, err error) {
	if accessToken == "" {
		return resp, errors.New("/accounts/balance/get - access token must be specified")
	}
	req := getBalancesRequest{
		ClientID:    c.clientID,
		Secret:      c.secret,
		AccessToken: accessToken,
	}
	if len(options.AccountIDs) > 0 {
		req.Options.AccountIDs = options.AccountIDs
	}
	jsonBody, err := json.Marshal(req)
	if err != nil {
		return resp, err
	}

	err = c.Call("/accounts/balance/get", jsonBody, &resp)
	return resp, err
}
135708
func getUnconfirmedBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
	cmd := icmd.(*btcjson.GetUnconfirmedBalanceCmd)

	acctName := "default"
	if cmd.Account != nil {
		acctName = *cmd.Account
	}
	account, err := w.AccountNumber(waddrmgr.KeyScopeBIP0044, acctName)
	if err != nil {
		return nil, err
	}
	bals, err := w.CalculateAccountBalances(account, 1)
	if err != nil {
		return nil, err
	}

	return (bals.Total - bals.Spendable).ToBTC(), nil
}