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

rpcclient: add spentandmissedtickets notification #10

Merged
merged 2 commits into from
Jan 30, 2022

Conversation

metaclips
Copy link
Owner

No description provided.

Comment on lines +139 to +153
notification_generator!(
"notify_spent_and_missed_tickets registers the client to receive notifications
when blocks are connected to the main chain and tickets are spent or missed.
The notifications are delivered to the notification handlers associated with the client.
Calling this function has no effect if there are no notification handlers and will result in
an error if the client is configured to run in HTTP POST mode.
\nThe notifications delivered as a result of this call will be those from OnSpentAndMissedTickets.
\n**NOTE: This is a dcrd extension and requires a websocket connection.**",
notify_spent_and_missed_tickets,
NotificationsFuture,
commands::METHOD_NOTIFY_SPEND_AND_MISSED_TICKETS,
&[],
all_defined(on_spent_and_missed_tickets),
()
);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a macro that generates notification commands. It comprises of 7 parameter.

  • Documentation of the notification command
  • Function name (which here is notify_spent_and_missed_tickets)
  • Future type (which normally is NotificationsFuture
  • Command type as a string
  • Notification parameters, which are to be sent as an array of serde values
  • Notification handlers that must all be defined (all of the provided handler must be defined) or either be defined (one of the handlers must be defined)
  • Functions input parameter with their types.

@@ -490,3 +509,69 @@ pub(super) fn on_tx_accepted_verbose(

on_tx_verbose_callback(tx_details);
}

pub(super) fn on_spent_and_missed_tickets(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On response from the server, the response parameters are treated appropriately.

Comment on lines +756 to +764
commands::NOTIFICATION_METHOD_SPENT_AND_MISSING_TICKETS => {
match notif.on_spent_and_missed_tickets {
Some(e) => chain_notification::on_spent_and_missed_tickets(&msg.params, e),
None => {
warn!("on spent and missing tickets callback not registered.");
continue;
}
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass the appropriate function OnNotification

@metaclips metaclips merged commit 8aab498 into main Jan 30, 2022
@metaclips metaclips mentioned this pull request Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant