diff --git a/Cargo.lock b/Cargo.lock index 9edd0ee35..91ce578b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -423,6 +423,7 @@ dependencies = [ "prost", "prost-wkt-types", "protobuf-src", + "rand", "rust_decimal", "rust_decimal_macros", "rusty-money", diff --git a/bria-client/Cargo.toml b/bria-client/Cargo.toml index a113ad79f..2a07f9f22 100644 --- a/bria-client/Cargo.toml +++ b/bria-client/Cargo.toml @@ -39,3 +39,4 @@ tonic-build = { version = "0.8", features = ["prost"] } [dev-dependencies] anyhow = "1.0.70" +rand = { workspace = true } diff --git a/bria-client/src/client.rs b/bria-client/src/client.rs index 685fb9ad0..8a8860b16 100644 --- a/bria-client/src/client.rs +++ b/bria-client/src/client.rs @@ -90,6 +90,7 @@ impl BriaClient { &mut self, destination: String, satoshis: rust_decimal::Decimal, + external_id: String, ) -> Result { use rust_decimal::prelude::ToPrimitive; @@ -109,7 +110,7 @@ impl BriaClient { .abs() .to_u64() .ok_or(BriaClientError::CouldNotConvertSatoshisToU64)?, - external_id: None, + external_id: Some(external_id), metadata: metadata.map(serde_json::from_value).transpose()?, }); diff --git a/bria-client/tests/bria_client.rs b/bria-client/tests/bria_client.rs index 14f2977e7..ed9e6ae92 100644 --- a/bria-client/tests/bria_client.rs +++ b/bria-client/tests/bria_client.rs @@ -36,7 +36,11 @@ async fn send_onchain_payment() -> anyhow::Result<()> { let destination = "bcrt1q5cwegu66cf344du3ffrvnwjz9u246xlydqezsa".to_string(); let satoshis = rust_decimal::Decimal::from(5000); - let id = client.send_onchain_payment(destination, satoshis).await?; + use rand::distributions::{Alphanumeric, DistString}; + let external_id = Alphanumeric.sample_string(&mut rand::thread_rng(), 32); + let id = client + .send_onchain_payment(destination, satoshis, external_id) + .await?; assert!(!id.is_empty()); Ok(()) diff --git a/hedging/src/okex/job/adjust_funding.rs b/hedging/src/okex/job/adjust_funding.rs index 972beea47..70817a020 100644 --- a/hedging/src/okex/job/adjust_funding.rs +++ b/hedging/src/okex/job/adjust_funding.rs @@ -145,15 +145,16 @@ pub(super) async fn execute( if let Some(client_id) = okex_transfers.reserve_transfer_slot(reservation).await? { - span.record( - "client_transfer_id", - &tracing::field::display(String::from(client_id)), - ); + let client_transfer_id = String::from(client_id.clone()); + span.record("client_transfer_id", &client_transfer_id); let amount_in_sats = amount * SATS_PER_BTC; - let _ = bria - .send_onchain_payment(deposit_address, amount_in_sats) - .await?; + bria.send_onchain_payment( + deposit_address, + amount_in_sats, + client_transfer_id, + ) + .await?; } } OkexFundingAdjustment::OnchainWithdraw(amount) => { diff --git a/okex-client/src/client/mod.rs b/okex-client/src/client/mod.rs index d0efb0568..133cda22b 100644 --- a/okex-client/src/client/mod.rs +++ b/okex-client/src/client/mod.rs @@ -257,6 +257,7 @@ impl OkexClient { }) } + /// https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-balance #[instrument(name = "okex_client.funding_account_balance", skip(self), err)] pub async fn funding_account_balance(&self) -> Result { let request_path = "/api/v5/asset/balances?ccy=BTC"; @@ -403,7 +404,13 @@ impl OkexClient { }) } - #[instrument(name = "okex_client.fetch_deposit", skip(self), err)] + /// https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-deposit-history + #[instrument( + name = "okex_client.fetch_deposit", + fields(deposit_found, okex_deposit_state), + skip(self), + err + )] pub async fn fetch_deposit( &self, depo_addr: String, @@ -428,10 +435,12 @@ impl OkexClient { }); if let Some(deposit_data) = deposit { + tracing::Span::current().record("deposit_found", true); + tracing::Span::current().record("okex_deposit_state", &deposit_data.state); Ok(DepositStatus { state: match &deposit_data.state[..] { "0" => "pending".to_string(), // waiting for confirmation - "1" => "success".to_string(), // deposit credited, cannot withdraw + "1" => "pending".to_string(), // deposit credited, cannot withdraw "2" => "success".to_string(), // deposit successful, can withdraw "8" => "pending".to_string(), // pending due to temporary deposit suspension on this crypto currency "12" => "pending".to_string(), // account or deposit is frozen