stacks-network / stacks-network/stacks-core

Calling stacks-node-api.mainnet-stacks.co returns a javascript code instead a json file

Open
#4,086 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

Describe the bug
Calling stacks-node-api.mainnet-stacks.co returns a javascript code instead a json file

Steps To Reproduce
This function calls the above API:
// reconfigure obtaining consensus hash
bskConfig.network.getConsensusHash = async function() {
//proe
// const httpResponse = await fetch('https://core.blockstack.org/v1/info')
const httpResponse = await fetch(bskConfig.network.coreApiUrl + '/v2/info')
logger.info(httpResponse)
const jsonResponse = await httpResponse.json()
logger.info(jsonResponse)

const lastBlockSeen = SERVER_GLOBALS.lastSeenBlockHeight

if (jsonResponse.stable_burn_block_height + 10 < lastBlockSeen) {
    logger.error('operation - getConsensusHash --> stacks-node-api.mainnet-stacks.co is >10 blocks behind the chain tip', {
        msgType: 'stale_core',
        burn_block_height: jsonResponse.burn_block_height,
        coreLastProcessed: jsonResponse.stable_burn_block_height
    })
    throw new Error('stacks-node-api.mainnet-stacks.co is >10 blocks behind the chain tip')
}

const consensusHash = jsonResponse.pox_consensus

logger.info(operation - getConsensusHash --> Obtained consensus hash ${consensusHash}, {
    msgType: 'consensus_hash',
    consensusHash
})
logger.info(consensusHash)
return consensusHash

}

Expected behavior
It used return a json file with the information, not a javascript code

Environment (please complete the following information):

  • OS: Ubuntu
  • Node
  • Version of the appropriate binary / software package

Additional context
It returns:
WhatsApp Image 2023-11-23 at 11 47 16_4cfd8851

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shown getConsensusHash function and request stacks-node-api.mainnet-stacks.co/v2/info directly, comparing the response headers and body with httpResponse.json() expectations. Trace bskConfig.network.coreApiUrl and the corresponding core API handler in stacks-core; done means the endpoint consistently returns the documented JSON information rather than JavaScript.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend, blockchain
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.