diff --git a/multi-service/ethqlite/src/crud.rs b/multi-service/ethqlite/src/crud.rs index 292d33a..264973d 100644 --- a/multi-service/ethqlite/src/crud.rs +++ b/multi-service/ethqlite/src/crud.rs @@ -69,15 +69,27 @@ pub fn create_table(conn: &Connection) -> std::result::Result<(), fce_sqlite_con res } -#[fce] -pub fn update_reward_blocks(data_string: String) -> bool { - if AUTH.load(Ordering::Relaxed) && !is_owner() { - return false; - } +#[fce] +#[derive(Debug)] +pub struct UpdateResult { + pub success: bool, + pub err_str: String, +} + +#[fce] +pub fn update_reward_blocks(data_string: String) -> UpdateResult { + if !is_owner() { + return UpdateResult { success:false, err_str: "You are not the owner".into()}; + } + let obj:serde_json::Value = serde_json::from_str(&data_string).unwrap(); let obj = obj["result"].clone(); + if obj["blockNumber"] == serde_json::Value::Null { + return UpdateResult { success:false, err_str: "Empty reward block string".into()}; + } + let conn = get_connection(); let insert = "insert or ignore into reward_blocks values(?, ?, ?, ?)"; @@ -99,10 +111,10 @@ pub fn update_reward_blocks(data_string: String) -> bool { println!("select row {:?}", row); println!("{}, {}", row[0].as_integer().unwrap(), row[2].as_string().unwrap()); } - return true; + return UpdateResult { success:true, err_str: "".into()}; } - - false + + UpdateResult { success:false, err_str: "Insert failed".into()} } #[fce] @@ -216,17 +228,3 @@ pub fn get_miner_rewards(miner_address: String) -> MinerRewards { miner_rewards } - - -#[fce] -#[derive(Debug)] -pub struct UpdateResult { - pub success: bool, - pub err_str: String, -} - -#[fce] -pub fn update_balance(user_id: String, tx_id: String, chain_id:u32) -> bool { - // check balance - true -} \ No newline at end of file diff --git a/multi-service/ethqlite/src/main.rs b/multi-service/ethqlite/src/main.rs index 3f3f248..e519bce 100644 --- a/multi-service/ethqlite/src/main.rs +++ b/multi-service/ethqlite/src/main.rs @@ -70,7 +70,7 @@ impl InitResult { } #[fce] -pub fn init_service(is_auth:bool, is_paywall: bool, api_data: String) -> InitResult { +pub fn init_service(is_auth:bool, api_data: String) -> InitResult { if INIT.load(Ordering::Relaxed) { return InitResult::error("Service already initiated".into());