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/lang_provider",
|
||||
"crates/payment_adapter",
|
||||
"crates/payment_adapter_pay_u",
|
||||
# artifacts
|
||||
# "crates/db-seed",
|
||||
# "crates/api",
|
||||
@ -28,6 +27,9 @@ members = [
|
||||
"vendor/t_pay",
|
||||
"vendor/pay_u",
|
||||
]
|
||||
exclude = [
|
||||
"crates/payment_adapter_pay_u",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
@ -12,7 +12,6 @@ actix-web = { version = "4.0", features = [], optional = true }
|
||||
cookie = { version = "0.16.1", features = ["signed"], optional = true }
|
||||
parking_lot = { version = "0.12", features = [] }
|
||||
password-hash = { version = "0.4", features = ["alloc"] }
|
||||
#pay_u = { path = "../../vendor/pay_u", features = ["single-client"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", features = [] }
|
||||
thiserror = { version = "1.0" }
|
||||
|
@ -510,7 +510,7 @@ impl OrderConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
pub struct PaymentProviderConfig {
|
||||
pub client_id: Option<String>,
|
||||
pub client_secret: Option<String>,
|
||||
@ -519,7 +519,7 @@ pub struct PaymentProviderConfig {
|
||||
pub custom: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
pub struct PaymentConfig {
|
||||
pub rpc_port: u16,
|
||||
pub rpc_bind: String,
|
||||
|
@ -6,5 +6,3 @@ edition = "2021"
|
||||
[dependencies]
|
||||
config = { path = "../config", default-features = false, features = [] }
|
||||
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 model::*;
|
||||
use wasmtime::WasmResults;
|
||||
|
||||
pub const CONFIG_POS: u32 = 3;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
@ -12,6 +13,7 @@ pub enum Status {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct Buyer {
|
||||
/// Required customer e-mail
|
||||
pub email: String,
|
||||
@ -26,6 +28,7 @@ pub struct Buyer {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct Product {
|
||||
pub id: ProductId,
|
||||
pub name: String,
|
||||
@ -34,6 +37,8 @@ pub struct Product {
|
||||
pub quantity: Quantity,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct CreatePayment {
|
||||
// pub client: PayUClient,
|
||||
pub buyer: Buyer,
|
||||
|
@ -7,7 +7,11 @@ edition = "2021"
|
||||
crate-type = ['cdylib']
|
||||
|
||||
[dependencies]
|
||||
payment_adapter = { path = "../payment_adapter" }
|
||||
pay_u = { path = "../../vendor/pay_u" }
|
||||
wasmtime = { version = "3.0.1" }
|
||||
wasmtime-api = { version = "0.4.0" }
|
||||
payment_adapter = { path = "../payment_adapter" }
|
||||
#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 wasmtime::{ValType, WasmParams, WasmResults};
|
||||
use std::os::wasi::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PayUAdapter {}
|
||||
use payment_adapter::{CreatePayment, Status};
|
||||
// use wasm_bindgen::prelude::*;
|
||||
|
||||
impl PayUAdapter {
|
||||
pub fn new() -> Self {
|
||||
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
|
||||
}
|
||||
}
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
// #[wasm_bindgen]
|
||||
#[no_mangle]
|
||||
pub fn adapter() -> PayUAdapter {
|
||||
PayUAdapter::new()
|
||||
pub extern "C" fn name() -> String {
|
||||
"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"] }
|
||||
config = { path = "../config" }
|
||||
db-utils = { path = "../db-utils" }
|
||||
gumdrop = { version = "0.8.1", features = [] }
|
||||
llvmenv = { version = "0.3.2" }
|
||||
model = { path = "../model", features = ["db"] }
|
||||
openssl-src = { version = "111" }
|
||||
openssl-sys = { version = "0.9", features = ['openssl-src'] }
|
||||
opentelemetry = { version = "0.17.0" }
|
||||
opentelemetry-jaeger = { version = "0.17.0" }
|
||||
payment_adapter = { path = "../payment_adapter" }
|
||||
rumqttc = { version = "*" }
|
||||
serde = { version = "1.0.137", features = ["derive"] }
|
||||
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-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
||||
uuid = { version = "1.2.1", features = ["serde"] }
|
||||
wasmtime = { version = "3.0.0", default-features = false, features = ['cranelift', 'parallel-compilation', 'pooling-allocator'] }
|
||||
wasmtime-wasi = { version = "3.0.0" }
|
||||
gumdrop = { version = "0.8.1", features = [] }
|
||||
payment_adapter = { path = "../payment_adapter" }
|
||||
wasmer = { version = "3", default-features = false, features = ['sys-default', 'wasmer-compiler-cranelift'] }
|
||||
wasmer-wasi = { version = "3.0.2", default-features = false, features = ['host-fs', 'host-vnet'] }
|
||||
|
||||
[dev-dependencies]
|
||||
fake = { version = "2.5.0" }
|
||||
|
@ -2,7 +2,7 @@ use std::fs::read_dir;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use config::{AppConfig, UpdateConfig};
|
||||
use payment_adapter::PaymentAdapter;
|
||||
// use payment_adapter::{CreatePayment, PaymentAdapter, Status};
|
||||
|
||||
// mod actions;
|
||||
// mod context;
|
||||
@ -30,18 +30,18 @@ async fn main() {
|
||||
let opts: Opts = gumdrop::parse_args_default_or_exit();
|
||||
|
||||
let config = config::default_load(&opts);
|
||||
let payment_config = { config.lock().payment().clone() };
|
||||
|
||||
let engine = wasmtime::Engine::default();
|
||||
let mut linker = wasmtime::Linker::new(&engine);
|
||||
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
|
||||
|
||||
let wasi_ctx = wasmtime_wasi::WasiCtxBuilder::new()
|
||||
.inherit_env()
|
||||
.unwrap()
|
||||
.inherit_stdio()
|
||||
.inherit_stdio()
|
||||
.build();
|
||||
let mut store = wasmtime::Store::new(&engine, wasi_ctx);
|
||||
use wasmer::{Instance, Module, Store, Value};
|
||||
let imports = wasmer::imports! {
|
||||
// "" => { "name" => name, "create_payment" => create_payment, }
|
||||
};
|
||||
let mut store = wasmer::Store::default();
|
||||
// store.add_fuel(u64::MAX).unwrap();
|
||||
// store.data_mut().table().insert_at(
|
||||
// payment_adapter::CONFIG_POS,
|
||||
// Box::new(payment_config.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()) {
|
||||
let module = wasmtime::Module::from_file(&engine, file).unwrap();
|
||||
let instance = linker.instantiate(&mut store, &module).unwrap();
|
||||
let fnc =
|
||||
match instance.get_typed_func::<(), dyn PaymentAdapter, _>(&mut store, "adapter") {
|
||||
Err(e) => {
|
||||
tracing::error!("{}", e);
|
||||
continue;
|
||||
}
|
||||
Ok(fnc) => fnc,
|
||||
eprintln!("{:?}", file.extension());
|
||||
if file.extension().and_then(|s| s.to_str()) != Some("wasm") {
|
||||
continue;
|
||||
}
|
||||
// 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) => {
|
||||
tracing::error!("{}", e);
|
||||
continue;
|
||||
}
|
||||
Ok(adapter) => adapter,
|
||||
};
|
||||
|
||||
let create_payment = instance.exports.get_function("create_payment").unwrap();
|
||||
let ext = wasmer::ExternRef::new(&mut store, msg);
|
||||
let result = create_payment.call(&mut store, &[Value::ExternRef(Some(ext))]);
|
||||
eprintln!("create payment res {:?}", result)
|
||||
}
|
||||
// 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