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

Add peer type transfer #25

Merged
merged 1 commit into from
Jul 21, 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
38 changes: 38 additions & 0 deletions src/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,44 @@ impl Client {
self.post(u, Some(args)).await
}

/// Create a vault-to-peer destination transaction (e.g. INTERNAL_WALLET)
/// create_transaction_whitelist(0, &id, PeerType::INTERNAL_WALLET, "SOL_TEST", BigDecimal::from_str("0.00001")?, None).await?
///
/// [createTransaction](https://docs.fireblocks.com/api/swagger-ui/#/Transactions/createTransaction)
#[tracing::instrument(level = "debug", skip(self))]
pub async fn create_transaction_peer<T>(
&self,
source_vault: i32,
destination_wallet_id: &str,
peer_type: PeerType,
asset_id: T,
amount: BigDecimal,
note: Option<&str>,
) -> crate::Result<CreateTransactionResponse>
where
T: AsRef<str> + Debug + Display,
{
let dest = DestinationTransferPeerPath {
peer_type,
id: String::from(destination_wallet_id),
wallet_id: Some(String::from(destination_wallet_id)),
virtual_id: None,
virtual_type: None,
one_time_address: None,
};
let args = &TransactionArguments {
asset_id: format!("{asset_id}"),
operation: TransactionOperation::TRANSFER,
source: TransferPeerPath { id: Some(source_vault.to_string()), ..Default::default() },
destination: Some(dest),
amount: amount.to_string(),
gas_price: None,
gas_limit: None,
note: note.unwrap_or("created by fireblocks-sdk for rust").to_string(),
};
self.create_transaction(args).await
}

/// Create a vault-to-vault transaction
///
/// [createTransaction](https://docs.fireblocks.com/api/swagger-ui/#/Transactions/createTransaction)
Expand Down
40 changes: 40 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,46 @@ mod tests {
Ok(())
}

#[rstest::rstest]
#[tokio::test]
async fn test_create_transaction_whitelist(config: Config) -> color_eyre::Result<()> {
if !config.is_ok() {
return Ok(());
}
/*
if !config.create_tx {
warn!("not testing create transaction");
return Ok(());
}
*/
let c = config.client();
let wallet = c.internal_wallets().await?.0.into_iter().find(|w| w.name == "test-whitelist");
let id: String = match wallet {
None => {
let id = c.internal_wallet_create("test-whitelist").await?.0.id;
c.internal_wallet_asset(&id, ASSET_SOL_TEST, "E4SfgGV2v9GLYsEkCQhrrnFbBcYmAiUZZbJ7swKGzZHJ").await?;
id
},
Some(w) => w.id,
};
let tx = c
.create_transaction_peer(
0,
&id,
PeerType::INTERNAL_WALLET,
ASSET_SOL_TEST,
BigDecimal::from_str("0.00001")?,
None,
)
.await?
.0;
c.poll_transaction(&tx.id, Duration::from_secs(50), Duration::from_secs(5), |t: &Transaction| {
tracing::info!("{:#?}", t.status);
})
.await?;
Ok(())
}

#[rstest::rstest]
#[tokio::test]
async fn test_create_transaction(config: Config) -> color_eyre::Result<()> {
Expand Down
Loading