Db create by FE
This commit is contained in:
parent
9ff8363ef3
commit
b0f3cd6a9d
|
@ -47,8 +47,6 @@ void deallocate_str(char *s);
|
|||
|
||||
struct CResult_u8 init_wallet(uint8_t coin, char *db_path);
|
||||
|
||||
struct CResult_u8 create_db(char *db_path);
|
||||
|
||||
struct CResult_u8 migrate_db(uint8_t coin, char *db_path);
|
||||
|
||||
struct CResult_u8 migrate_data_db(uint8_t coin);
|
||||
|
|
|
@ -98,13 +98,6 @@ pub unsafe extern "C" fn init_wallet(coin: u8, db_path: *mut c_char) -> CResult<
|
|||
to_cresult(init_coin(coin, &db_path).and_then(|()| Ok(0u8)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn create_db(db_path: *mut c_char) -> CResult<u8> {
|
||||
try_init_logger();
|
||||
from_c_str!(db_path);
|
||||
to_cresult(crate::db::DbAdapter::create_db(&db_path).and_then(|()| Ok(0u8)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn migrate_db(coin: u8, db_path: *mut c_char) -> CResult<u8> {
|
||||
try_init_logger();
|
||||
|
|
28
src/db.rs
28
src/db.rs
|
@ -11,12 +11,10 @@ use crate::unified::UnifiedAddressType;
|
|||
use crate::{sync, BlockId, CompactTxStreamerClient, Hash};
|
||||
use orchard::keys::FullViewingKey;
|
||||
use rusqlite::Error::QueryReturnedNoRows;
|
||||
use rusqlite::{params, Connection, OpenFlags, OptionalExtension, Transaction};
|
||||
use rusqlite::{params, Connection, OptionalExtension, Transaction};
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::path::Path;
|
||||
use anyhow::anyhow;
|
||||
use tonic::transport::Channel;
|
||||
use tonic::Request;
|
||||
use zcash_client_backend::encoding::decode_extended_full_viewing_key;
|
||||
|
@ -104,18 +102,9 @@ impl DbAdapter {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn create_db(db_path: &str) -> anyhow::Result<()> {
|
||||
let path = Path::new(db_path);
|
||||
let directory = path.parent().ok_or(anyhow!("Invalid path"))?;
|
||||
std::fs::create_dir_all(directory)?;
|
||||
let connection = Connection::open_with_flags(db_path, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE)?;
|
||||
connection.query_row("PRAGMA journal_mode = WAL", [], |_| Ok(()))?;
|
||||
connection.execute("PRAGMA synchronous = NORMAL", [])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn migrate_db(network: &Network, db_path: &str, has_ua: bool) -> anyhow::Result<()> {
|
||||
let connection = Connection::open(db_path)?;
|
||||
Self::set_wal(&connection, true)?;
|
||||
migration::init_db(&connection, network, has_ua)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -153,9 +142,20 @@ impl DbAdapter {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_wal(connection: &Connection, v: bool) -> anyhow::Result<()> {
|
||||
if v {
|
||||
connection.query_row("PRAGMA journal_mode = WAL", [], |_| Ok(()))?;
|
||||
connection.execute("PRAGMA synchronous = NORMAL", [])?;
|
||||
}
|
||||
else {
|
||||
connection.query_row("PRAGMA journal_mode = OFF", [], |_| Ok(()))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn disable_wal(db_path: &str) -> anyhow::Result<()> {
|
||||
let connection = Connection::open(db_path)?;
|
||||
connection.query_row("PRAGMA journal_mode = OFF", [], |_| Ok(()))?;
|
||||
Self::set_wal(&connection, false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue