diff --git a/graphql/schemas/operations.graphql b/graphql/schemas/operations.graphql index 1b6c006..9449697 100644 --- a/graphql/schemas/operations.graphql +++ b/graphql/schemas/operations.graphql @@ -182,3 +182,11 @@ query VerifiedPhoneNumber { encryptedPhoneNumber } } + +mutation DisableLightningAddresses($addresses: [String!]!) { + disable_lightning_addresses(addresses: $addresses) +} + +mutation EnableLightningAddresses($addresses: [String!]!) { + enable_lightning_addresses(addresses: $addresses) +} diff --git a/graphql/schemas/schema_wallet_read.graphql b/graphql/schemas/schema_wallet_read.graphql index a93506d..a47fa4f 100644 --- a/graphql/schemas/schema_wallet_read.graphql +++ b/graphql/schemas/schema_wallet_read.graphql @@ -698,6 +698,8 @@ type mutation_root { accept_wallet_acl_by_pk(pk_columns: AcceptWalletPkRequestInput!): WalletAcl assign_lightning_address: LightningAddressResponse create_backup(encryptedBackup: String!, schemaName: String!, schemaVersion: String!): CreateBackupResponse + disable_lightning_addresses(addresses: [String!]!): Void + enable_lightning_addresses(addresses: [String!]!): Void hide_topup(id: String!): String """ diff --git a/graphql/src/schema.rs b/graphql/src/schema.rs index 945a808..ab8fedf 100644 --- a/graphql/src/schema.rs +++ b/graphql/src/schema.rs @@ -214,3 +214,19 @@ pub struct VerifyPhoneNumber; response_derives = "Debug" )] pub struct VerifiedPhoneNumber; + +#[derive(GraphQLQuery)] +#[graphql( + schema_path = "schemas/schema_wallet_read.graphql", + query_path = "schemas/operations.graphql", + response_derives = "Debug" +)] +pub struct DisableLightningAddresses; + +#[derive(GraphQLQuery)] +#[graphql( + schema_path = "schemas/schema_wallet_read.graphql", + query_path = "schemas/operations.graphql", + response_derives = "Debug" +)] +pub struct EnableLightningAddresses; diff --git a/pigeon/src/lib.rs b/pigeon/src/lib.rs index c049c60..d29fd80 100644 --- a/pigeon/src/lib.rs +++ b/pigeon/src/lib.rs @@ -1,12 +1,10 @@ use graphql::perro::OptionToError; -use graphql::schema::VerifiedPhoneNumber; use graphql::schema::{ - assign_lightning_address, submit_lnurl_pay_invoice, AssignLightningAddress, - SubmitLnurlPayInvoice, -}; -use graphql::schema::{ - request_phone_number_verification, verified_phone_number, verify_phone_number, - RequestPhoneNumberVerification, VerifyPhoneNumber, + assign_lightning_address, disable_lightning_addresses, enable_lightning_addresses, + request_phone_number_verification, submit_lnurl_pay_invoice, verified_phone_number, + verify_phone_number, AssignLightningAddress, DisableLightningAddresses, + EnableLightningAddresses, RequestPhoneNumberVerification, SubmitLnurlPayInvoice, + VerifiedPhoneNumber, VerifyPhoneNumber, }; use graphql::{build_async_client, post}; use honeybadger::asynchronous::Auth; @@ -92,3 +90,35 @@ pub async fn query_verified_phone_number( .await?; Ok(data.verified_phone_number.map(|n| n.encrypted_phone_number)) } + +pub async fn disable_lightning_addresses( + backend_url: &str, + auth: &Auth, + addresses: Vec, +) -> graphql::Result<()> { + let token = auth.query_token().await?; + let client = build_async_client(Some(&token))?; + post::( + &client, + backend_url, + disable_lightning_addresses::Variables { addresses }, + ) + .await?; + Ok(()) +} + +pub async fn enable_lightning_addresses( + backend_url: &str, + auth: &Auth, + addresses: Vec, +) -> graphql::Result<()> { + let token = auth.query_token().await?; + let client = build_async_client(Some(&token))?; + post::( + &client, + backend_url, + enable_lightning_addresses::Variables { addresses }, + ) + .await?; + Ok(()) +} diff --git a/pigeon/tests/integration_tests.rs b/pigeon/tests/integration_tests.rs index ccd9c32..526a56f 100644 --- a/pigeon/tests/integration_tests.rs +++ b/pigeon/tests/integration_tests.rs @@ -2,7 +2,10 @@ use bitcoin::Network; use honeybadger::asynchronous::Auth; use honeybadger::secrets::{derive_keys, generate_keypair, generate_mnemonic}; use honeybadger::AuthLevel; -use pigeon::{assign_lightning_address, submit_lnurl_pay_invoice}; +use pigeon::{ + assign_lightning_address, disable_lightning_addresses, enable_lightning_addresses, + submit_lnurl_pay_invoice, +}; use simplelog::TestLogger; use std::env; use std::sync::Once; @@ -33,6 +36,37 @@ async fn test_assigning_lightning_address() { assert_ne!(address, address_for_another_user); } +#[tokio::test] +async fn test_disable_enable_lightning_addresses() { + let (backend_url, auth) = build_client(); + let address = assign_lightning_address(&backend_url, &auth).await.unwrap(); + println!("Assigned address is: {address}"); + disable_lightning_addresses(&backend_url, &auth, vec![address.clone()]) + .await + .unwrap(); + // Disabling again. + disable_lightning_addresses(&backend_url, &auth, vec![address.clone()]) + .await + .unwrap(); + + enable_lightning_addresses(&backend_url, &auth, vec![address.clone()]) + .await + .unwrap(); + // Enabling again. + enable_lightning_addresses(&backend_url, &auth, vec![address.clone()]) + .await + .unwrap(); + + let (backend_url, another_auth) = build_client(); + // Disabling/enabling an address of another user. + disable_lightning_addresses(&backend_url, &another_auth, vec![address.clone()]) + .await + .unwrap_err(); + enable_lightning_addresses(&backend_url, &another_auth, vec![address.clone()]) + .await + .unwrap_err(); +} + #[tokio::test] async fn test_submit_lnurl_pay_invoice() { let (backend_url, auth) = build_client();