Skip to content

Commit

Permalink
Show difficulty target as u256 hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Feb 5, 2024
1 parent a9cb7ab commit 0b8310d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api-server/web-server/src/api/json_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use common::{
block::ConsensusData, output_value::OutputValue, Block, ChainConfig, Transaction, TxOutput,
},
primitives::{Amount, Idable},
Uint256,
};
use hex::ToHex;
use serde_json::json;
Expand Down Expand Up @@ -155,7 +156,10 @@ pub fn tx_to_json(tx: &Transaction, chain_config: &ChainConfig) -> serde_json::V

pub fn block_header_to_json(block: &Block) -> serde_json::Value {
let consensus_data = match block.header().header().consensus_data() {
ConsensusData::PoS(pos) => json!({"target": pos.compact_target()}),
ConsensusData::PoS(pos) => {
let target = Uint256::try_from(pos.compact_target()).expect("ok");
json!({"target": format!("{target:?}")})
}
ConsensusData::PoW(pow) => {
json!({
"nonce": pow.nonce(),
Expand Down

0 comments on commit 0b8310d

Please sign in to comment.