diff --git a/Cargo.toml b/Cargo.toml index 152e4d3..2ed0dd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,10 @@ authors = ["Santiago Carmuega "] [dependencies] bytes = "1.10.1" -thiserror = "2.0.12" +thiserror = "2.0.17" tokio = "1.46.1" tonic = { version = "0.12.3", features = ["tls-roots"] } -utxorpc-spec = { version = "0.17.0" } +utxorpc-spec = { version = "0.18.1" } # utxorpc-spec = { path = "../spec/gen/rust" } [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 816d084..39679cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -555,22 +555,16 @@ impl_grpc_client!( ); impl SubmitClient { - pub async fn submit_tx>( - &mut self, - txs: Vec, - ) -> Result> { - let tx = txs - .into_iter() - .map(|bytes| spec::submit::AnyChainTx { - r#type: Some(spec::submit::any_chain_tx::Type::Raw(bytes.into())), - }) - .collect(); + pub async fn submit_tx>(&mut self, tx: B) -> Result { + let tx = Some(spec::submit::AnyChainTx { + r#type: Some(spec::submit::any_chain_tx::Type::Raw(tx.into())), + }); let req = spec::submit::SubmitTxRequest { tx }; let res = self.inner.submit_tx(req).await?; - let refs = res.into_inner().r#ref; - Ok(refs) + let tx_ref = res.into_inner().r#ref; + Ok(tx_ref) } pub async fn wait_for_tx>( @@ -617,6 +611,9 @@ where tx: ChainTx, block: ChainBlock, }, + Idle { + block_ref: spec::watch::BlockRef, + }, } pub struct WatchedTxStream(Streaming, PhantomData); @@ -639,6 +636,9 @@ impl WatchedTxStream { block: chain_tx.1, })) } + Some(spec::watch::watch_tx_response::Action::Idle(block_ref)) => { + Ok(Some(WatchedTx::Idle { block_ref })) + } None => Ok(None), }, None => Ok(None), diff --git a/utxorpc-tests/src/lib.rs b/utxorpc-tests/src/lib.rs index a4083e8..0ab34e3 100644 --- a/utxorpc-tests/src/lib.rs +++ b/utxorpc-tests/src/lib.rs @@ -1 +1 @@ -// This crate contains all integration tests for the utxorpc library \ No newline at end of file +// This crate contains all integration tests for the utxorpc library diff --git a/utxorpc-tests/tests/common/mod.rs b/utxorpc-tests/tests/common/mod.rs index efd5737..2ae54b4 100644 --- a/utxorpc-tests/tests/common/mod.rs +++ b/utxorpc-tests/tests/common/mod.rs @@ -129,14 +129,17 @@ pub async fn fetch_utxos_from_utxorpc( let tx_hash = hex::encode(&tx_ref.hash); let output_index = tx_ref.index; - let lovelace_amount = parsed.coin; + let lovelace_amount = parsed.coin.and_then(unwrap_bigint).unwrap_or_default(); let mut assets = Vec::new(); for asset_group in parsed.assets { let policy_id = hex::encode(&asset_group.policy_id); for asset in asset_group.assets { let asset_name = hex::encode(&asset.name); - let asset_amount = asset.output_coin; + let asset_amount = match asset.quantity { + Some(spec::cardano::asset::Quantity::OutputCoin(int)) => unwrap_bigint(int).unwrap_or_default(), + _ => 0, + }; assets.push((policy_id.clone(), asset_name, asset_amount)); } } @@ -417,4 +420,11 @@ pub async fn build_transaction( asset_name, asset_amount, ).await +} + +fn unwrap_bigint(value: spec::cardano::BigInt) -> Option { + match value.big_int { + Some(spec::cardano::big_int::BigInt::Int(inner)) => Some(inner as u64), + _ => None + } } \ No newline at end of file diff --git a/utxorpc-tests/tests/submit.rs b/utxorpc-tests/tests/submit.rs index 34a8af7..33bfffc 100644 --- a/utxorpc-tests/tests/submit.rs +++ b/utxorpc-tests/tests/submit.rs @@ -34,16 +34,12 @@ async fn submit_and_wait_for_tx() { } }; - let refs = match submit_client.submit_tx(vec![tx_bytes]).await { - Ok(refs) => refs, - Err(_) => { - eprintln!("Transaction submission failed - skipping test"); - return; - } + let Ok(tx_ref) = submit_client.submit_tx(tx_bytes).await else { + eprintln!("Transaction submission failed - skipping test"); + return; }; - assert!(!refs.is_empty()); - let mut stream = submit_client.wait_for_tx(refs).await.unwrap(); + let mut stream = submit_client.wait_for_tx(vec![tx_ref]).await.unwrap(); match tokio::time::timeout( std::time::Duration::from_secs(5), @@ -180,10 +176,8 @@ async fn watch_mempool_all_patterns() { } }; - let submitted_tx_id = match submit_client.submit_tx(vec![tx_bytes]).await { - Ok(refs) => refs.first() - .map(|tx_ref| hex::encode(tx_ref)) - .expect("No transaction ref returned from submit"), + let submitted_tx_id = match submit_client.submit_tx(tx_bytes).await { + Ok(tx_ref) => hex::encode(tx_ref), Err(_) => { eprintln!("Transaction submission failed - skipping test"); return; diff --git a/utxorpc-tests/tests/sync.rs b/utxorpc-tests/tests/sync.rs index d63379b..c5448fa 100644 --- a/utxorpc-tests/tests/sync.rs +++ b/utxorpc-tests/tests/sync.rs @@ -1,6 +1,6 @@ mod common; -use utxorpc::{*, spec}; +use utxorpc::{spec, *}; #[tokio::test] async fn client_build() { @@ -25,6 +25,7 @@ async fn follow_tip() { .unwrap() .into(), height: 3399486, + timestamp: 1768682099000, }]; let mut tip = client.follow_tip(intersect).await.unwrap(); @@ -84,12 +85,13 @@ async fn fetch_block() { .unwrap() .into(), height: 3399486, + timestamp: 1768682099000, }; let blocks = client.fetch_block(vec![block_ref]).await.unwrap(); assert_eq!(blocks.len(), 1, "Should fetch exactly one block"); - + if let Some(parsed) = &blocks[0].parsed { if let Some(header) = &parsed.header { assert_eq!(header.slot, 85213090); @@ -112,12 +114,13 @@ async fn dump_history() { .unwrap() .into(), height: 3399486, + timestamp: 1768682099000, }; let history = client.dump_history(Some(start_ref), 1).await.unwrap(); assert!(!history.items.is_empty(), "Should have at least one block"); - + let first_block = &history.items[0]; if let Some(parsed) = &first_block.parsed { if let Some(header) = &parsed.header { @@ -125,4 +128,4 @@ async fn dump_history() { assert_eq!(header.height, 3399486); } } -} \ No newline at end of file +} diff --git a/utxorpc-tests/tests/watch.rs b/utxorpc-tests/tests/watch.rs index 93378b9..84ad367 100644 --- a/utxorpc-tests/tests/watch.rs +++ b/utxorpc-tests/tests/watch.rs @@ -51,6 +51,7 @@ async fn watch_for_tx( } } WatchedTx::Undo { .. } => {} + WatchedTx::Idle { .. } => {} } } None @@ -149,10 +150,8 @@ async fn watch_tx_all_patterns() { tokio::time::sleep(std::time::Duration::from_secs(1)).await; // Submit transaction - let submitted_tx_id = match submit_client.submit_tx(vec![tx_bytes]).await { - Ok(refs) => refs.first() - .map(|tx_ref| hex::encode(tx_ref)) - .expect("No transaction ref returned from submit"), + let submitted_tx_id = match submit_client.submit_tx(tx_bytes).await { + Ok(tx_ref) => hex::encode(tx_ref), Err(_) => { eprintln!("Transaction submission failed - skipping test"); return;