diff --git a/src/database.rs b/src/database.rs index 78837d9..00dd6e9 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1096,9 +1096,10 @@ impl Database { /// Returns the block at `block_height` if present, otherwise returns an Error. #[instrument(skip(self))] pub async fn block_by_height(&self, block_height: u32) -> Result, Error> { - let str = format!("SELECT b.*, txs FROM {0}.blocks b LEFT JOIN (SELECT block_id, JSON_AGG(JSON_BUILD_OBJECT('hash_id', encode(t.hash, 'hex'), 'tx_type', t.tx_type)) AS txs FROM {0}.transactions t GROUP BY t.block_id) t ON b.block_id = t.block_id WHERE b.header_height = {block_height};", self.network); + let str = format!("SELECT b.*, txs FROM {0}.blocks b LEFT JOIN (SELECT block_id, JSON_AGG(JSON_BUILD_OBJECT('hash_id', encode(t.hash, 'hex'), 'tx_type', t.tx_type)) AS txs FROM {0}.transactions t GROUP BY t.block_id) t ON b.block_id = t.block_id WHERE b.header_height = $1;", self.network); query(&str) + .bind(block_height) .fetch_optional(&*self.pool) .await .map_err(Error::from) diff --git a/src/server/blocks.rs b/src/server/blocks.rs index c63b50e..8ce5610 100644 --- a/src/server/blocks.rs +++ b/src/server/blocks.rs @@ -222,7 +222,7 @@ impl TryFrom<&Row> for BlockInfo { // tx hashes let txs: serde_json::Value = row.try_get("txs")?; - let tx_hashes: Vec = serde_json::from_value(txs)?; + let tx_hashes: Vec = if !txs.is_null() { serde_json::from_value(txs)? } else { vec![] }; let header = Header { version,