mirror of
https://github.com/fluencelabs/examples
synced 2025-06-28 01:01:34 +00:00
cleanup
This commit is contained in:
@ -5,10 +5,17 @@ modules_dir = "artifacts/"
|
|||||||
mem_pages_count = 100
|
mem_pages_count = 100
|
||||||
logger_enabled = false
|
logger_enabled = false
|
||||||
|
|
||||||
|
[module.wasi]
|
||||||
|
preopened_files = ["/tmp"]
|
||||||
|
mapped_dirs = { "tmp" = "/tmp" }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[module]]
|
[[module]]
|
||||||
name = "ethqlite"
|
name = "ethqlite"
|
||||||
mem_pages_count = 1
|
mem_pages_count = 1
|
||||||
logger_enabled = false
|
logger_enabled = false
|
||||||
preopened_files = ["/var"]
|
|
||||||
mapped_dirs = { "var" = "./var" }
|
[module.wasi]
|
||||||
|
preopened_files = ["/tmp"]
|
||||||
|
mapped_dirs = { "tmp" = "/tmp" }
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "EthQlite",
|
"name": "ethqlite",
|
||||||
"mem_page_count": 1,
|
"mem_page_count": 1,
|
||||||
"preopened_files": [
|
"preopened_files": [
|
||||||
"/var"
|
"/tmp"
|
||||||
],
|
],
|
||||||
"mapped_dirs": {
|
"mapped_dirs": {
|
||||||
"var": "./var"
|
"tmp": "./tmp"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,11 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fce_sqlite_connector;
|
use fce_sqlite_connector;
|
||||||
use fce_sqlite_connector::{Connection, State, Value};
|
use fce_sqlite_connector::{Connection, Value};
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
|
|
||||||
use crate::AUTH;
|
|
||||||
use crate::get_connection;
|
use crate::get_connection;
|
||||||
use crate::auth::is_owner;
|
use crate::auth::is_owner;
|
||||||
|
|
||||||
@ -34,36 +31,6 @@ pub fn create_table(conn: &Connection) -> std::result::Result<(), fce_sqlite_con
|
|||||||
block_reward integer not null
|
block_reward integer not null
|
||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists payments (
|
|
||||||
tx_number text not null primary key,
|
|
||||||
chain_id integer not null,
|
|
||||||
timestamp integer not null,
|
|
||||||
balance integer not null,
|
|
||||||
unit text not null,
|
|
||||||
available integer not null,
|
|
||||||
unique(chain_id, tx_number)
|
|
||||||
);
|
|
||||||
|
|
||||||
create table if not exists costs (
|
|
||||||
chain_id integer not null primary key,
|
|
||||||
query_cost integer not null,
|
|
||||||
cost_unit string not null ,
|
|
||||||
currency string not null
|
|
||||||
);
|
|
||||||
|
|
||||||
insert or ignore into costs values(42, 10, 'gwei', 'eth');
|
|
||||||
|
|
||||||
create table if not exists security (
|
|
||||||
peer_id Text not null,
|
|
||||||
service_id Text not null primary key,
|
|
||||||
fn_name Text not null,
|
|
||||||
json_path Text not null
|
|
||||||
);
|
|
||||||
|
|
||||||
create table if not exists api_keys (
|
|
||||||
provider text not null primary key,
|
|
||||||
api_key text not null
|
|
||||||
);
|
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
res
|
res
|
||||||
|
@ -36,16 +36,10 @@ const DB_PATH: &str = "/tmp/fluence_service_db.sqlite";
|
|||||||
mod crud;
|
mod crud;
|
||||||
mod auth;
|
mod auth;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// WasmLoggerBuilder::new().build().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
const KOVAN_ACCT: &str = "";
|
|
||||||
|
|
||||||
pub static AUTH: AtomicBool = AtomicBool::new(false);
|
|
||||||
pub static INIT: AtomicBool = AtomicBool::new(false);
|
pub static INIT: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
|
||||||
fn get_connection() -> Connection {
|
fn get_connection() -> Connection {
|
||||||
Connection::open(DB_PATH).unwrap()
|
Connection::open(DB_PATH).unwrap()
|
||||||
@ -59,57 +53,27 @@ pub struct InitResult {
|
|||||||
pub err_msg: String,
|
pub err_msg: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InitResult {
|
|
||||||
fn success() -> Self {
|
|
||||||
InitResult {success: true, err_msg: String::from(""),}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn error(err_msg: String) -> Self {
|
|
||||||
InitResult {success: false, err_msg,}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fce]
|
#[fce]
|
||||||
pub fn init_service(is_auth:bool, api_data: String) -> InitResult {
|
pub fn init_service() -> InitResult {
|
||||||
|
|
||||||
|
if !is_owner() {
|
||||||
|
return InitResult {success: false, err_msg: "Not authorized to use this service".into()};
|
||||||
|
}
|
||||||
|
|
||||||
if INIT.load(Ordering::Relaxed) {
|
if INIT.load(Ordering::Relaxed) {
|
||||||
return InitResult::error("Service already initiated".into());
|
return InitResult {success: false, err_msg: "Service already initiated".into()};
|
||||||
}
|
}
|
||||||
|
|
||||||
let conn = get_connection();
|
let conn = get_connection();
|
||||||
let res = create_table(&conn);
|
let res = create_table(&conn);
|
||||||
println!("create tables: {:?}", res);
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return InitResult::error("Failure to create tables".into());
|
return InitResult {success: false, err_msg: "Failure to create tables".into()};
|
||||||
}
|
|
||||||
|
|
||||||
AUTH.store(is_auth, Ordering::Relaxed);
|
|
||||||
|
|
||||||
|
|
||||||
if api_data.len() > 0 {
|
|
||||||
let tokens: Vec<&str> = api_data.as_str().split(":").collect();
|
|
||||||
if tokens.len() != 2{
|
|
||||||
return InitResult::error("Invalid api data".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let ins_stmt = "insert or ignore into api_keys values (?, ?)";
|
|
||||||
let mut ins_cur = conn.prepare(ins_stmt).unwrap().cursor();
|
|
||||||
let insert = ins_cur.bind(
|
|
||||||
&[Value::String(tokens[0].into()),
|
|
||||||
Value::String(tokens[1].into()),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
if insert.is_err() {
|
|
||||||
return InitResult::error("Failure to insert api data".into());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return InitResult::error("Missing api data".into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Todo: implement rollbacks
|
// TODO: implement rollbacks
|
||||||
|
|
||||||
INIT.store(true, Ordering::Relaxed);
|
INIT.store(true, Ordering::Relaxed);
|
||||||
InitResult::success()
|
InitResult {success: true, err_msg: "".into()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,11 +83,10 @@ pub fn owner_nuclear_reset() -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AUTH.store(false, Ordering::Relaxed);
|
|
||||||
INIT.store(false, Ordering::Relaxed);
|
INIT.store(false, Ordering::Relaxed);
|
||||||
|
|
||||||
let conn = get_connection();
|
let conn = get_connection();
|
||||||
let t_names = vec!["api_keys", "reward_blocks", "payments", "costs", "security"];
|
let t_names = vec!["reward_blocks"];
|
||||||
for t_name in t_names {
|
for t_name in t_names {
|
||||||
let stmt = format!("delete from {}", t_name);
|
let stmt = format!("delete from {}", t_name);
|
||||||
let mut del_cur = conn.prepare(&stmt).unwrap().cursor();
|
let mut del_cur = conn.prepare(&stmt).unwrap().cursor();
|
||||||
|
Reference in New Issue
Block a user