zcash_client_sqlite::query::get_address()

This commit is contained in:
Jack Grigg
2019-03-09 02:23:31 +00:00
parent bee4d6a92b
commit 0bf1fad0ed
3 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
//! Functions for querying information in the data database.
use rusqlite::Connection;
use std::path::Path;
use crate::error::Error;
/// Returns the address for the account.
///
/// # Examples
///
/// ```
/// use zcash_client_sqlite::query::get_address;
///
/// let addr = get_address("/path/to/data.db", 0);
/// ```
pub fn get_address<P: AsRef<Path>>(db_data: P, account: u32) -> Result<String, Error> {
let data = Connection::open(db_data)?;
let addr = data.query_row(
"SELECT address FROM accounts
WHERE account = ?",
&[account],
|row| row.get(0),
)?;
Ok(addr)
}