Skip to content

Commit

Permalink
Merge pull request #1427 from mintlayer/fix/get_block_json_return
Browse files Browse the repository at this point in the history
Fix get_block_json return to return json value instead of a string
  • Loading branch information
TheQuantumPhysicist authored Jan 5, 2024
2 parents 768351b + 770ea41 commit e3dc5b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 7 additions & 3 deletions chainstate/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait ChainstateRpc {

/// Returns a json-encoded serialized block with the given id.
#[method(name = "get_block_json")]
async fn get_block_json(&self, id: Id<Block>) -> RpcResult<Option<String>>;
async fn get_block_json(&self, id: Id<Block>) -> RpcResult<Option<serde_json::Value>>;

/// Returns a hex-encoded serialized blocks from the mainchain starting from a given block height.
#[method(name = "get_mainchain_blocks")]
Expand Down Expand Up @@ -145,7 +145,7 @@ impl ChainstateRpcServer for super::ChainstateHandle {
Ok(block.map(HexEncoded::new))
}

async fn get_block_json(&self, id: Id<Block>) -> RpcResult<Option<String>> {
async fn get_block_json(&self, id: Id<Block>) -> RpcResult<Option<serde_json::Value>> {
let both: Option<(Block, BlockIndex)> = rpc::handle_result(
self.call(move |this| {
let block = this.get_block(id);
Expand All @@ -171,7 +171,11 @@ impl ChainstateRpcServer for super::ChainstateHandle {

let result: Option<String> = result.map(|res| dehexify_all_addresses(&chain_config, &res));

Ok(result)
let result = result.map(|res| serde_json::from_str::<serde_json::Value>(&res));

let result = result.transpose();

rpc::handle_result(result)
}

async fn get_mainchain_blocks(
Expand Down
1 change: 0 additions & 1 deletion test/functional/wallet_submit_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ async def async_test(self):

block_id = node.chainstate_block_id_at_height(1)
block = node.chainstate_get_block_json(block_id)
block = json.loads(block)
timestamp = block['block']['V1']['header']['block_header']['timestamp']['timestamp']

output = await wallet.get_transaction(tx_id)
Expand Down

0 comments on commit e3dc5b4

Please sign in to comment.