Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChaingraphAPI issue #146

Open
cromachina opened this issue Jul 23, 2024 · 3 comments
Open

ChaingraphAPI issue #146

cromachina opened this issue Jul 23, 2024 · 3 comments

Comments

@cromachina
Copy link

An error is thrown when trying to extract data from a ChaingraphAPI response, seemingly.
Minimal example:

import bitcash
k = bitcash.PrivateKeyTestnet()
k.get_balance()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/wallet.py", line 216, in get_balance
    _ = self.get_unspents()
        ^^^^^^^^^^^^^^^^^^^
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/wallet.py", line 234, in get_unspents
    self.unspents[:] = NetworkAPI.get_unspent(
                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/network/services.py", line 247, in get_unspent
    for endpoint in get_sanitized_endpoints_for(network):
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/utils.py", line 97, in _wrapped
    return_value = cache_fn(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/utils.py", line 91, in cache_fn
    value = fn(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/network/services.py", line 126, in get_sanitized_endpoints_for
    endpoints_blockheight[i] = endpoint.get_blockheight(timeout=DEFAULT_TIMEOUT)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cro/aux/Projects/crypto-bot/venv/lib/python3.12/site-packages/bitcash/network/APIs/ChaingraphAPI.py", line 77, in get_blockheight
    blockheight = int(json["data"]["block"][0]["height"])
                      ~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
@merc1er
Copy link
Member

merc1er commented Jul 23, 2024

It looks like the chaingraph testnet instance returns invalid data... I am getting various errors (mainly ConnectionResetError: [Errno 104] Connection reset by peer) when running your code snippet.

Sadly this is the single main recurring issue that BitCash has been dealing with pretty much forever: none of the third party services used to interact with the blockchain are reliable.

However, the mainnet instance seems to be working fine:

import bitcash
k = bitcash.PrivateKey()
k.get_balance()

# Returns '0'

@merc1er
Copy link
Member

merc1er commented Jul 23, 2024

FYI @cromachina here is the response from ChainGraph when querrying the block height:

Request:

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"query": "query GetBlockheight($node: String!) { block(limit: 1, order_by: { height: desc }, where: { accepted_by: { node: { name: { _like: $node } } } }) { height } }", "variables": { "node": "%testnet" }}' \
  https://demo.chaingraph.cash/v1/graphql

Response:

{
  "errors": [
    {
      "extensions": {
        "code": "unexpected",
        "path": "$"
      },
      "message": "database query error"
    }
  ]
}

and the worst thing is it's a 200 status code... Again, it looks like this is specific to testnet.

So that doesn't seem to be an issue with BitCash, though it is breaking BitCash as a result. I suggest raising an issue with Chaingraph directly so hopefully they can fix it: https://github.com/bitauth/chaingraph

@merc1er merc1er closed this as completed Jul 23, 2024
@merc1er
Copy link
Member

merc1er commented Jul 23, 2024

Actually I'll leave this open even though it's an issue with Chaingraph, in case anyone is having the same problem.

Hopefully this is fixed soon 🤞🏻

@merc1er merc1er reopened this Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants