3

I'm looking into the data and source of bitcore-node ( http://bitcore.io/ ), I'm a bit confused how all the information is stored in the database, probably it's in a similar way to others block explorers, so maybe someone could help me.

In this case for example https://blockchain.info/tx/acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42

In the database I found two txo- txo-acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42-0

{"prevTxId":"8697331c3124c8a4cf2f43afb5732374ea13769e42f10aa3a98148a08989af5e","outputIndex":1,"sequenceNumber":4294967295,"script":"4730440220106c316c22d4bf8c970f8e4b1af1edd95121397cfe29ab987cb000b478ec8e4302202b77986b89d77ab716da3cf53424efacf35e9097b1c89194df220e99503b8cae01","scriptString":"71 0x30440220106c316c22d4bf8c970f8e4b1af1edd95121397cfe29ab987cb000b478ec8e4302202b77986b89d77ab716da3cf53424efacf35e9097b1c89194df220e99503b8cae01","heightConfirmed":37514}

txo-acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42-1

{"satoshis":10100000000,"script":"76a91427d25a1ff9a6da31eeb991c48bb6cd95191a6b2c88ac"}

Clearly different data, not sure why in one case we store the previous txid and in the other just the satoshis sent. It has to be obvious, but not sure what I'm missing here.

Another example https://blockchain.info/tx/00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b

txo-00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b-0 (from 0 to 5 all have similar data)

{"prevTxId":"6aebb4a764a027436f703ca9d42d0735423798f56973f9f236832a91fc2e9026","outputIndex":0,"sequenceNumber":4294967295,"script":"473044022057801e812f964bcb9e8ff17b37acef55afbb7119a66f24a148ba65e86a7aa1e3022064af657d280068b979ea17a29969976aedee8a664b3f1b575ebb88ef9275302601","scriptString":"71 0x3044022057801e812f964bcb9e8ff17b37acef55afbb7119a66f24a148ba65e86a7aa1e3022064af657d280068b979ea17a29969976aedee8a664b3f1b575ebb88ef9275302601","heightConfirmed":10712}

Also,... they are inputs, not outputs of the transaction.

I'm trying to read the code, but I can't get to understand all the pieces.

As someone points me in reddit, it looks like it's using txo-- to store both, outputs and inputs. So I'm not sure how bitcore manages to get the inputs/outputs separately later (the API allows you to request only the inputs for example).

2
  • Are you using one of the bitcore sub-projects? I don't see any references to a database in bitcore, or in any of the sub-projects that I looked in, actually.
    – morsecoder
    Aug 4, 2015 at 15:25
  • No, I was using the bitcore-node only, but because there were no subproject/module at the moment. They changed quite a bit the code since them, I need to review it again. I'm a bit confused by bitcore (only the library?) and bitcore-node (a full node with DB?), as you have a module for block explorer for bitcore (not bitcore-node) github.com/bitpay/bitcore-explorers . The node use a database : github.com/bitpay/bitcore-node/blob/master/lib/db.js Anyway, what I want is the DB key structure, to replicate it on my own
    – CONEJO
    Aug 6, 2015 at 5:55

1 Answer 1

2
+50

Bitpay's bitcore-node project uses the same datadirectory as Bitcoin Core. You can see this in their sample configuration in their README:

var configuration = {
    datadir: '~/.bitcoin',
    network: 'testnet'
};

As such, the you can see: What are the keys used in the blockchain levelDB (ie what are the key:value pairs)? for information on what is in this database. However, bitcore-node does provide another interface for storing extra data about addresses and their balances. This is defined in this file. You have to enable this in your configuration and re-index the blockchain to enable this module, as their README details.

As these lines show, for each output, key-value pairs are added to the leveldb database in this format:

key:   [AddressModule.PREFIXES.OUTPUTS, address, timestamp, txid, outputIndex].join('-'),
value: [output.satoshis, script, height].join(':')

And, similarly for inputs, this is the format of the key-value pairs:

key: [AddressModule.PREFIXES.SPENTS, input.prevTxId, input.outputIndex].join('-'),
value: [txid, j].join(':')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.