func (db *DB) AddToBalanceWithinTransaction(pubkey *koblitz.PublicKey, amount uint64, tx *sql.Tx, param *coinparam.Params) (err error) {
	defer func() {
		if err != nil {
			err = fmt.Errorf("Error updating balances within transaction: \n%s", err)
			return
		}
	}()

	if _, err = tx.Exec("USE " + db.balanceSchema + ";"); err != nil {
		return
	}

	currentBalanceQuery := fmt.Sprintf("SELECT balance FROM %s WHERE pubkey='%x';", param.Name, pubkey.SerializeCompressed())
	var rows *sql.Rows
	if rows, err = tx.Query(currentBalanceQuery); err != nil {
		return
	}

	// Get the first result for balance
	var balance uint64
	if rows.Next() {

		if err = rows.Scan(&balance); err != nil {
			return
		}
	} else {
		// If we have no results then there's an issue
		err = fmt.Errorf("No balance for pubkey, please register")
		return
	}

	if err = rows.Close(); err != nil {
		return
	}

	insertBalanceQuery := fmt.Sprintf("UPDATE %s SET balance='%d' WHERE pubkey='%x';", param.Name, balance+amount, pubkey.SerializeCompressed())

	if _, err = tx.Exec(insertBalanceQuery); err != nil {
		return
	}

	return
}
// AddToBalanceWithinTransaction increases the balance of pubkey by amount
AddToBalanceWithinTransaction increases the balance of pubkey by amount
// AddToBalanceWithinTransaction increases the balance of pubkey by amount
func (db *DB) AddToBalanceWithinTransaction(pubkey *koblitz.PublicKey, amount uint64, tx *sql.Tx, param *coinparam.Params) (err error) {
	defer func() {
		if err != nil {
			err = fmt.Errorf("Error updating balances within transaction: \n%s", err)
			return
		}
	}()
	if _, err = tx.Exec("USE " + db.balanceSchema + ";"); err != nil {
		return
	}
	currentBalanceQuery := fmt.Sprintf("SELECT balance FROM %s WHERE pubkey='%x';", param.Name, pubkey.SerializeCompressed())
	var rows *sql.Rows
	if rows, err = tx.Query(currentBalanceQuery); err != nil {
		return
	}
	var balance uint64
	if rows.Next() {
		if err = rows.Scan(&balance); err != nil {
			return
		}
	} else {
		err = fmt.Errorf("No balance for pubkey, please register")
		return
	}
	if err = rows.Close(); err != nil {
		return
	}
	insertBalanceQuery := fmt.Sprintf("UPDATE %s SET balance='%d' WHERE pubkey='%x';", param.Name, balance+amount, pubkey.SerializeCompressed())
	if _, err = tx.Exec(insertBalanceQuery); err != nil {
		return
	}
	return
}
func ( db * DB ) AddToBalanceWithinTransaction ( pubkey * koblitz . PublicKey , amount uint64 , tx * sql . Tx , param * coinparam . Params ) ( err error ) { defer func ( ) { if err != nil { err = fmt . Errorf ( " \n " , err ) return } } ( ) if _ , err = tx . Exec ( " " + db . balanceSchema + " " ) ; err != nil { return } currentBalanceQuery := fmt . Sprintf ( " " , param . Name , pubkey . SerializeCompressed ( ) ) var rows * sql . Rows if rows , err = tx . Query ( currentBalanceQuery ) ; err != nil { return } var balance uint64 if rows . Next ( ) { if err = rows . Scan ( & balance ) ; err != nil { return } } else { err = fmt . Errorf ( " " ) return } if err = rows . Close ( ) ; err != nil { return } insertBalanceQuery := fmt . Sprintf ( " " , param . Name , balance + amount , pubkey . SerializeCompressed ( ) ) if _ , err = tx . Exec ( insertBalanceQuery ) ; err != nil { return } return }
AddToBalanceWithinTransaction increases the balance of pubkey by amount
AddToBalanceWithinTransaction increases the balance of pubkey by amount
// Get the first result for balance // If we have no results then there's an issue