Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable/enable lightning addresses #112

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions graphql/schemas/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions graphql/schemas/schema_wallet_read.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
16 changes: 16 additions & 0 deletions graphql/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
44 changes: 37 additions & 7 deletions pigeon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String>,
) -> graphql::Result<()> {
let token = auth.query_token().await?;
let client = build_async_client(Some(&token))?;
post::<DisableLightningAddresses>(
&client,
backend_url,
disable_lightning_addresses::Variables { addresses },
)
.await?;
Ok(())
}

pub async fn enable_lightning_addresses(
backend_url: &str,
auth: &Auth,
addresses: Vec<String>,
) -> graphql::Result<()> {
let token = auth.query_token().await?;
let client = build_async_client(Some(&token))?;
post::<EnableLightningAddresses>(
&client,
backend_url,
enable_lightning_addresses::Variables { addresses },
)
.await?;
Ok(())
}
36 changes: 35 additions & 1 deletion pigeon/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Loading