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

Bug: failed to get block hash 0000000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0 #1101

Open
redtigervn opened this issue Oct 25, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@redtigervn
Copy link

Hi there,

I've installed bitcoin node and electrs server on VPS. I write nodejs script to listen new transaction from specific addrs and I get this error when I use Electrum protocol method blockchain.scripthash.subscribe to subscribe scripthash. Then I use electrumClient.subscribe.on event to listen new tx. But I always get this error

Failed to get block: 0000000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

This block hash has 66 characters instead of 64 characters. Anyone get this error?

I also delete electrs_db folder and sync data again but it doesn't help.

image

@redtigervn redtigervn added the bug Something isn't working label Oct 25, 2024
@romanz
Copy link
Owner

romanz commented Oct 26, 2024

Which client library is being used? Would it be possible to share the requests' log?

@romanz
Copy link
Owner

romanz commented Oct 26, 2024

IIUC, by removing the first zero byte, we get the following valid block hash:
https://blockstream.info/block/00000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

@redtigervn
Copy link
Author

redtigervn commented Oct 28, 2024

Hi Romanz,
Sorry for late reply, I use electrum-client lib (version ^0.0.6)
I also use bitcoinjs-lib lib to convert address to electrum hash

const crypto = require('crypto');
const ecc = require('tiny-secp256k1');
const bitcoin = require('bitcoinjs-lib');
bitcoin.initEccLib(ecc);

const script = bitcoin.address.toOutputScript(address);
const hash = crypto.createHash('sha256').update(script).digest();
const reversedHash = Buffer.from(hash.reverse());
cosnt scripthash = reversedHash.toString('hex');

electrumClient.blockchainScripthash_subscribe(scripthash).then((scripthash) => {              
    console.log(`Subscribed to updates for scripthash: ${scriptHash}`);
});

electrumClient.subscribe.on('blockchain.scripthash.subscribe', async (data) => {
    const [scripthash, status] = data;
    //receive a notification when the status of the script hash changes.
    //do something here....
});

@redtigervn
Copy link
Author

IIUC, by removing the first zero byte, we get the following valid block hash: https://blockstream.info/block/00000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

but I don't know where this block hash come from. I get this error when I'm listening new status of the script hash changes.
This protocol method: blockchain.scripthash.subscribe

@romanz
Copy link
Owner

romanz commented Oct 28, 2024

Unfortunately, I am not familiar with this client library.

You can run electrs with higher logging verbosity, to see all the JSON-RPC requests and responses:

export RUST_LOG=electrs::server=DEBUG

I would suggest also trying to see if your code works on other Electrum servers, and maybe opening an issue here.

@redtigervn
Copy link
Author

Unfortunately, I am not familiar with this client library.

You can run electrs with higher logging verbosity, to see all the JSON-RPC requests and responses:

export RUST_LOG=electrs::server=DEBUG

I would suggest also trying to see if your code works on other Electrum servers, and maybe opening an issue here.

Thanks for your suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants