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

View file

@ -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(())
}

View file

@ -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(

View file

@ -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;
};

View file

@ -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;
};