Skip to content

Commit

Permalink
Update Webhook Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed May 6, 2024
1 parent 9fed8ac commit 594bdf0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Enhanced Transactions API
- [`parsed_transaction_history`](https://docs.helius.dev/solana-apis/enhanced-transactions-api/parsed-transaction-history) - Retrieves a parsed transaction history for a specific address

### Webhooks
- [`create_webhook`]()
- [`edit_webhook`]()
- [`append_addresses_to_webhook`]()
- [`get_webhook_by_id`]()
- [`get_all_webhooks`]()

### Helper Methods
- [`get_priority_fee_estimate`](https://docs.helius.dev/solana-rpc-nodes/alpha-priority-fee-api) - Gets an estimate of the priority fees required for a transaction to be processed more quickly
Expand Down
30 changes: 29 additions & 1 deletion src/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ use crate::Helius;
use reqwest::{Method, Url};

impl Helius {
/// Creates a webhook given account addresses,
/// Creates a webhook given account addresses
///
/// # Arguments
/// * `request` - A `CreateWebhookRequest` containing the relevant webhook parameters for creation such as the webhook url and type
///
/// # Returns
/// A `Result` wrapping a `Webhook` if the webhook is successfully created, or a `HeliusError` if creation fails
pub async fn create_webhook(&self, request: CreateWebhookRequest) -> Result<Webhook> {
let url: String = format!(
"{}v0/webhooks/?api-key={}",
Expand All @@ -22,6 +28,12 @@ impl Helius {
}

/// Edits a Helius webhook programmatically
///
/// # Arguments
/// * `request` - An `EditWebhookRequest` containing the parameters to be updated for a given webhook
///
/// # Returns
/// A `Result` wrapping the updated `Webhook`, or a `HeliusError` if the edit request fails
pub async fn edit_webhook(&self, request: EditWebhookRequest) -> Result<Webhook> {
let url: String = format!(
"{}v0/webhooks/{}/?api-key={}",
Expand All @@ -36,6 +48,13 @@ impl Helius {
}

/// Appends a set of addresses to a given webhook
///
/// # Arguments
/// * `webhook_id` - The ID of the webhook to be updated
/// * `new_addresses` - A slice of strings representing the new account addresses to be added to the given webhook
///
/// # Returns
/// A `Result` containing the updated `Webhook` object
pub async fn append_addresses_to_webhook(&self, webhook_id: &str, new_addresses: &[String]) -> Result<Webhook> {
let mut webhook: Webhook = self.get_webhook_by_id(webhook_id).await?;
webhook.account_addresses.extend(new_addresses.to_vec());
Expand All @@ -54,6 +73,12 @@ impl Helius {
}

/// Gets a webhook config given a webhook ID
///
/// # Arguments
/// * `webhook_id` - The ID of the webhook to be updated
///
/// # Returns
/// A `Result` wrapping the `Webhook` queried, if it exists
pub async fn get_webhook_by_id(&self, webhook_id: &str) -> Result<Webhook> {
let url: String = format!(
"{}v0/webhooks/{}/?api-key={}",
Expand All @@ -67,6 +92,9 @@ impl Helius {
/// Retrieves all Helius webhooks programmatically
///
/// Due to response size limitations, we will truncate addresses returned to 100 per config
///
/// # Returns
/// A `Result` containing a vector of `Webhook` representing all configured webhooks for a given account
pub async fn get_all_webhooks(&self) -> Result<Vec<Webhook>> {
let url: String = format!(
"{}v0/webhooks/?api-key={}",
Expand Down

0 comments on commit 594bdf0

Please sign in to comment.