diff --git a/zebra-rpc/src/methods.rs b/zebra-rpc/src/methods.rs index 4fbe683a354..012ee13e1e6 100644 --- a/zebra-rpc/src/methods.rs +++ b/zebra-rpc/src/methods.rs @@ -852,15 +852,20 @@ where .transactions .iter() .map(|tx| { - TransactionObject::new( - tx.clone(), - height, - confirmations - .try_into() - .expect("should be less than max block height, i32::MAX"), - ) + let GetRawTransaction::Object(tx_obj) = + GetRawTransaction::from_transaction( + tx.clone(), + Some(height), + confirmations + .try_into() + .expect("should be less than max block height, i32::MAX"), + true, + ) + else { + unreachable!("an Object must be returned when verbose is true"); + }; + GetBlockTransaction::Object(tx_obj) }) - .map(GetBlockTransaction::Object) .collect(), _ => unreachable!("unmatched response to a transaction_ids_for_block request"), }; @@ -2041,20 +2046,6 @@ pub struct TransactionObject { // TODO: many fields not yet supported } -impl TransactionObject { - /// Creates a new [`TransactionObject`]. - fn new(tx: Arc, height: block::Height, confirmations: u32) -> Self { - TransactionObject { - hex: tx.into(), - height: height - .0 - .try_into() - .expect("valid block heights are limited to i32::MAX"), - confirmations, - } - } -} - impl Default for TransactionObject { fn default() -> Self { Self { diff --git a/zebra-rpc/src/methods/tests/vectors.rs b/zebra-rpc/src/methods/tests/vectors.rs index 5f76c468266..722e89e5664 100644 --- a/zebra-rpc/src/methods/tests/vectors.rs +++ b/zebra-rpc/src/methods/tests/vectors.rs @@ -242,31 +242,12 @@ async fn rpc_getblock() { ); } - // With verbosity=2, the RPC calls getrawtransaction which queries the - // mempool, which we need to mock since we used a MockService for it. This - // function returns a future that mocks that query. This is similar to what - // we use in the getrawtransaction test, but here we don't bother checking - // if the request is correct. - let make_mempool_req = || { - let mut mempool = mempool.clone(); - async move { - mempool - .expect_request_that(|_request| true) - .await - .respond(mempool::Response::Transactions(vec![])); - } - }; - // Make height calls with verbosity=2 and check response for (i, block) in blocks.iter().enumerate() { - let get_block_req = rpc.get_block(i.to_string(), Some(2u8)); - - // Run both the getblock request and the mocked mempool request. - // This assumes a single mempool query, i.e. that there is a single - // transaction the block. If the test vectors changes and the block - // has more than one transaction, this will need to be adjusted. - let (response, _) = futures::join!(get_block_req, make_mempool_req()); - let get_block = response.expect("We should have a GetBlock struct"); + let get_block = rpc + .get_block(i.to_string(), Some(2u8)) + .await + .expect("We should have a GetBlock struct"); let (expected_nonce, expected_final_sapling_root) = get_block_data(&read_state, block.clone(), i).await; @@ -310,10 +291,10 @@ async fn rpc_getblock() { // Make hash calls with verbosity=2 and check response for (i, block) in blocks.iter().enumerate() { - let get_block_req = rpc.get_block(blocks[i].hash().to_string(), Some(2u8)); - - let (response, _) = futures::join!(get_block_req, make_mempool_req()); - let get_block = response.expect("We should have a GetBlock struct"); + let get_block = rpc + .get_block(blocks[i].hash().to_string(), Some(2u8)) + .await + .expect("We should have a GetBlock struct"); let (expected_nonce, expected_final_sapling_root) = get_block_data(&read_state, block.clone(), i).await;