Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
empty vec is null
Browse files Browse the repository at this point in the history
  • Loading branch information
rllola committed Apr 22, 2024
1 parent 3fd7362 commit 1cdb0db
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Row>, 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)
Expand Down
2 changes: 1 addition & 1 deletion src/server/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl TryFrom<&Row> for BlockInfo {

// tx hashes
let txs: serde_json::Value = row.try_get("txs")?;
let tx_hashes: Vec<TxShort> = serde_json::from_value(txs)?;
let tx_hashes: Vec<TxShort> = if !txs.is_null() { serde_json::from_value(txs)? } else { vec![] };

let header = Header {
version,
Expand Down

0 comments on commit 1cdb0db

Please sign in to comment.