Skip to main content

alchemy_api/api/notify/webhook_addresses/
get.rs

1use crate::{
2    cores::{endpoint::Endpoint, params::QueryParams},
3    types::common::PaginationObject,
4};
5use derive_builder::Builder;
6use ethers_core::types::Address;
7use http::Method;
8use serde::{Deserialize, Serialize};
9
10/// Paginated endpoint to list all of the addresses a given `Address Activity` webhook is
11/// subscribed to.
12#[derive(Default, Debug, Builder, Clone, Serialize, Deserialize)]
13#[builder(setter(into, strip_option))]
14pub struct GetWebhookAddresses {
15    /// ID of the address activity webhook.
16    #[builder(setter)]
17    webhook_id: String,
18    /// Number of items per page.
19    #[builder(default)]
20    limit: Option<u64>,
21    /// Page cursor for the next page.
22    #[builder(default)]
23    after: Option<String>,
24}
25
26impl GetWebhookAddresses {
27    /// Create a builder for the endpoint.
28    pub fn builder() -> GetWebhookAddressesBuilder {
29        GetWebhookAddressesBuilder::default()
30    }
31}
32
33impl Endpoint for GetWebhookAddresses {
34    fn method(&self) -> http::Method {
35        Method::GET
36    }
37
38    fn endpoint(&self) -> std::borrow::Cow<'static, str> {
39        "api/webhook-addresses".into()
40    }
41
42    fn parameters(&self) -> crate::cores::params::QueryParams<'_> {
43        let mut params = QueryParams::default();
44        params.push("webhook_id", self.webhook_id.clone());
45        params.push_opt("limit", self.limit);
46        params.push_opt("after", self.after.clone());
47        params
48    }
49}
50
51/// List of addresses and pagination info.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct GetWebhookAddressesResponse {
54    data: Vec<Address>,
55    pagination: PaginationObject,
56}
57
58impl GetWebhookAddressesResponse {
59    /// List of addresses associated with given webhook.
60    pub fn data(&self) -> Vec<Address> {
61        self.data.clone()
62    }
63
64    /// Information for pagination.
65    pub fn pagination(&self) -> PaginationObject {
66        self.pagination.clone()
67    }
68}