Remove default_currency() method from config object
Preparing for multi-currency deployments.
This commit is contained in:
parent
b3fb1c612c
commit
ea4d15da48
5 changed files with 12 additions and 13 deletions
|
@ -15,7 +15,6 @@ use crate::utils::crypto::{
|
||||||
generate_private_key,
|
generate_private_key,
|
||||||
serialize_private_key,
|
serialize_private_key,
|
||||||
};
|
};
|
||||||
use crate::utils::currencies::Currency;
|
|
||||||
use crate::utils::files::{set_file_permissions, write_file};
|
use crate::utils::files::{set_file_permissions, write_file};
|
||||||
|
|
||||||
use super::blockchain::BlockchainConfig;
|
use super::blockchain::BlockchainConfig;
|
||||||
|
@ -138,10 +137,6 @@ impl Config {
|
||||||
pub fn media_dir(&self) -> PathBuf {
|
pub fn media_dir(&self) -> PathBuf {
|
||||||
self.storage_dir.join("media")
|
self.storage_dir.join("media")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_currency(&self) -> Currency {
|
|
||||||
Currency::Ethereum
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
@ -63,6 +63,7 @@ use crate::utils::crypto::{
|
||||||
generate_private_key,
|
generate_private_key,
|
||||||
serialize_private_key,
|
serialize_private_key,
|
||||||
};
|
};
|
||||||
|
use crate::utils::currencies::Currency;
|
||||||
use super::helpers::get_relationship;
|
use super::helpers::get_relationship;
|
||||||
use super::types::{
|
use super::types::{
|
||||||
Account,
|
Account,
|
||||||
|
@ -237,11 +238,13 @@ async fn create_identity_proof(
|
||||||
let actor_id = current_user.profile.actor_id(&config.instance_url());
|
let actor_id = current_user.profile.actor_id(&config.instance_url());
|
||||||
let did = proof_data.did.parse::<DidPkh>()
|
let did = proof_data.did.parse::<DidPkh>()
|
||||||
.map_err(|_| ValidationError("invalid DID"))?;
|
.map_err(|_| ValidationError("invalid DID"))?;
|
||||||
if did.currency() != Some(config.default_currency()) {
|
if did.currency() != Some(Currency::Ethereum) {
|
||||||
|
// DID must point to Ethereum Mainnet because it is a valid
|
||||||
|
// identifier on any Ethereum chain
|
||||||
return Err(ValidationError("unsupported chain ID").into());
|
return Err(ValidationError("unsupported chain ID").into());
|
||||||
};
|
};
|
||||||
let maybe_public_address =
|
let maybe_public_address =
|
||||||
current_user.public_wallet_address(&config.default_currency());
|
current_user.public_wallet_address(&Currency::Ethereum);
|
||||||
if let Some(address) = maybe_public_address {
|
if let Some(address) = maybe_public_address {
|
||||||
if did.address != address {
|
if did.address != address {
|
||||||
return Err(ValidationError("DID doesn't match current identity").into());
|
return Err(ValidationError("DID doesn't match current identity").into());
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::models::users::queries::{
|
||||||
get_user_by_login_address,
|
get_user_by_login_address,
|
||||||
};
|
};
|
||||||
use crate::utils::crypto::verify_password;
|
use crate::utils::crypto::verify_password;
|
||||||
use crate::utils::currencies::validate_wallet_address;
|
use crate::utils::currencies::{validate_wallet_address, Currency};
|
||||||
use super::types::{TokenRequest, TokenResponse};
|
use super::types::{TokenRequest, TokenResponse};
|
||||||
use super::utils::generate_access_token;
|
use super::utils::generate_access_token;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ async fn token_view(
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
let wallet_address = request_data.wallet_address.as_ref()
|
let wallet_address = request_data.wallet_address.as_ref()
|
||||||
.ok_or(ValidationError("wallet address is required"))?;
|
.ok_or(ValidationError("wallet address is required"))?;
|
||||||
validate_wallet_address(&config.default_currency(), wallet_address)?;
|
validate_wallet_address(&Currency::Ethereum, wallet_address)?;
|
||||||
get_user_by_login_address(db_client, wallet_address).await?
|
get_user_by_login_address(db_client, wallet_address).await?
|
||||||
},
|
},
|
||||||
"eip4361" => {
|
"eip4361" => {
|
||||||
|
|
|
@ -38,6 +38,7 @@ use crate::models::reactions::queries::{
|
||||||
create_reaction,
|
create_reaction,
|
||||||
delete_reaction,
|
delete_reaction,
|
||||||
};
|
};
|
||||||
|
use crate::utils::currencies::Currency;
|
||||||
use super::helpers::{
|
use super::helpers::{
|
||||||
build_status,
|
build_status,
|
||||||
build_status_list,
|
build_status_list,
|
||||||
|
@ -429,9 +430,9 @@ async fn get_signature(
|
||||||
.ok_or(HttpError::NotSupported)?
|
.ok_or(HttpError::NotSupported)?
|
||||||
.ethereum_config()
|
.ethereum_config()
|
||||||
.ok_or(HttpError::NotSupported)?;
|
.ok_or(HttpError::NotSupported)?;
|
||||||
// User must have a public wallet address
|
// User must have a public ethereum address
|
||||||
let wallet_address = current_user
|
let wallet_address = current_user
|
||||||
.public_wallet_address(&config.default_currency())
|
.public_wallet_address(&Currency::Ethereum)
|
||||||
.ok_or(HttpError::PermissionError)?;
|
.ok_or(HttpError::PermissionError)?;
|
||||||
let post = get_post_by_id(db_client, &status_id).await?;
|
let post = get_post_by_id(db_client, &status_id).await?;
|
||||||
if post.author.id != current_user.id || !post.is_public() || post.repost_of_id.is_some() {
|
if post.author.id != current_user.id || !post.is_public() || post.repost_of_id.is_some() {
|
||||||
|
|
|
@ -36,11 +36,11 @@ pub async fn authorize_subscription(
|
||||||
.ok_or(HttpError::NotSupported)?
|
.ok_or(HttpError::NotSupported)?
|
||||||
.ethereum_config()
|
.ethereum_config()
|
||||||
.ok_or(HttpError::NotSupported)?;
|
.ok_or(HttpError::NotSupported)?;
|
||||||
// The user must have a public wallet address,
|
// The user must have a public ethereum address,
|
||||||
// because subscribers should be able
|
// because subscribers should be able
|
||||||
// to verify that payments are actually sent to the recipient.
|
// to verify that payments are actually sent to the recipient.
|
||||||
let wallet_address = current_user
|
let wallet_address = current_user
|
||||||
.public_wallet_address(&config.default_currency())
|
.public_wallet_address(&Currency::Ethereum)
|
||||||
.ok_or(HttpError::PermissionError)?;
|
.ok_or(HttpError::PermissionError)?;
|
||||||
let signature = create_subscription_signature(
|
let signature = create_subscription_signature(
|
||||||
ethereum_config,
|
ethereum_config,
|
||||||
|
|
Loading…
Reference in a new issue