Skip to content

Commit

Permalink
Add peer type transfer (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougEfresh committed Jul 21, 2024
1 parent 728eacd commit 357dc2b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
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

0 comments on commit 357dc2b

Please sign in to comment.