mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-12-22 19:49:24 +00:00
differentiate between app and order wallets
This commit is contained in:
parent
a8517fcade
commit
24c276c250
12 changed files with 117 additions and 19 deletions
|
@ -88,11 +88,16 @@ fn update_expiration(f_auth: &Authorization, address: &String) -> Authorization
|
||||||
|
|
||||||
/// Performs the signature verfication against stored auth
|
/// Performs the signature verfication against stored auth
|
||||||
pub async fn verify_login(aid: String, uid: String, signature: String) -> Authorization {
|
pub async fn verify_login(aid: String, uid: String, signature: String) -> Authorization {
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
||||||
let address = m_address.result.address;
|
let address = m_address.result.address;
|
||||||
let f_auth: Authorization = find(&aid);
|
let f_auth: Authorization = find(&aid);
|
||||||
if f_auth.xmr_address == utils::empty_string() {
|
if f_auth.xmr_address == utils::empty_string() {
|
||||||
error!("auth not found");
|
error!("auth not found");
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
return create(&address);
|
return create(&address);
|
||||||
}
|
}
|
||||||
let data: String = String::from(&f_auth.rnd);
|
let data: String = String::from(&f_auth.rnd);
|
||||||
|
@ -100,6 +105,7 @@ pub async fn verify_login(aid: String, uid: String, signature: String) -> Author
|
||||||
monero::verify(String::from(&address), data, String::from(&signature)).await;
|
monero::verify(String::from(&address), data, String::from(&signature)).await;
|
||||||
if sig_address == utils::ApplicationErrors::LoginError.value() {
|
if sig_address == utils::ApplicationErrors::LoginError.value() {
|
||||||
error!("signature validation failed");
|
error!("signature validation failed");
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
return f_auth;
|
return f_auth;
|
||||||
}
|
}
|
||||||
let f_user: User = user::find(&uid);
|
let f_user: User = user::find(&uid);
|
||||||
|
@ -116,16 +122,20 @@ pub async fn verify_login(aid: String, uid: String, signature: String) -> Author
|
||||||
&u_auth.aid,
|
&u_auth.aid,
|
||||||
&Authorization::to_db(&u_auth),
|
&Authorization::to_db(&u_auth),
|
||||||
);
|
);
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
return u_auth;
|
return u_auth;
|
||||||
} else if f_user.xmr_address != utils::empty_string() {
|
} else if f_user.xmr_address != utils::empty_string() {
|
||||||
info!("returning user");
|
info!("returning user");
|
||||||
let m_access = verify_access(&address, &signature).await;
|
let m_access = verify_access(&address, &signature).await;
|
||||||
if !m_access {
|
if !m_access {
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
return Default::default();
|
return Default::default();
|
||||||
}
|
}
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
return f_auth;
|
return f_auth;
|
||||||
} else {
|
} else {
|
||||||
error!("error creating user");
|
error!("error creating user");
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
return Default::default();
|
return Default::default();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +208,12 @@ impl<'r> FromRequest<'r> for BearerToken {
|
||||||
return Outcome::Success(BearerToken(utils::empty_string()));
|
return Outcome::Success(BearerToken(utils::empty_string()));
|
||||||
}
|
}
|
||||||
let token = request.headers().get_one("token");
|
let token = request.headers().get_one("token");
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let address = m_address.result.address;
|
let address = m_address.result.address;
|
||||||
debug!("{}", address);
|
debug!("{}", address);
|
||||||
match token {
|
match token {
|
||||||
|
|
|
@ -89,7 +89,12 @@ pub fn find_all() -> Vec<Contact> {
|
||||||
|
|
||||||
async fn validate_contact(j: &Json<Contact>) -> bool {
|
async fn validate_contact(j: &Json<Contact>) -> bool {
|
||||||
info!("validating contact: {}", &j.cid);
|
info!("validating contact: {}", &j.cid);
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let validate_address = monero::validate_address(&j.xmr_address).await;
|
let validate_address = monero::validate_address(&j.xmr_address).await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
j.cid.len() < utils::string_limit()
|
j.cid.len() < utils::string_limit()
|
||||||
&& j.i2p_address.len() < utils::string_limit()
|
&& j.i2p_address.len() < utils::string_limit()
|
||||||
&& j.i2p_address.contains(".b32.i2p")
|
&& j.i2p_address.contains(".b32.i2p")
|
||||||
|
@ -101,7 +106,12 @@ async fn validate_contact(j: &Json<Contact>) -> bool {
|
||||||
pub async fn share() -> Contact {
|
pub async fn share() -> Contact {
|
||||||
let vendor_env = std::env::var(NEVEKO_VENDOR_ENABLED).unwrap_or(String::from("0"));
|
let vendor_env = std::env::var(NEVEKO_VENDOR_ENABLED).unwrap_or(String::from("0"));
|
||||||
let is_vendor = vendor_env == String::from("1");
|
let is_vendor = vendor_env == String::from("1");
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let gpg_key = gpg::export_key().unwrap_or(Vec::new());
|
let gpg_key = gpg::export_key().unwrap_or(Vec::new());
|
||||||
let i2p_address = i2p::get_destination();
|
let i2p_address = i2p::get_destination();
|
||||||
let xmr_address = m_address.result.address;
|
let xmr_address = m_address.result.address;
|
||||||
|
@ -123,11 +133,11 @@ pub fn exists(from: &String) -> bool {
|
||||||
return addresses.contains(from);
|
return addresses.contains(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign for trusted neveko contacts
|
/// Sign for trusted nevmes contacts
|
||||||
///
|
///
|
||||||
/// UI/UX should have some prompt about the implication of trusting keys
|
/// UI/UX should have some prompt about the implication of trusting keys
|
||||||
///
|
///
|
||||||
/// however that is beyond the scope of this app. neveko assumes contacts
|
/// however that is beyond the scope of this app. nevmes assumes contacts
|
||||||
///
|
///
|
||||||
/// using the app already have some level of knowledge about each other.
|
/// using the app already have some level of knowledge about each other.
|
||||||
///
|
///
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub mod reqres; // http request/responses
|
||||||
pub mod user; // misc.
|
pub mod user; // misc.
|
||||||
pub mod utils; // user rep/service layer
|
pub mod utils; // user rep/service layer
|
||||||
|
|
||||||
|
pub const APP_NAME: &str = "neveko";
|
||||||
pub const NEVEKO_JWP_SECRET_KEY: &str = "NEVEKO_JWP_SECRET_KEY";
|
pub const NEVEKO_JWP_SECRET_KEY: &str = "NEVEKO_JWP_SECRET_KEY";
|
||||||
pub const NEVEKO_JWT_SECRET_KEY: &str = "NEVEKO_JWT_SECRET_KEY";
|
pub const NEVEKO_JWT_SECRET_KEY: &str = "NEVEKO_JWT_SECRET_KEY";
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ struct MultisigMessageData {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODOs(c2m):
|
TODOs(c2m):
|
||||||
- add wallet open before multisig methods
|
|
||||||
- API to valid payment and import multisig info
|
- API to valid payment and import multisig info
|
||||||
- API to sign and submit the signed tx set
|
- API to sign and submit the signed tx set
|
||||||
*/
|
*/
|
||||||
|
@ -451,6 +450,8 @@ fn is_fts_clear(r: String) -> bool {
|
||||||
/// `prepare_multisig_info` method.
|
/// `prepare_multisig_info` method.
|
||||||
pub async fn send_prepare_info(orid: &String, contact: &String) {
|
pub async fn send_prepare_info(orid: &String, contact: &String) {
|
||||||
let s = db::Interface::open();
|
let s = db::Interface::open();
|
||||||
|
let wallet_password = utils::empty_string();
|
||||||
|
monero::open_wallet(&orid, &wallet_password).await;
|
||||||
let prepare_info = monero::prepare_wallet().await;
|
let prepare_info = monero::prepare_wallet().await;
|
||||||
let k = format!("{}-{}", "fts-jwp", contact);
|
let k = format!("{}-{}", "fts-jwp", contact);
|
||||||
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
||||||
|
@ -465,6 +466,7 @@ pub async fn send_prepare_info(orid: &String, contact: &String) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let j_message: Json<Message> = utils::message_to_json(&message);
|
let j_message: Json<Message> = utils::message_to_json(&message);
|
||||||
|
monero::close_wallet(&orid, &wallet_password).await;
|
||||||
create(j_message, jwp, MessageType::Multisig).await;
|
create(j_message, jwp, MessageType::Multisig).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,6 +475,8 @@ pub async fn send_prepare_info(orid: &String, contact: &String) {
|
||||||
/// `make_multisig_info` method.
|
/// `make_multisig_info` method.
|
||||||
pub async fn send_make_info(orid: &String, contact: &String, info: Vec<String>) {
|
pub async fn send_make_info(orid: &String, contact: &String, info: Vec<String>) {
|
||||||
let s = db::Interface::open();
|
let s = db::Interface::open();
|
||||||
|
let wallet_password = utils::empty_string();
|
||||||
|
monero::open_wallet(&orid, &wallet_password).await;
|
||||||
let make_info = monero::make_wallet(info).await;
|
let make_info = monero::make_wallet(info).await;
|
||||||
let k = format!("{}-{}", "fts-jwp", contact);
|
let k = format!("{}-{}", "fts-jwp", contact);
|
||||||
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
||||||
|
@ -484,6 +488,7 @@ pub async fn send_make_info(orid: &String, contact: &String, info: Vec<String>)
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let j_message: Json<Message> = utils::message_to_json(&message);
|
let j_message: Json<Message> = utils::message_to_json(&message);
|
||||||
|
monero::close_wallet(&orid, &wallet_password).await;
|
||||||
create(j_message, jwp, MessageType::Multisig).await;
|
create(j_message, jwp, MessageType::Multisig).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,9 +497,9 @@ pub async fn send_make_info(orid: &String, contact: &String, info: Vec<String>)
|
||||||
/// `exchange_multisig_keys` method.
|
/// `exchange_multisig_keys` method.
|
||||||
pub async fn send_exchange_info(orid: &String, contact: &String, info: Vec<String>) {
|
pub async fn send_exchange_info(orid: &String, contact: &String, info: Vec<String>) {
|
||||||
let s = db::Interface::open();
|
let s = db::Interface::open();
|
||||||
let wallet_password =
|
let wallet_password = utils::empty_string();
|
||||||
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
monero::open_wallet(&orid, &wallet_password).await;
|
||||||
let exchange_info = monero::exchange_multisig_keys(false, info, wallet_password).await;
|
let exchange_info = monero::exchange_multisig_keys(false, info, &wallet_password).await;
|
||||||
let k = format!("{}-{}", "fts-jwp", contact);
|
let k = format!("{}-{}", "fts-jwp", contact);
|
||||||
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
||||||
let body_str = format!(
|
let body_str = format!(
|
||||||
|
@ -508,6 +513,7 @@ pub async fn send_exchange_info(orid: &String, contact: &String, info: Vec<Strin
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let j_message: Json<Message> = utils::message_to_json(&message);
|
let j_message: Json<Message> = utils::message_to_json(&message);
|
||||||
|
monero::close_wallet(&orid, &wallet_password).await;
|
||||||
create(j_message, jwp, MessageType::Multisig).await;
|
create(j_message, jwp, MessageType::Multisig).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,6 +522,8 @@ pub async fn send_exchange_info(orid: &String, contact: &String, info: Vec<Strin
|
||||||
/// `export_multisig_info` method.
|
/// `export_multisig_info` method.
|
||||||
pub async fn send_export_info(orid: &String, contact: &String) {
|
pub async fn send_export_info(orid: &String, contact: &String) {
|
||||||
let s = db::Interface::open();
|
let s = db::Interface::open();
|
||||||
|
let wallet_password = utils::empty_string();
|
||||||
|
monero::open_wallet(&orid, &wallet_password).await;
|
||||||
let exchange_info = monero::export_multisig_info().await;
|
let exchange_info = monero::export_multisig_info().await;
|
||||||
let k = format!("{}-{}", "fts-jwp", contact);
|
let k = format!("{}-{}", "fts-jwp", contact);
|
||||||
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
let jwp = db::Interface::read(&s.env, &s.handle, &k);
|
||||||
|
@ -527,6 +535,7 @@ pub async fn send_export_info(orid: &String, contact: &String) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let j_message: Json<Message> = utils::message_to_json(&message);
|
let j_message: Json<Message> = utils::message_to_json(&message);
|
||||||
|
monero::close_wallet(&orid, &wallet_password).await;
|
||||||
create(j_message, jwp, MessageType::Multisig).await;
|
create(j_message, jwp, MessageType::Multisig).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -312,12 +312,12 @@ pub async fn verify(address: String, data: String, signature: String) -> String
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the xmr rpc 'create_wallet' method
|
/// Performs the xmr rpc 'create_wallet' method
|
||||||
pub async fn create_wallet(filename: String, password: &String) -> bool {
|
pub async fn create_wallet(filename: &String, password: &String) -> bool {
|
||||||
info!("executing {}", RpcFields::CreateWallet.value());
|
info!("executing {}", RpcFields::CreateWallet.value());
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let host = get_rpc_host();
|
let host = get_rpc_host();
|
||||||
let params = reqres::XmrRpcCreateWalletParams {
|
let params = reqres::XmrRpcCreateWalletParams {
|
||||||
filename,
|
filename: String::from(filename),
|
||||||
language: String::from("English"),
|
language: String::from("English"),
|
||||||
password: String::from(password),
|
password: String::from(password),
|
||||||
};
|
};
|
||||||
|
@ -353,12 +353,12 @@ pub async fn create_wallet(filename: String, password: &String) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the xmr rpc 'open_wallet' method
|
/// Performs the xmr rpc 'open_wallet' method
|
||||||
pub async fn open_wallet(filename: String, password: &String) -> bool {
|
pub async fn open_wallet(filename: &String, password: &String) -> bool {
|
||||||
info!("executing {}", RpcFields::Open.value());
|
info!("executing {}", RpcFields::Open.value());
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let host = get_rpc_host();
|
let host = get_rpc_host();
|
||||||
let params = reqres::XmrRpcOpenWalletParams {
|
let params = reqres::XmrRpcOpenWalletParams {
|
||||||
filename,
|
filename: String::from(filename),
|
||||||
password: String::from(password),
|
password: String::from(password),
|
||||||
};
|
};
|
||||||
let req = reqres::XmrRpcOpenRequest {
|
let req = reqres::XmrRpcOpenRequest {
|
||||||
|
@ -394,11 +394,14 @@ pub async fn open_wallet(filename: String, password: &String) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the xmr rpc 'close_wallet' method
|
/// Performs the xmr rpc 'close_wallet' method
|
||||||
pub async fn close_wallet(filename: String, password: String) -> bool {
|
pub async fn close_wallet(filename: &String, password: &String) -> bool {
|
||||||
info!("executing {}", RpcFields::Close.value());
|
info!("executing {}", RpcFields::Close.value());
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let host = get_rpc_host();
|
let host = get_rpc_host();
|
||||||
let params = reqres::XmrRpcOpenWalletParams { filename, password };
|
let params = reqres::XmrRpcOpenWalletParams {
|
||||||
|
filename: String::from(filename),
|
||||||
|
password: String::from(password),
|
||||||
|
};
|
||||||
let req = reqres::XmrRpcOpenRequest {
|
let req = reqres::XmrRpcOpenRequest {
|
||||||
jsonrpc: RpcFields::JsonRpcVersion.value(),
|
jsonrpc: RpcFields::JsonRpcVersion.value(),
|
||||||
id: RpcFields::Id.value(),
|
id: RpcFields::Id.value(),
|
||||||
|
@ -688,14 +691,14 @@ pub async fn sign_multisig(tx_data_hex: String) -> reqres::XmrRpcSignMultisigRes
|
||||||
pub async fn exchange_multisig_keys(
|
pub async fn exchange_multisig_keys(
|
||||||
force_update_use_with_caution: bool,
|
force_update_use_with_caution: bool,
|
||||||
multisig_info: Vec<String>,
|
multisig_info: Vec<String>,
|
||||||
password: String,
|
password: &String,
|
||||||
) -> reqres::XmrRpcExchangeMultisigKeysResponse {
|
) -> reqres::XmrRpcExchangeMultisigKeysResponse {
|
||||||
info!("executing: {}", RpcFields::ExchangeMultisigKeys.value());
|
info!("executing: {}", RpcFields::ExchangeMultisigKeys.value());
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let host = get_rpc_host();
|
let host = get_rpc_host();
|
||||||
let params = reqres::XmrRpcExchangeMultisigKeysParams {
|
let params = reqres::XmrRpcExchangeMultisigKeysParams {
|
||||||
force_update_use_with_caution,
|
force_update_use_with_caution,
|
||||||
password,
|
password: String::from(password),
|
||||||
multisig_info,
|
multisig_info,
|
||||||
};
|
};
|
||||||
let req = reqres::XmrRpcExchangeMultisigKeysRequest {
|
let req = reqres::XmrRpcExchangeMultisigKeysRequest {
|
||||||
|
|
|
@ -56,7 +56,12 @@ impl Default for TxProof {
|
||||||
pub async fn create_invoice() -> reqres::Invoice {
|
pub async fn create_invoice() -> reqres::Invoice {
|
||||||
info!("creating invoice");
|
info!("creating invoice");
|
||||||
// create a new subaddress
|
// create a new subaddress
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let c_address = monero::create_address().await;
|
let c_address = monero::create_address().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let address = c_address.result.address;
|
let address = c_address.result.address;
|
||||||
let pay_threshold = utils::get_payment_threshold();
|
let pay_threshold = utils::get_payment_threshold();
|
||||||
let conf_threshold = utils::get_conf_threshold();
|
let conf_threshold = utils::get_conf_threshold();
|
||||||
|
@ -251,6 +256,10 @@ impl<'r> FromRequest<'r> for PaymentProof {
|
||||||
// jwp creation, however, will always require blockchain validation?
|
// jwp creation, however, will always require blockchain validation?
|
||||||
// future validations not so much
|
// future validations not so much
|
||||||
async fn validate_proof(txp: &TxProof) -> TxProof {
|
async fn validate_proof(txp: &TxProof) -> TxProof {
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
// verify unlock time isn't something funky (e.g. > 20)
|
// verify unlock time isn't something funky (e.g. > 20)
|
||||||
let tx: reqres::XmrRpcGetTxByIdResponse = monero::get_transfer_by_txid(&txp.hash).await;
|
let tx: reqres::XmrRpcGetTxByIdResponse = monero::get_transfer_by_txid(&txp.hash).await;
|
||||||
let unlock_time = tx.result.transfer.unlock_time;
|
let unlock_time = tx.result.transfer.unlock_time;
|
||||||
|
@ -271,6 +280,7 @@ async fn validate_proof(txp: &TxProof) -> TxProof {
|
||||||
signature: String::from(&txp.signature),
|
signature: String::from(&txp.signature),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +290,12 @@ async fn validate_proof(txp: &TxProof) -> TxProof {
|
||||||
///
|
///
|
||||||
/// for faster lookups (check minor > 0)
|
/// for faster lookups (check minor > 0)
|
||||||
async fn validate_subaddress(subaddress: &String) -> bool {
|
async fn validate_subaddress(subaddress: &String) -> bool {
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let m_address = monero::get_address().await;
|
let m_address = monero::get_address().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let all_address = m_address.result.addresses;
|
let all_address = m_address.result.addresses;
|
||||||
let mut address_list: Vec<String> = Vec::new();
|
let mut address_list: Vec<String> = Vec::new();
|
||||||
for s_address in all_address {
|
for s_address in all_address {
|
||||||
|
|
|
@ -279,14 +279,14 @@ fn create_wallet_dir() {
|
||||||
/// Generate application wallet at startup if none exist
|
/// Generate application wallet at startup if none exist
|
||||||
async fn gen_app_wallet(password: &String) {
|
async fn gen_app_wallet(password: &String) {
|
||||||
info!("fetching application wallet");
|
info!("fetching application wallet");
|
||||||
let filename = "neveko";
|
let filename = String::from(crate::APP_NAME);
|
||||||
let mut m_wallet = monero::open_wallet(String::from(filename), password).await;
|
let mut m_wallet = monero::open_wallet(&filename, password).await;
|
||||||
if !m_wallet {
|
if !m_wallet {
|
||||||
m_wallet = monero::create_wallet(String::from(filename), password).await;
|
m_wallet = monero::create_wallet(&filename, password).await;
|
||||||
if !m_wallet {
|
if !m_wallet {
|
||||||
error!("failed to create wallet")
|
error!("failed to create wallet")
|
||||||
} else {
|
} else {
|
||||||
m_wallet = monero::open_wallet(String::from(filename), password).await;
|
m_wallet = monero::open_wallet(&filename, password).await;
|
||||||
if m_wallet {
|
if m_wallet {
|
||||||
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
let m_address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
||||||
info!("app wallet address: {}", m_address.result.address)
|
info!("app wallet address: {}", m_address.result.address)
|
||||||
|
@ -638,7 +638,13 @@ pub async fn estimate_fee() -> u128 {
|
||||||
///
|
///
|
||||||
/// determine whether or not a transfer for a given invoice is possible.
|
/// determine whether or not a transfer for a given invoice is possible.
|
||||||
pub async fn can_transfer(invoice: u128) -> bool {
|
pub async fn can_transfer(invoice: u128) -> bool {
|
||||||
|
let wallet_name = String::from(crate::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(crate::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let balance = monero::get_balance().await;
|
let balance = monero::get_balance().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let fee = estimate_fee().await;
|
let fee = estimate_fee().await;
|
||||||
debug!("fee estimated to: {}", fee);
|
debug!("fee estimated to: {}", fee);
|
||||||
debug!("balance: {}", balance.result.unlocked_balance);
|
debug!("balance: {}", balance.result.unlocked_balance);
|
||||||
|
|
|
@ -690,6 +690,11 @@ fn send_payment_req(
|
||||||
let ptxp_address = String::from(&d.address);
|
let ptxp_address = String::from(&d.address);
|
||||||
let ftxp_address = String::from(&d.address);
|
let ftxp_address = String::from(&d.address);
|
||||||
log::debug!("sending {} piconero(s) to: {}", &d.amount, &d.address);
|
log::debug!("sending {} piconero(s) to: {}", &d.amount, &d.address);
|
||||||
|
let wallet_name = String::from(neveko_core::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(neveko_core::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let transfer: reqres::XmrRpcTransferResponse = monero::transfer(d).await;
|
let transfer: reqres::XmrRpcTransferResponse = monero::transfer(d).await;
|
||||||
// in order to keep the jwp creation process transparent to the user
|
// in order to keep the jwp creation process transparent to the user
|
||||||
// we will process all logic in one shot here.
|
// we will process all logic in one shot here.
|
||||||
|
@ -739,6 +744,7 @@ fn send_payment_req(
|
||||||
String::from(&contact),
|
String::from(&contact),
|
||||||
&ftxp.hash
|
&ftxp.hash
|
||||||
);
|
);
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
// if we made it this far we can now request a JWP from our friend
|
// if we made it this far we can now request a JWP from our friend
|
||||||
match proof::prove_payment(String::from(&contact), &ftxp).await {
|
match proof::prove_payment(String::from(&contact), &ftxp).await {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
|
|
|
@ -364,7 +364,13 @@ fn send_ver_req(tx: Sender<reqres::XmrRpcVersionResponse>, ctx: egui::Context) {
|
||||||
|
|
||||||
fn send_address_req(tx: Sender<reqres::XmrRpcAddressResponse>, ctx: egui::Context) {
|
fn send_address_req(tx: Sender<reqres::XmrRpcAddressResponse>, ctx: egui::Context) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
let wallet_name = String::from(neveko_core::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(neveko_core::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
let address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let _ = tx.send(address);
|
let _ = tx.send(address);
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
});
|
});
|
||||||
|
@ -372,7 +378,13 @@ fn send_address_req(tx: Sender<reqres::XmrRpcAddressResponse>, ctx: egui::Contex
|
||||||
|
|
||||||
fn send_balance_req(tx: Sender<reqres::XmrRpcBalanceResponse>, ctx: egui::Context) {
|
fn send_balance_req(tx: Sender<reqres::XmrRpcBalanceResponse>, ctx: egui::Context) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
let wallet_name = String::from(neveko_core::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(neveko_core::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let balance: reqres::XmrRpcBalanceResponse = monero::get_balance().await;
|
let balance: reqres::XmrRpcBalanceResponse = monero::get_balance().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let _ = tx.send(balance);
|
let _ = tx.send(balance);
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
});
|
});
|
||||||
|
|
|
@ -139,7 +139,13 @@ impl eframe::App for WalletApp {
|
||||||
|
|
||||||
fn send_address_req(tx: Sender<reqres::XmrRpcAddressResponse>, ctx: egui::Context) {
|
fn send_address_req(tx: Sender<reqres::XmrRpcAddressResponse>, ctx: egui::Context) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
let wallet_name = String::from(neveko_core::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(neveko_core::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
let address: reqres::XmrRpcAddressResponse = monero::get_address().await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let _ = tx.send(address);
|
let _ = tx.send(address);
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
});
|
});
|
||||||
|
@ -151,7 +157,13 @@ fn send_sweep_all_req(
|
||||||
address: String,
|
address: String,
|
||||||
) {
|
) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
let wallet_name = String::from(neveko_core::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(neveko_core::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::open_wallet(&wallet_name, &wallet_password).await;
|
||||||
let result: reqres::XmrRpcSweepAllResponse = monero::sweep_all(address).await;
|
let result: reqres::XmrRpcSweepAllResponse = monero::sweep_all(address).await;
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let _ = tx.send(result);
|
let _ = tx.send(result);
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,8 @@ use std::sync::mpsc::{
|
||||||
Sender,
|
Sender,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO(c2m): gui marketplace integration
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
|
@ -33,6 +33,11 @@ impl StatusType {
|
||||||
/// Create a intial order
|
/// Create a intial order
|
||||||
pub async fn create(j_order: Json<reqres::OrderRequest>) -> Order {
|
pub async fn create(j_order: Json<reqres::OrderRequest>) -> Order {
|
||||||
info!("creating order");
|
info!("creating order");
|
||||||
|
let wallet_name = String::from(neveko_core::APP_NAME);
|
||||||
|
let wallet_password =
|
||||||
|
std::env::var(neveko_core::MONERO_WALLET_PASSWORD)
|
||||||
|
.unwrap_or(String::from("password"));
|
||||||
|
monero::close_wallet(&wallet_name, &wallet_password).await;
|
||||||
let ts = chrono::offset::Utc::now().timestamp();
|
let ts = chrono::offset::Utc::now().timestamp();
|
||||||
let orid: String = format!("O{}", utils::generate_rnd());
|
let orid: String = format!("O{}", utils::generate_rnd());
|
||||||
let r_subaddress = monero::create_address().await;
|
let r_subaddress = monero::create_address().await;
|
||||||
|
@ -49,9 +54,10 @@ pub async fn create(j_order: Json<reqres::OrderRequest>) -> Order {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
debug!("insert order: {:?}", new_order);
|
debug!("insert order: {:?}", new_order);
|
||||||
let m_wallet = monero::create_wallet(String::from(&orid), &utils::empty_string()).await;
|
let m_wallet = monero::create_wallet(&orid, &utils::empty_string()).await;
|
||||||
if !m_wallet {
|
if !m_wallet {
|
||||||
error!("error creating msig wallet for order {}", &orid);
|
error!("error creating msig wallet for order {}", &orid);
|
||||||
|
monero::close_wallet(&orid, &wallet_password).await;
|
||||||
return Default::default();
|
return Default::default();
|
||||||
}
|
}
|
||||||
debug!("insert order: {:?}", &new_order);
|
debug!("insert order: {:?}", &new_order);
|
||||||
|
@ -67,6 +73,7 @@ pub async fn create(j_order: Json<reqres::OrderRequest>) -> Order {
|
||||||
let order_list = [r, String::from(&orid)].join(",");
|
let order_list = [r, String::from(&orid)].join(",");
|
||||||
debug!("writing order index {} for id: {}", order_list, list_key);
|
debug!("writing order index {} for id: {}", order_list, list_key);
|
||||||
db::Interface::write(&s.env, &s.handle, &String::from(list_key), &order_list);
|
db::Interface::write(&s.env, &s.handle, &String::from(list_key), &order_list);
|
||||||
|
monero::close_wallet(&orid, &wallet_password).await;
|
||||||
new_order
|
new_order
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue