midgard_rs/midgard/endpoints/
actions.rs

1use anyhow::Result;
2use chrono::Utc;
3
4use crate::Midgard;
5use crate::{api_get_action_list, ActionList, GetActionList};
6
7impl Midgard {
8	/// List actions along with their related transactions. An action is generated by one or more inbound transactions with the intended action set in the transaction memo. The action may result in one or more outbound transactions. Results are paginated by sets of 50. Filters may be applied to query actions.
9	///
10	/// # Example
11	///
12	/// ```rust
13	/// use midgard_rs::GetActionList;
14	/// use midgard_rs::Midgard;
15	///
16	/// # tokio_test::block_on(async {
17	/// let mut midgard = Midgard::new();
18	///
19	/// let params = GetActionList::new(vec!["BTC.BTC".to_string()], 10);
20	/// let actions = midgard.get_actions(params).await.unwrap();
21	///
22	/// assert!(!actions.get_actions().get_actions().is_empty());
23	/// # });
24	/// ```
25	///
26	/// To get paginated responses, you can pass the `next_page_token` from the previous response to the next request.
27	/// ```rust
28	/// use midgard_rs::GetActionList;
29	/// use midgard_rs::Midgard;
30	///
31	/// # tokio_test::block_on(async {
32	/// let mut midgard = Midgard::new();
33	///
34	/// let mut params = GetActionList::new(vec!["BTC.BTC".to_string()], 10);
35	/// let actions = midgard.get_actions(params.clone()).await.unwrap();
36	///
37	/// assert!(!actions.get_actions().get_actions().is_empty());
38	///
39	///
40	/// let next_page_token = actions.get_meta().get_next_page_token();
41	/// if let Some(next_page_token) = next_page_token {
42	///         params.set_next_page_token(next_page_token);
43	///         let next_actions = midgard.get_actions(params).await.unwrap();
44	///         assert!(!next_actions.get_actions().get_actions().is_empty());
45	/// }
46	/// # });
47	/// ```
48        /// 
49        /// # Errors
50        /// todo
51	pub async fn get_actions(&mut self, params: GetActionList) -> Result<ActionList> {
52		// Wait for rate limit timer
53		self.sleep_until_ok_to_call().await;
54
55		self.set_last_call(Utc::now());
56		api_get_action_list(self.get_config().get_base_url(), params).await
57	}
58}