-
Notifications
You must be signed in to change notification settings - Fork 23
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
Example to calculate address balance #36
Comments
I'm still learning about the nuts and bolts of the blockchain and have refined my understanding of the question I first posed. From what I understand, there is a public key that is stored in the blockchain along with the transaction. I understand that each private key can have two public addresses, compressed and uncompressed. The private key can be used to calculate it's associated public keys, but the public keys cannot be reversed to find the private key. Please correct me if I am wrong as I am still learning. If this is the case, then as long as the public key is a searchable field in the database that is being parsed, then it should be possible to determine the unspents of a private key. Is the data being parsed able to be queried based on the public keys associated with the transactions? |
@KryptoNova the blockchain contains blocks, which each have transactions, which each have inputs and outputs. Each output has a script (the output script) which is typically (but not always) of some form akin to:
By looking at the output scripts, you can build an index (aka database) of unspents outputs for each unique script, or each unique public key hash ( |
I think I understand what needs to be done to make this happen. Thank you for the enlightenment! |
@KryptoNova apologies, I thought this was question was for another project.
I'll add an example here at some point. |
@KryptoNova and others who might be interested: bitcoinjs/regtest-server implements most of this functionality and may serve as your example: https://github.com/bitcoinjs/regtest-server/blob/b699cfad29e21272c7c644d9d66c5ad089d56be8/routes/1.js#L107-L112 router.get('/a/:address/unspents', addressWare, (req, res) => {
let { scId } = req.params
indexd().utxosByScriptRange({
scId, heightRange: [0, 0xffffffff], mempool: true
}, DBLIMIT, res.easy)
}) The result is an array of UTXO objects; you may sum the Note the |
Hello,
I am working on a project that has many private keys that have balances in them. I do not want to have to go out to a public API to query for security concerns.
I see there is a way to get the unspent amounts for an address in the example. However, I am not seeing a way to connect the private key to it's address. I believe this is what I would have to do to determine how much BTC the private key is linked to.
Is the data structure in indexd able to perform this type of query against the blockchain?
Thanks in advance!
The text was updated successfully, but these errors were encountered: