Change reset-subscriptions command arguments

This commit is contained in:
silverpill 2023-04-13 20:47:57 +00:00
parent d3210d0ea0
commit d368661d08
5 changed files with 19 additions and 8 deletions

View file

@ -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. - Ignore errors when importing activities from outbox.
- Make activity limit in outbox fetcher adjustable. - Make activity limit in outbox fetcher adjustable.
- Changed `reset-subscriptions` command arguments (removes subscription options by default).
## [1.21.0] - 2023-04-12 ## [1.21.0] - 2023-04-12

View file

@ -598,8 +598,9 @@ impl UpdateCurrentBlock {
/// (can be used during development or when switching between chains) /// (can be used during development or when switching between chains)
#[derive(Parser)] #[derive(Parser)]
pub struct ResetSubscriptions { pub struct ResetSubscriptions {
// Subscription options are removed by default
#[clap(long)] #[clap(long)]
ethereum_contract_replaced: bool, keep_subscription_options: bool,
} }
impl ResetSubscriptions { impl ResetSubscriptions {
@ -608,7 +609,7 @@ impl ResetSubscriptions {
_config: &Config, _config: &Config,
db_client: &mut impl DatabaseClient, db_client: &mut impl DatabaseClient,
) -> Result<(), Error> { ) -> Result<(), Error> {
reset_subscriptions(db_client, self.ethereum_contract_replaced).await?; reset_subscriptions(db_client, self.keep_subscription_options).await?;
println!("subscriptions deleted"); println!("subscriptions deleted");
Ok(()) Ok(())
} }

View file

@ -155,12 +155,14 @@ pub async fn get_incoming_subscriptions(
pub async fn reset_subscriptions( pub async fn reset_subscriptions(
db_client: &mut impl DatabaseClient, db_client: &mut impl DatabaseClient,
ethereum_contract_replaced: bool, keep_subscription_options: bool,
) -> Result<(), DatabaseError> { ) -> Result<(), DatabaseError> {
let transaction = db_client.transaction().await?; let transaction = db_client.transaction().await?;
if ethereum_contract_replaced { if !keep_subscription_options {
// Ethereum subscription configuration is stored in contract. let payment_types = vec![
// If contract is replaced, payment option needs to be deleted. i16::from(&PaymentType::EthereumSubscription),
i16::from(&PaymentType::MoneroSubscription),
];
transaction.execute( transaction.execute(
" "
UPDATE actor_profile UPDATE actor_profile
@ -171,10 +173,10 @@ pub async fn reset_subscriptions(
EXISTS ( EXISTS (
SELECT 1 SELECT 1
FROM jsonb_array_elements(payment_options) AS option 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?; ).await?;
}; };
transaction.execute( transaction.execute(

View file

@ -179,6 +179,12 @@ pub async fn check_ethereum_subscriptions(
).await { ).await {
Ok(subscription) => { Ok(subscription) => {
if subscription.chain_id != config.chain_id { 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"); log::error!("can't switch to another chain");
continue; continue;
}; };

View file

@ -165,6 +165,7 @@ pub async fn check_monero_subscriptions(
).await { ).await {
Ok(subscription) => { Ok(subscription) => {
if subscription.chain_id != config.chain_id { if subscription.chain_id != config.chain_id {
// Reset is required (mitractl reset-subscriptions)
log::error!("can't switch to another chain"); log::error!("can't switch to another chain");
continue; continue;
}; };