diff --git a/src/api/transactions.rs b/src/api/transactions.rs index 9648b98..f87626d 100644 --- a/src/api/transactions.rs +++ b/src/api/transactions.rs @@ -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( + &self, + source_vault: i32, + destination_wallet_id: &str, + peer_type: PeerType, + asset_id: T, + amount: BigDecimal, + note: Option<&str>, + ) -> crate::Result + where + T: AsRef + 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) diff --git a/src/lib.rs b/src/lib.rs index 1dc94ab..8dae602 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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<()> {