mirror of
https://github.com/fluencelabs/examples
synced 2025-06-15 11:01:20 +00:00
rmm paywall
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
(seq
|
(seq
|
||||||
(seq
|
(seq
|
||||||
(call relay ("op" "identity") [])
|
(call relay ("op" "identity") [])
|
||||||
(call node_1 (service "init_service") [use_owner use_paywall api_key] result)
|
(call node_1 (service "init_service") [use_owner api_key] result)
|
||||||
)
|
)
|
||||||
(seq
|
(seq
|
||||||
(call relay ("op" "identity") [])
|
(call relay ("op" "identity") [])
|
||||||
|
@ -19,7 +19,7 @@ use fce_sqlite_connector::{Connection, State, Value};
|
|||||||
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use crate::{AUTH, PAYWALL};
|
use crate::AUTH;
|
||||||
use crate::get_connection;
|
use crate::get_connection;
|
||||||
use crate::auth::is_owner;
|
use crate::auth::is_owner;
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ use fluence::WasmLoggerBuilder;
|
|||||||
use fce_sqlite_connector;
|
use fce_sqlite_connector;
|
||||||
use fce_sqlite_connector::{Connection, State, Value};
|
use fce_sqlite_connector::{Connection, State, Value};
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@ -36,7 +35,6 @@ const DB_PATH: &str = "/tmp/fluence_service_db.sqlite";
|
|||||||
|
|
||||||
mod crud;
|
mod crud;
|
||||||
mod auth;
|
mod auth;
|
||||||
// mod paywall;
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -46,7 +44,6 @@ fn main() {
|
|||||||
const KOVAN_ACCT: &str = "";
|
const KOVAN_ACCT: &str = "";
|
||||||
|
|
||||||
pub static AUTH: AtomicBool = AtomicBool::new(false);
|
pub static AUTH: AtomicBool = AtomicBool::new(false);
|
||||||
pub static PAYWALL: AtomicBool = AtomicBool::new(false);
|
|
||||||
pub static INIT: AtomicBool = AtomicBool::new(false);
|
pub static INIT: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
|
||||||
@ -87,7 +84,6 @@ pub fn init_service(is_auth:bool, is_paywall: bool, api_data: String) -> InitRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
AUTH.store(is_auth, Ordering::Relaxed);
|
AUTH.store(is_auth, Ordering::Relaxed);
|
||||||
PAYWALL.store(is_paywall, Ordering::Relaxed);
|
|
||||||
|
|
||||||
|
|
||||||
if api_data.len() > 0 {
|
if api_data.len() > 0 {
|
||||||
@ -124,7 +120,6 @@ pub fn owner_nuclear_reset() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AUTH.store(false, Ordering::Relaxed);
|
AUTH.store(false, Ordering::Relaxed);
|
||||||
PAYWALL.store(false, Ordering::Relaxed);
|
|
||||||
INIT.store(false, Ordering::Relaxed);
|
INIT.store(false, Ordering::Relaxed);
|
||||||
|
|
||||||
let conn = get_connection();
|
let conn = get_connection();
|
||||||
@ -137,25 +132,3 @@ pub fn owner_nuclear_reset() -> bool {
|
|||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
#[fce]
|
|
||||||
fn get_balance(reference_id: String, ) {
|
|
||||||
let conn = fce_sqlite_connector::open(DB_PATH).unwrap();
|
|
||||||
|
|
||||||
let stmt = "select balance from payments where block_miner = ?";
|
|
||||||
let select = conn.prepare(stmt);
|
|
||||||
let mut miner_rewards = MinerRewards::new(miner_address.clone());
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
fn check_funding(compute_units: u32, unit_cost: u32) -> bool {
|
|
||||||
let conn = get_connection();
|
|
||||||
|
|
||||||
let req_balance:i64 = (compute_units * unit_cost).into();
|
|
||||||
get_balance(user_id)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
*/
|
|
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2021 Fluence Labs Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
use ed25519_dalek::{Signature, Verifier, PublicKey};
|
|
||||||
|
|
||||||
|
|
||||||
use crate::get_connection;
|
|
||||||
|
|
||||||
|
|
||||||
pub enum EthereumChains {
|
|
||||||
MAINNET = 1,
|
|
||||||
ROPSTEN = 3,
|
|
||||||
RINKEBY = 4,
|
|
||||||
GOERLI = 5,
|
|
||||||
KOVAN = 42,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn sig_check(pub_key: &[u8], message: &[u8], signature: [u8;64]) -> bool {
|
|
||||||
let pk = PublicKey::from_bytes(pub_key).unwrap();
|
|
||||||
let signature = Signature::new(signature);
|
|
||||||
match pk.verify(message, &signature) {
|
|
||||||
Ok(_) => true,
|
|
||||||
Err(_) => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[fce]
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DepositResult {
|
|
||||||
success: bool,
|
|
||||||
balance: String,
|
|
||||||
err_msg: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DepositResult {
|
|
||||||
fn success(balance: String) -> Self {
|
|
||||||
DepositResult {
|
|
||||||
success: true,
|
|
||||||
balance,
|
|
||||||
err_msg: String::from(""),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn failure(err_msg: String, balance: String) -> Self {
|
|
||||||
DepositResult {
|
|
||||||
success: false,
|
|
||||||
balance,
|
|
||||||
err_msg,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deposit(user_id:String, tx_id: String, chain_id: u32, pub_key: &[u8], signature: &[u8]) -> DepositResult {
|
|
||||||
let mut user_id:String = user_id;
|
|
||||||
if user_id.len() == 0 {
|
|
||||||
let user_id = Uuid::new_v4();
|
|
||||||
}
|
|
||||||
|
|
||||||
let stmt = "insert into table ??? where user_id = ? on conflict (user_id) do update set balance += ?";
|
|
||||||
|
|
||||||
DepositResult::failure("no_good".into(), "0".into())
|
|
||||||
}
|
|
||||||
|
|
Reference in New Issue
Block a user