Wasner
This commit is contained in:
parent
89c2aff705
commit
2f2e6b8c2f
1914
Cargo.lock
generated
1914
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,6 @@ members = [
|
|||||||
"crates/fs_manager",
|
"crates/fs_manager",
|
||||||
"crates/lang_provider",
|
"crates/lang_provider",
|
||||||
"crates/payment_adapter",
|
"crates/payment_adapter",
|
||||||
"crates/payment_adapter_pay_u",
|
|
||||||
# artifacts
|
# artifacts
|
||||||
# "crates/db-seed",
|
# "crates/db-seed",
|
||||||
# "crates/api",
|
# "crates/api",
|
||||||
@ -28,6 +27,9 @@ members = [
|
|||||||
"vendor/t_pay",
|
"vendor/t_pay",
|
||||||
"vendor/pay_u",
|
"vendor/pay_u",
|
||||||
]
|
]
|
||||||
|
exclude = [
|
||||||
|
"crates/payment_adapter_pay_u",
|
||||||
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
@ -12,7 +12,6 @@ actix-web = { version = "4.0", features = [], optional = true }
|
|||||||
cookie = { version = "0.16.1", features = ["signed"], optional = true }
|
cookie = { version = "0.16.1", features = ["signed"], optional = true }
|
||||||
parking_lot = { version = "0.12", features = [] }
|
parking_lot = { version = "0.12", features = [] }
|
||||||
password-hash = { version = "0.4", features = ["alloc"] }
|
password-hash = { version = "0.4", features = ["alloc"] }
|
||||||
#pay_u = { path = "../../vendor/pay_u", features = ["single-client"] }
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = { version = "1.0", features = [] }
|
serde_json = { version = "1.0", features = [] }
|
||||||
thiserror = { version = "1.0" }
|
thiserror = { version = "1.0" }
|
||||||
|
@ -510,7 +510,7 @@ impl OrderConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Default)]
|
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct PaymentProviderConfig {
|
pub struct PaymentProviderConfig {
|
||||||
pub client_id: Option<String>,
|
pub client_id: Option<String>,
|
||||||
pub client_secret: Option<String>,
|
pub client_secret: Option<String>,
|
||||||
@ -519,7 +519,7 @@ pub struct PaymentProviderConfig {
|
|||||||
pub custom: HashMap<String, String>,
|
pub custom: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Default)]
|
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct PaymentConfig {
|
pub struct PaymentConfig {
|
||||||
pub rpc_port: u16,
|
pub rpc_port: u16,
|
||||||
pub rpc_bind: String,
|
pub rpc_bind: String,
|
||||||
|
@ -6,5 +6,3 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
config = { path = "../config", default-features = false, features = [] }
|
config = { path = "../config", default-features = false, features = [] }
|
||||||
model = { path = "../model" }
|
model = { path = "../model" }
|
||||||
wasmtime = { version = "3.0.1" }
|
|
||||||
#socket2 = { version = "0.4.7", default-features = false, features = [] }
|
|
||||||
|
@ -2,7 +2,8 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
pub use config::PaymentProviderConfig;
|
pub use config::PaymentProviderConfig;
|
||||||
pub use model::*;
|
pub use model::*;
|
||||||
use wasmtime::WasmResults;
|
|
||||||
|
pub const CONFIG_POS: u32 = 3;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -12,6 +13,7 @@ pub enum Status {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct Buyer {
|
pub struct Buyer {
|
||||||
/// Required customer e-mail
|
/// Required customer e-mail
|
||||||
pub email: String,
|
pub email: String,
|
||||||
@ -26,6 +28,7 @@ pub struct Buyer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct Product {
|
pub struct Product {
|
||||||
pub id: ProductId,
|
pub id: ProductId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -34,6 +37,8 @@ pub struct Product {
|
|||||||
pub quantity: Quantity,
|
pub quantity: Quantity,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct CreatePayment {
|
pub struct CreatePayment {
|
||||||
// pub client: PayUClient,
|
// pub client: PayUClient,
|
||||||
pub buyer: Buyer,
|
pub buyer: Buyer,
|
||||||
|
@ -7,7 +7,11 @@ edition = "2021"
|
|||||||
crate-type = ['cdylib']
|
crate-type = ['cdylib']
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
payment_adapter = { path = "../payment_adapter" }
|
|
||||||
pay_u = { path = "../../vendor/pay_u" }
|
pay_u = { path = "../../vendor/pay_u" }
|
||||||
wasmtime = { version = "3.0.1" }
|
payment_adapter = { path = "../payment_adapter" }
|
||||||
wasmtime-api = { version = "0.4.0" }
|
#wasmer-wasi = { version = "3.0.2" }
|
||||||
|
wasmer = { version = "3.0.2", default-features = false, features = ['js', 'std', 'wasmer-compiler-llvm', 'enable-serde'] }
|
||||||
|
#wasm-bindgen = { version = "0.2.83", features = [] }
|
||||||
|
#js-sys = { version = "0.3.60", features = [] }
|
||||||
|
#web-sys = { version = "0.3.60", features = [] }
|
||||||
|
wee_alloc = { version = "0.4.5" }
|
||||||
|
@ -1,28 +1,20 @@
|
|||||||
use payment_adapter::{CreatePayment, PaymentAdapter, PaymentProviderConfig, Status};
|
use std::os::wasi::prelude::*;
|
||||||
use wasmtime::{ValType, WasmParams, WasmResults};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
use payment_adapter::{CreatePayment, Status};
|
||||||
pub struct PayUAdapter {}
|
// use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
impl PayUAdapter {
|
#[global_allocator]
|
||||||
pub fn new() -> Self {
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PaymentAdapter for PayUAdapter {
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"pay_u"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init(&mut self, config: PaymentProviderConfig) {}
|
|
||||||
|
|
||||||
fn create_payment(&self, msg: CreatePayment) -> Status {
|
|
||||||
Status::Failure
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// #[wasm_bindgen]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn adapter() -> PayUAdapter {
|
pub extern "C" fn name() -> String {
|
||||||
PayUAdapter::new()
|
"pay_u".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[wasm_bindgen]
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn create_payment(msg: *const CreatePayment) -> i32 {
|
||||||
|
eprintln!("{:?}", msg);
|
||||||
|
Status::Failure as i32
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,14 @@ channels = { path = "../channels" }
|
|||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
config = { path = "../config" }
|
config = { path = "../config" }
|
||||||
db-utils = { path = "../db-utils" }
|
db-utils = { path = "../db-utils" }
|
||||||
|
gumdrop = { version = "0.8.1", features = [] }
|
||||||
|
llvmenv = { version = "0.3.2" }
|
||||||
model = { path = "../model", features = ["db"] }
|
model = { path = "../model", features = ["db"] }
|
||||||
|
openssl-src = { version = "111" }
|
||||||
|
openssl-sys = { version = "0.9", features = ['openssl-src'] }
|
||||||
opentelemetry = { version = "0.17.0" }
|
opentelemetry = { version = "0.17.0" }
|
||||||
opentelemetry-jaeger = { version = "0.17.0" }
|
opentelemetry-jaeger = { version = "0.17.0" }
|
||||||
|
payment_adapter = { path = "../payment_adapter" }
|
||||||
rumqttc = { version = "*" }
|
rumqttc = { version = "*" }
|
||||||
serde = { version = "1.0.137", features = ["derive"] }
|
serde = { version = "1.0.137", features = ["derive"] }
|
||||||
sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] }
|
sqlx = { version = "0.6.2", features = ["migrate", "runtime-actix-rustls", "all-types", "postgres"] }
|
||||||
@ -26,10 +31,8 @@ tracing = { version = "0.1.6" }
|
|||||||
tracing-opentelemetry = { version = "0.17.4" }
|
tracing-opentelemetry = { version = "0.17.4" }
|
||||||
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
||||||
uuid = { version = "1.2.1", features = ["serde"] }
|
uuid = { version = "1.2.1", features = ["serde"] }
|
||||||
wasmtime = { version = "3.0.0", default-features = false, features = ['cranelift', 'parallel-compilation', 'pooling-allocator'] }
|
wasmer = { version = "3", default-features = false, features = ['sys-default', 'wasmer-compiler-cranelift'] }
|
||||||
wasmtime-wasi = { version = "3.0.0" }
|
wasmer-wasi = { version = "3.0.2", default-features = false, features = ['host-fs', 'host-vnet'] }
|
||||||
gumdrop = { version = "0.8.1", features = [] }
|
|
||||||
payment_adapter = { path = "../payment_adapter" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
fake = { version = "2.5.0" }
|
fake = { version = "2.5.0" }
|
||||||
|
@ -2,7 +2,7 @@ use std::fs::read_dir;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use config::{AppConfig, UpdateConfig};
|
use config::{AppConfig, UpdateConfig};
|
||||||
use payment_adapter::PaymentAdapter;
|
// use payment_adapter::{CreatePayment, PaymentAdapter, Status};
|
||||||
|
|
||||||
// mod actions;
|
// mod actions;
|
||||||
// mod context;
|
// mod context;
|
||||||
@ -30,18 +30,18 @@ async fn main() {
|
|||||||
let opts: Opts = gumdrop::parse_args_default_or_exit();
|
let opts: Opts = gumdrop::parse_args_default_or_exit();
|
||||||
|
|
||||||
let config = config::default_load(&opts);
|
let config = config::default_load(&opts);
|
||||||
|
let payment_config = { config.lock().payment().clone() };
|
||||||
|
|
||||||
let engine = wasmtime::Engine::default();
|
use wasmer::{Instance, Module, Store, Value};
|
||||||
let mut linker = wasmtime::Linker::new(&engine);
|
let imports = wasmer::imports! {
|
||||||
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
|
// "" => { "name" => name, "create_payment" => create_payment, }
|
||||||
|
};
|
||||||
let wasi_ctx = wasmtime_wasi::WasiCtxBuilder::new()
|
let mut store = wasmer::Store::default();
|
||||||
.inherit_env()
|
// store.add_fuel(u64::MAX).unwrap();
|
||||||
.unwrap()
|
// store.data_mut().table().insert_at(
|
||||||
.inherit_stdio()
|
// payment_adapter::CONFIG_POS,
|
||||||
.inherit_stdio()
|
// Box::new(payment_config.clone()),
|
||||||
.build();
|
// );
|
||||||
let mut store = wasmtime::Store::new(&engine, wasi_ctx);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let adapters_path = config.lock().payment().adapters_path.clone();
|
let adapters_path = config.lock().payment().adapters_path.clone();
|
||||||
@ -53,23 +53,60 @@ async fn main() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
for file in dir.filter_map(|r| r.map(|r| r.path()).ok()) {
|
for file in dir.filter_map(|r| r.map(|r| r.path()).ok()) {
|
||||||
let module = wasmtime::Module::from_file(&engine, file).unwrap();
|
eprintln!("{:?}", file.extension());
|
||||||
let instance = linker.instantiate(&mut store, &module).unwrap();
|
if file.extension().and_then(|s| s.to_str()) != Some("wasm") {
|
||||||
let fnc =
|
|
||||||
match instance.get_typed_func::<(), dyn PaymentAdapter, _>(&mut store, "adapter") {
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!("{}", e);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ok(fnc) => fnc,
|
// let module = wasmtime::Module::from_file(&engine, file).unwrap();
|
||||||
|
// let instance = linker.instantiate(&mut store, &module).unwrap();
|
||||||
|
// // let config = wasmtime::ExternRef::new(payment_config.clone());
|
||||||
|
//
|
||||||
|
// let f = instance
|
||||||
|
// .get_typed_func::<Option<wasmtime::ExternRef>, i32, _>(&mut store,
|
||||||
|
// "create_payment") .unwrap();
|
||||||
|
|
||||||
|
let module = wasmer::Module::from_file(&store, file).unwrap();
|
||||||
|
let instance = Instance::new(&mut store, &module, &imports).unwrap();
|
||||||
|
|
||||||
|
{
|
||||||
|
let msg = payment_adapter::CreatePayment {
|
||||||
|
buyer: payment_adapter::Buyer {
|
||||||
|
email: "email".to_string(),
|
||||||
|
phone: "phone".to_string(),
|
||||||
|
first_name: "first_name".to_string(),
|
||||||
|
last_name: "last_name".to_string(),
|
||||||
|
language: "language".to_string(),
|
||||||
|
},
|
||||||
|
customer_ip: "customer_ip".to_string(),
|
||||||
|
currency: "currency".to_string(),
|
||||||
|
description: "description".to_string(),
|
||||||
|
cart_products: vec![],
|
||||||
|
items: Default::default(),
|
||||||
|
order_ext_id: "order_ext_id".to_string(),
|
||||||
|
notify_uri: "notify_uri".to_string(),
|
||||||
|
continue_uri: "continue_uri".to_string(),
|
||||||
};
|
};
|
||||||
let adapter = match fnc.call(&mut store, ()) {
|
|
||||||
Err(e) => {
|
let create_payment = instance.exports.get_function("create_payment").unwrap();
|
||||||
tracing::error!("{}", e);
|
let ext = wasmer::ExternRef::new(&mut store, msg);
|
||||||
continue;
|
let result = create_payment.call(&mut store, &[Value::ExternRef(Some(ext))]);
|
||||||
|
eprintln!("create payment res {:?}", result)
|
||||||
}
|
}
|
||||||
Ok(adapter) => adapter,
|
// let fnc =
|
||||||
};
|
// match instance.get_typed_func::<(), dyn PaymentAdapter,
|
||||||
|
// _>(&mut store, "adapter") { Err(e) => {
|
||||||
|
// tracing::error!("{}", e);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// Ok(fnc) => fnc,
|
||||||
|
// };
|
||||||
|
// let adapter = match fnc.call(&mut store, ()) {
|
||||||
|
// Err(e) => {
|
||||||
|
// tracing::error!("{}", e);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// Ok(adapter) => adapter,
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user