-
Notifications
You must be signed in to change notification settings - Fork 5
Queue events broadcasted while we are disconnected #101
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
Open
denmeh
wants to merge
6
commits into
master
Choose a base branch
from
Queue-events-broadcasted-while-we-are-disconnected
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c88bca9
New QueuedEvent struct
denmeh 73de380
Queue event with incremental delay
denmeh f2d18b8
Now retrying failing relays
denmeh b6beb77
Remove unnecessary `nostr::Event` clone
denmeh 7a8c8ee
Review copilot for queue event to broadcast
denmeh d2e11a8
cli: add payment request test
denmeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| use std::{sync::Arc, time::Duration as StdDuration}; | ||
|
|
||
| use app::{CallbackError, CashuRequestListener, PaymentRequestListener, PaymentStatusNotifier, RecurringPaymentRequest, SinglePaymentRequest}; | ||
| use cli::{CliError, create_app_instance, create_sdk_instance}; | ||
| use portal::protocol::model::{ | ||
| payment::{Currency, RecurringPaymentResponseContent, RecurringPaymentStatus, SinglePaymentRequestContent}, Timestamp | ||
| }; | ||
|
|
||
| struct LogPaymentRequestListener; | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl PaymentRequestListener for LogPaymentRequestListener { | ||
| async fn on_single_payment_request( | ||
| &self, | ||
| event: SinglePaymentRequest, | ||
| notifier: Arc<dyn PaymentStatusNotifier>, | ||
| ) -> Result<(), CallbackError> { | ||
| log::info!("Receiver: Received Payment request: {:?}", event); | ||
| // Always approve for test | ||
| Ok(()) | ||
| } | ||
| async fn on_recurring_payment_request( | ||
| &self, | ||
| event: RecurringPaymentRequest, | ||
| ) -> Result<RecurringPaymentResponseContent, CallbackError> { | ||
| log::info!("Receiver: Received Recurring Payment request: {:?}", event); | ||
| Ok(RecurringPaymentResponseContent { | ||
| request_id: event.content.request_id, | ||
| status: RecurringPaymentStatus::Rejected { reason: Some("User rejected".to_string()) }, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), CliError> { | ||
| env_logger::init(); | ||
|
|
||
| let relays = vec!["wss://relay.nostr.net".to_string()]; | ||
|
|
||
| let (receiver_key, receiver) = create_app_instance( | ||
| "Receiver", | ||
| "mass derive myself benefit shed true girl orange family spawn device theme", | ||
| relays.clone(), | ||
| ) | ||
| .await?; | ||
| let _receiver = receiver.clone(); | ||
|
|
||
| tokio::spawn(async move { | ||
| log::info!("Receiver: Setting up Payment request listener"); | ||
| _receiver | ||
| .listen_for_payment_request(Arc::new(LogPaymentRequestListener)) | ||
| .await | ||
| .expect("Receiver: Error creating listener"); | ||
| }); | ||
|
|
||
| let sender_sdk = create_sdk_instance( | ||
| "draft sunny old taxi chimney ski tilt suffer subway bundle once story", | ||
| relays.clone(), | ||
| ) | ||
| .await?; | ||
|
|
||
| log::info!("Apps created, waiting 5 seconds before sending request"); | ||
| tokio::time::sleep(StdDuration::from_secs(5)).await; | ||
|
|
||
| let request_content = SinglePaymentRequestContent { | ||
| amount: 1000, | ||
| currency: Currency::Millisats, | ||
| current_exchange_rate: None, | ||
| invoice: "invoice".to_string(), | ||
| auth_token: None, | ||
| expires_at: Timestamp::now_plus_seconds(300), | ||
| subscription_id: None, | ||
| description: Some("test".to_string()), | ||
| request_id: "test".to_string(), | ||
| }; | ||
|
|
||
| let mut response = sender_sdk | ||
| .request_single_payment(receiver_key.public_key().0, vec![], request_content) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| while let Some(resp) = response.next().await { | ||
|
|
||
| match resp { | ||
| Ok(resp) => { | ||
| log::info!("Sender: Received payment: {:?}", resp); | ||
| } | ||
| Err(e) => { | ||
| log::error!("Sender: Error receiving payment: {}", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.