BitcoinUnlimited / ElectrsCash

Electron Cash Server, rust implementation. Forked from https://github.com/romanz/electrs
MIT License
24 stars 14 forks source link

Add flag for raw transaction to address/scripthash get_history #91

Open monsterbitar opened 4 years ago

monsterbitar commented 4 years ago

I currently have some code that requests history for an address, and I loop over it and ask for the raw transaction hex so I can parse it and evaluate some constraints local to my application.

I think this might be more efficiently done by adding a boolean flag INCLUDE_RAW_TRANSACTION = true to the two get_history calls that would append the hex-encoded transactions as part of the output.

For example, if I call blockchain.scripthash.get_history(scripthash) today, I get [ { "height": 200004, "tx_hash": "acc3758bd2a26f869fcc67d48ff30b96464d476bca82c1cd6656e7d506816412" }, { "height": 215008, "tx_hash": "f3e1bf48975b8d6060a9de8884296abb80be618dc00ae3cb2f6cee3085e09403" } ] back.

By calling blockchain.scripthash.get_history(scripthash, true) i would expect to get the same object as above, but in addition to tx_hash, I would also get tx_hex.

dagurval commented 4 years ago

I'm not sure about this, get_history is already the most expensive call in the protocol and it has no pagination support. At minimum, we need to define some good DoS limits for this.

As the electrum servers (all of them) work today, in the backend, we'd need to call getrawtransaction from bitcoind for every result, which will make the query super slow.

dagurval commented 4 years ago

Is there any more efficient way to query for the data you need? (is it generic enough tat it makes sense to index/filter server side?)

monsterbitar commented 4 years ago

Actually, the pagination part is also a big of an issue - could we add a "min_height" or something so that any transactions prior to a given height is excluded?

monsterbitar commented 4 years ago

I don't know if there's a more efficient way, I looked for a while but couldn't find any.

I have a list of outputs (address+satoshi pairs) and I need to know if there exist a transaction matching those outputs. (and the matches have to be in the same transaction, not as separate transactions)

I also need to know which transactions spends from a specific address, if any, but I don't have any other criteria for that part and I'm interested in the full spending transactions.

dagurval commented 4 years ago

Actually, the pagination part is also a big of an issue - could we add a "min_height" or something so that any transactions prior to a given height is excluded?

Adding min_height could work, don't see an issue with that.

I have a list of outputs (address+satoshi pairs) and I need to know if there exist a transaction matching those outputs. (and the matches have to be in the same transaction, not as separate transactions)

That does sound rather specific.

I also need to know which transactions spends from a specific address, if any, but I don't have any other criteria for that part and I'm interested in the full spending transactions.

I also recently wrote client side filtering to find transaction that spend from a specific address. This might be generic enough to be useful. This would be easy to implement in electrscash, because "fund" and "spend" utxo's are indexed separate, but this is not the case for other implementations of electrum server.