diff --git a/CHANGELOG.md b/CHANGELOG.md index 1543d12..4990a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Ignore errors when importing activities from outbox. - Make activity limit in outbox fetcher adjustable. +- Changed `reset-subscriptions` command arguments (removes subscription options by default). ## [1.21.0] - 2023-04-12 diff --git a/mitra-cli/src/cli.rs b/mitra-cli/src/cli.rs index a946a9c..276b93b 100644 --- a/mitra-cli/src/cli.rs +++ b/mitra-cli/src/cli.rs @@ -598,8 +598,9 @@ impl UpdateCurrentBlock { /// (can be used during development or when switching between chains) #[derive(Parser)] pub struct ResetSubscriptions { + // Subscription options are removed by default #[clap(long)] - ethereum_contract_replaced: bool, + keep_subscription_options: bool, } impl ResetSubscriptions { @@ -608,7 +609,7 @@ impl ResetSubscriptions { _config: &Config, db_client: &mut impl DatabaseClient, ) -> Result<(), Error> { - reset_subscriptions(db_client, self.ethereum_contract_replaced).await?; + reset_subscriptions(db_client, self.keep_subscription_options).await?; println!("subscriptions deleted"); Ok(()) } diff --git a/mitra-models/src/subscriptions/queries.rs b/mitra-models/src/subscriptions/queries.rs index 3b82f95..ddc9caf 100644 --- a/mitra-models/src/subscriptions/queries.rs +++ b/mitra-models/src/subscriptions/queries.rs @@ -155,12 +155,14 @@ pub async fn get_incoming_subscriptions( pub async fn reset_subscriptions( db_client: &mut impl DatabaseClient, - ethereum_contract_replaced: bool, + keep_subscription_options: bool, ) -> Result<(), DatabaseError> { let transaction = db_client.transaction().await?; - if ethereum_contract_replaced { - // Ethereum subscription configuration is stored in contract. - // If contract is replaced, payment option needs to be deleted. + if !keep_subscription_options { + let payment_types = vec![ + i16::from(&PaymentType::EthereumSubscription), + i16::from(&PaymentType::MoneroSubscription), + ]; transaction.execute( " UPDATE actor_profile @@ -171,10 +173,10 @@ pub async fn reset_subscriptions( EXISTS ( SELECT 1 FROM jsonb_array_elements(payment_options) AS option - WHERE CAST(option ->> 'payment_type' AS SMALLINT) = $1 + WHERE CAST(option ->> 'payment_type' AS SMALLINT) = ANY($1) ) ", - &[&i16::from(&PaymentType::EthereumSubscription)], + &[&payment_types], ).await?; }; transaction.execute( diff --git a/src/ethereum/subscriptions.rs b/src/ethereum/subscriptions.rs index 43930ee..8a57d06 100644 --- a/src/ethereum/subscriptions.rs +++ b/src/ethereum/subscriptions.rs @@ -179,6 +179,12 @@ pub async fn check_ethereum_subscriptions( ).await { Ok(subscription) => { if subscription.chain_id != config.chain_id { + // Reset is required (mitractl reset-subscriptions). + // Without this precaution, sender_address can be + // lost during the switch, leading to a loss + // of the ability to call withdrawReceived() + // from a client. + // See also: ApiSubscription type. log::error!("can't switch to another chain"); continue; }; diff --git a/src/monero/subscriptions.rs b/src/monero/subscriptions.rs index 2712f6d..d80322c 100644 --- a/src/monero/subscriptions.rs +++ b/src/monero/subscriptions.rs @@ -165,6 +165,7 @@ pub async fn check_monero_subscriptions( ).await { Ok(subscription) => { if subscription.chain_id != config.chain_id { + // Reset is required (mitractl reset-subscriptions) log::error!("can't switch to another chain"); continue; };