func (db *DB) GetDepositAddress(pubkey *koblitz.PublicKey, asset string) (depositAddr string, err error) {

	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	// this defer is pushed onto the stack first
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while getting deposit address: \n%s", err)
			return
		}
		err = tx.Commit()
		return
	}()

	// Use the deposit schema
	if _, err = tx.Exec("USE " + db.depositSchema + ";"); err != nil {
		err = fmt.Errorf("Could not use deposit schema: \n%s", err)
		return
	}

	getBalanceQuery := fmt.Sprintf("SELECT address FROM %s WHERE pubkey='%x';", asset, pubkey.SerializeCompressed())
	var rows *sql.Rows
	if rows, err = tx.Query(getBalanceQuery); err != nil {
		err = fmt.Errorf("Error when getting deposit: \n%s", err)
		return
	}

	if rows.Next() {

		if err = rows.Scan(&depositAddr); err != nil {
			err = fmt.Errorf("Error scanning for deposit address: \n%s", err)
			return
		}

		logging.Debugf("Pubkey %x's deposit address for %s: %s\n", pubkey.SerializeCompressed(), asset, depositAddr)

	} else {
		err = fmt.Errorf("Cannot find deposit address. Make sure you've registered")
		return
	}

	if err = rows.Close(); err != nil {
		err = fmt.Errorf("Error closing deposit result: \n%s", err)
		return
	}

	return
}
// GetDepositAddress gets the deposit address of an account
GetDepositAddress gets the deposit address of an account
// GetDepositAddress gets the deposit address of an account
func (db *DB) GetDepositAddress(pubkey *koblitz.PublicKey, asset string) (depositAddr string, err error) {
	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while getting deposit address: \n%s", err)
			return
		}
		err = tx.Commit()
		return
	}()
	if _, err = tx.Exec("USE " + db.depositSchema + ";"); err != nil {
		err = fmt.Errorf("Could not use deposit schema: \n%s", err)
		return
	}
	getBalanceQuery := fmt.Sprintf("SELECT address FROM %s WHERE pubkey='%x';", asset, pubkey.SerializeCompressed())
	var rows *sql.Rows
	if rows, err = tx.Query(getBalanceQuery); err != nil {
		err = fmt.Errorf("Error when getting deposit: \n%s", err)
		return
	}
	if rows.Next() {
		if err = rows.Scan(&depositAddr); err != nil {
			err = fmt.Errorf("Error scanning for deposit address: \n%s", err)
			return
		}
		logging.Debugf("Pubkey %x's deposit address for %s: %s\n", pubkey.SerializeCompressed(), asset, depositAddr)
	} else {
		err = fmt.Errorf("Cannot find deposit address. Make sure you've registered")
		return
	}
	if err = rows.Close(); err != nil {
		err = fmt.Errorf("Error closing deposit result: \n%s", err)
		return
	}
	return
}
func ( db * DB ) GetDepositAddress ( pubkey * koblitz . PublicKey , asset string ) ( depositAddr string , err error ) { var tx * sql . Tx if tx , err = db . DBHandler . Begin ( ) ; err != nil { return } defer func ( ) { if err != nil { tx . Rollback ( ) err = fmt . Errorf ( " \n " , err ) return } err = tx . Commit ( ) return } ( ) if _ , err = tx . Exec ( " " + db . depositSchema + " " ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } getBalanceQuery := fmt . Sprintf ( " " , asset , pubkey . SerializeCompressed ( ) ) var rows * sql . Rows if rows , err = tx . Query ( getBalanceQuery ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } if rows . Next ( ) { if err = rows . Scan ( & depositAddr ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } logging . Debugf ( " \n " , pubkey . SerializeCompressed ( ) , asset , depositAddr ) } else { err = fmt . Errorf ( " " ) return } if err = rows . Close ( ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } return }
GetDepositAddress gets the deposit address of an account
GetDepositAddress gets the deposit address of an account
// this defer is pushed onto the stack first // Use the deposit schema