func (f Fetcher) CalculateConfirmedBalanceFor(address btcutil.Address) (btcutil.Amount, error){

	//filter needed to search for transactions
	var filteraddrs []string = []string{address.EncodeAddress()}
	logrus.Infof("Looking for transactions for %s ..",address.EncodeAddress())
	//search for transactions involving the given address
	searchRawResult, err := f.rpcClient.SearchRawTransactionsVerbose(address,0,1000000,true,false,filteraddrs)
	if err != nil{
		logrus.Errorf("Error retrieving raw transactions: %s",err)
	}
	if len(searchRawResult) == 0{
		return 0, errors.New("No transactions found for given address!")
	}
	logrus.Infof("Found %d transactions involving %s",len(searchRawResult),address.EncodeAddress())
	var sumin btcutil.Amount
	var sumout btcutil.Amount
	//while looping over txs, let's not forget that there may be immature coinbase txs
	// we need to also take into account regular transactions that have not had over 6 confirmations
	for _,result := range searchRawResult {
		for _, in := range result.Vin {
			if !in.IsCoinBase() {
				if addrutils.AddrIsIncluded(address.EncodeAddress(), in.PrevOut.Addresses) {
					logrus.Infof("adding input %f", in.PrevOut.Value)
					amount, err := btcutil.NewAmount(in.PrevOut.Value)
					if err != nil {
						continue
					}
					sumout += amount
				}

			}
		}
		for _, out := range result.Vout {
			if addrutils.AddrIsIncluded(address.EncodeAddress(), out.ScriptPubKey.Addresses) {
				logrus.Infof("adding output %f", out.Value)
				amount, err := btcutil.NewAmount(out.Value)
				if err != nil {
					continue
				}
				sumin += amount
			}

		}
	}
	balance := sumin - sumout

	return balance, nil
}
//CalculateBalanceFor calculates the balance for a given pay-to address
CalculateBalanceFor calculates the balance for a given pay-to address
// CalculateBalanceFor calculates the balance for a given pay - to address
func (f Fetcher) CalculateConfirmedBalanceFor(address btcutil.Address) (btcutil.Amount, error){
	var filteraddrs []string = []string{address.EncodeAddress()}
	logrus.Infof("Looking for transactions for %s ..",address.EncodeAddress())
	searchRawResult, err := f.rpcClient.SearchRawTransactionsVerbose(address,0,1000000,true,false,filteraddrs)
	if err != nil{
		logrus.Errorf("Error retrieving raw transactions: %s",err)
	}
	if len(searchRawResult) == 0{
		return 0, errors.New("No transactions found for given address!")
	}
	logrus.Infof("Found %d transactions involving %s",len(searchRawResult),address.EncodeAddress())
	var sumin btcutil.Amount
	var sumout btcutil.Amount
	for _,result := range searchRawResult {
		for _, in := range result.Vin {
			if !in.IsCoinBase() {
				if addrutils.AddrIsIncluded(address.EncodeAddress(), in.PrevOut.Addresses) {
					logrus.Infof("adding input %f", in.PrevOut.Value)
					amount, err := btcutil.NewAmount(in.PrevOut.Value)
					if err != nil {
						continue
					}
					sumout += amount
				}
			}
		}
		for _, out := range result.Vout {
			if addrutils.AddrIsIncluded(address.EncodeAddress(), out.ScriptPubKey.Addresses) {
				logrus.Infof("adding output %f", out.Value)
				amount, err := btcutil.NewAmount(out.Value)
				if err != nil {
					continue
				}
				sumin += amount
			}
		}
	}
	balance := sumin - sumout
	return balance, nil
}
func ( f Fetcher ) CalculateConfirmedBalanceFor ( address btcutil . Address ) ( btcutil . Amount , error ) { var filteraddrs [ ] string = [ ] string { address . EncodeAddress ( ) } logrus . Infof ( " " , address . EncodeAddress ( ) ) searchRawResult , err := f . rpcClient . SearchRawTransactionsVerbose ( address , 0 , 1000000 , true , false , filteraddrs ) if err != nil { logrus . Errorf ( " " , err ) } if len ( searchRawResult ) == 0 { return 0 , errors . New ( " " ) } logrus . Infof ( " " , len ( searchRawResult ) , address . EncodeAddress ( ) ) var sumin btcutil . Amount var sumout btcutil . Amount for _ , result := range searchRawResult { for _ , in := range result . Vin { if ! in . IsCoinBase ( ) { if addrutils . AddrIsIncluded ( address . EncodeAddress ( ) , in . PrevOut . Addresses ) { logrus . Infof ( " " , in . PrevOut . Value ) amount , err := btcutil . NewAmount ( in . PrevOut . Value ) if err != nil { continue } sumout += amount } } } for _ , out := range result . Vout { if addrutils . AddrIsIncluded ( address . EncodeAddress ( ) , out . ScriptPubKey . Addresses ) { logrus . Infof ( " " , out . Value ) amount , err := btcutil . NewAmount ( out . Value ) if err != nil { continue } sumin += amount } } } balance := sumin - sumout return balance , nil }
CalculateBalanceFor calculates the balance for a given pay-to address
CalculateBalanceFor calculates the balance for a given pay - to address
//filter needed to search for transactions //search for transactions involving the given address //while looping over txs, let's not forget that there may be immature coinbase txs // we need to also take into account regular transactions that have not had over 6 confirmations