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

Clone serialize deadcode #17

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fireblocks-sdk"
resolver = "2"
version = "0.3.0"
version = "0.3.1"
authors = ["Doug Chimento <dchimento@gmail.com>"]
description = "Rust implementation of the Fireblocks SDK"
readme = "README.md"
Expand All @@ -20,7 +20,7 @@ crate-type = ["cdylib", "rlib"]

[lints.rust]
unsafe_code = "forbid"
dead_code = "allow"


[lints.clippy]
enum_glob_use = "deny"
Expand Down
34 changes: 34 additions & 0 deletions src/api/hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::api::Success;
use crate::types::hooks::HookResponse;
use crate::Client;
use crate::Result;
use serde_derive::{Deserialize, Serialize};

impl Client {
/// Resends all failed webhook notifications.
///
/// See
/// * [resendWebhooks](https://docs.fireblocks.com/api/swagger-ui/#/Webhooks/resendWebhooks)
#[tracing::instrument(level = "debug", skip(self))]
pub async fn hooks_resend(&self) -> Result<HookResponse> {
let u = self.build_url("webhooks/resend")?.0;
self.post::<HookResponse, ()>(u, None).await
}

/// Resend a specific transaction by txId
///
/// See
/// * [resendTransactionWebhooks](https://docs.fireblocks.com/api/swagger-ui/#/Webhooks/resendTransactionWebhooks)
#[tracing::instrument(level = "debug", skip(self))]
pub async fn hooks_resend_tx(&self, tx_id: &str, created: bool, updated: bool) -> Result<Success> {
#[derive(Debug, Deserialize, Serialize, Default)]

Check warning on line 24 in src/api/hooks.rs

View check run for this annotation

Codecov / codecov/patch

src/api/hooks.rs#L24

Added line #L24 was not covered by tests
#[serde(rename_all = "camelCase")]
struct HookTransaction {
resend_created: bool,
resend_status_updated: bool,
}
let request = HookTransaction { resend_created: created, resend_status_updated: updated };
let u = self.build_url(format!("webhooks/resend/{tx_id}"))?.0;
self.post::<Success, HookTransaction>(u, Some(request).as_ref()).await
}
}
8 changes: 7 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde_derive::Serialize;
use serde_derive::{Deserialize, Serialize};

mod contracts;
mod external_wallets;
mod hooks;
mod internal_wallets;
mod staking;
mod transactions;
Expand All @@ -19,3 +20,8 @@ pub struct WalletCreateAsset {
pub address: String,
pub tag: String,
}

#[derive(Debug, Deserialize, Default)]
pub struct Success {
pub success: bool,
}
8 changes: 2 additions & 6 deletions src/api/vaults.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use crate::api::Success;
use crate::types::{
Account, Address, AddressContainer, CreateAccount, CreateAddressResponse, PaginatedAssetWallet, VaultAccounts,
VaultRenameResponse,
};
use crate::Client;
use crate::Result;
use serde_derive::{Deserialize, Serialize};
use serde_derive::Serialize;
use std::borrow::Borrow;
use std::fmt::{Debug, Display};

#[derive(Debug, Deserialize, Default)]
struct Success {
success: bool,
}

impl Client {
/// Create an asset (address) for a vault account
///
Expand Down
52 changes: 43 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,19 @@ mod tests {
if !config.is_ok() {
return Ok(());
}
let c = config.client();
let name = format!("c-{}", vault_name());
let (contract_response, id) = config.client().contract_create(&name).await?;
let (contract_response, id) = c.contract_create(&name).await?;
assert!(!id.is_empty());
assert_eq!(contract_response.name, name);
assert!(!contract_response.id.is_empty());

let (addr_response, _) = config
.client()
.contract_asset(&contract_response.id, ASSET_ETH_TEST, "0x9bb4d44e6963260a1850926e8f6beb8d5803836f")
.await?;
let (addr_response, _) =
c.contract_asset(&contract_response.id, ASSET_ETH_TEST, "0x9bb4d44e6963260a1850926e8f6beb8d5803836f").await?;
assert_eq!(addr_response.id, ASSET_ETH_TEST);

config.client().contract_delete(&name).await?;
config.client().contracts().await?;
c.contract(&contract_response.id).await?;
c.contract_delete(&name).await?;
c.contracts().await?;
Ok(())
}

Expand Down Expand Up @@ -423,7 +422,15 @@ mod tests {
if !config.is_ok() {
return Ok(());
}
config.client().wallet_connections().await?;
let c = config.client();
c.wallet_connections().await?;
if let Err(e) = c.wallet_connection_delete("wallet-connect-id").await {
assert!(e.to_string().contains("wallet-connect-id not found"));
}

if let Err(e) = c.wallet_connection_approve("wallet-connect-id", true).await {
assert!(e.to_string().contains("wallet-connect-id not found"));
}
Ok(())
}

Expand Down Expand Up @@ -496,6 +503,33 @@ mod tests {
Ok(())
}

#[rstest::rstest]
#[tokio::test]
async fn test_hooks(config: Config) -> color_eyre::Result<()> {
if !config.is_ok() {
return Ok(());
}
let c = config.client();
match c.hooks_resend().await {
Ok(result) => {
assert!(result.0.message_count > 0);
},
Err(e) => {
assert!(e.to_string().contains("Internal Fireblocks Error"));
},
};

match c.hooks_resend_tx("e01b1c68-2d26-45dc-bb02-4cc9152295e1", true, true).await {
Err(e) => {
assert!(e.to_string().contains("Internal Fireblocks Error"));
},
Ok(result) => {
assert!(result.0.success);
},
}
Ok(())
}

#[rstest::rstest]
#[tokio::test]
async fn test_paged_transactions(config: Config) -> color_eyre::Result<()> {
Expand Down
3 changes: 0 additions & 3 deletions src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@ where

#[derive(Debug, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct AddressContainer {
pub addresses: Vec<Address>,
pub paging: Option<Paging>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct CreateAddressResponse {
pub id: String,
pub address: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct Address {
pub asset_id: Asset,
pub address: String,
Expand Down
3 changes: 0 additions & 3 deletions src/types/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct SupportedAsset {
pub id: Asset,
pub name: String,
Expand All @@ -18,7 +17,6 @@ pub struct SupportedAsset {

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct AssetResponse {
#[serde(deserialize_with = "deserialize_str_u64", default)]
pub vault_id: u64,
Expand All @@ -34,7 +32,6 @@ pub struct AssetResponse {

#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct AccountAsset {
pub id: String,
pub total: BigDecimal,
Expand Down
8 changes: 0 additions & 8 deletions src/types/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct Metadata {
pub app_url: String,
pub app_name: String,
Expand All @@ -14,7 +13,6 @@ pub struct Metadata {

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct WalletConnection {
pub id: String,
#[serde(rename = "userId")]
Expand All @@ -33,30 +31,26 @@ pub struct WalletConnection {

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct NextPage {
pub next: String,
}

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct PagedWalletConnectResponse {
pub data: Vec<WalletConnection>,
pub page: Option<NextPage>,
}

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[allow(dead_code)]
pub enum FeeLevel {
#[default]
Medium,
}

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct WalletConnectRequest {
pub fee_level: FeeLevel,
pub vault_account_id: i32,
Expand All @@ -66,14 +60,12 @@ pub struct WalletConnectRequest {

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct WalletConnectResponse {
pub id: String,
}

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct WalletApprove {
pub approve: bool,
}
Expand Down
2 changes: 0 additions & 2 deletions src/types/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use serde::Deserialize;

#[derive(Debug, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct Fee {
pub network_fee: Option<BigDecimal>,
pub gas_price: Option<BigDecimal>,
Expand All @@ -14,7 +13,6 @@ pub struct Fee {

#[derive(Debug, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct EstimateFee {
pub low: Fee,
pub medium: Fee,
Expand Down
7 changes: 7 additions & 0 deletions src/types/hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use serde_derive::Deserialize;

#[derive(Debug, Deserialize, Default)]

Check warning on line 3 in src/types/hooks.rs

View check run for this annotation

Codecov / codecov/patch

src/types/hooks.rs#L3

Added line #L3 was not covered by tests
#[serde(rename_all = "camelCase")]
pub struct HookResponse {
pub message_count: u32,
}
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod address;
pub mod asset;
pub mod connect;
pub mod fee;
pub mod hooks;
mod page;
pub mod staking;
pub mod transaction;
Expand Down Expand Up @@ -66,7 +67,6 @@ where

#[derive(Debug, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct PaginatedAssetWallet {
pub asset_wallets: Vec<AssetResponse>,
pub paging: Paging,
Expand Down
1 change: 0 additions & 1 deletion src/types/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct Paging {
pub before: Option<String>,
pub after: Option<String>,
Expand Down
Loading
Loading