1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::api::{WalletCreate, WalletCreateAsset};
use crate::types::{WalletContainer, WalletCreateAssetResponse};
use crate::Client;
use crate::Result;
use std::fmt::{Debug, Display};

impl Client {
  #[tracing::instrument(level = "debug", skip(self))]
  pub async fn contracts(&self) -> Result<Vec<WalletContainer>> {
    let u = self.build_url("contracts")?.0;
    self.get(u).await
  }

  #[tracing::instrument(level = "debug", skip(self))]
  pub async fn contract(&self, id: &str) -> Result<WalletContainer> {
    let u = self.build_url(format!("contracts/{id}"))?.0;
    self.get(u).await
  }

  #[tracing::instrument(level = "debug", skip(self))]
  pub async fn contract_asset<T>(&self, id: &str, asset: T, address: &str) -> Result<WalletCreateAssetResponse>
  where
    T: AsRef<str> + Display + Debug,
  {
    let u = self.build_url(format!("contracts/{id}/{asset}"))?.0;
    let w = WalletCreateAsset { address: String::from(address), tag: "fireblocks-sdk-rs".to_string() };
    self.post(u, Some(&w)).await
  }

  #[tracing::instrument(level = "debug", skip(self))]
  pub async fn contract_create(&self, name: &str) -> Result<WalletContainer> {
    let u = self.build_url("contracts")?.0;
    let w = WalletCreate { name: String::from(name) };
    self.post(u, Some(&w)).await
  }

  #[tracing::instrument(level = "debug", skip(self))]
  pub async fn contract_delete(&self, id: &str) -> Result<()> {
    let u = self.build_url(format!("contracts/{id}"))?.0;
    self.delete(u).await
  }
}