update to accomodate empty reward block string

This commit is contained in:
boneyard93501 2021-03-08 22:06:34 -06:00
parent 9124648719
commit fbaf9143ee
2 changed files with 21 additions and 23 deletions

View File

@ -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;
#[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
}

View File

@ -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());