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

Added batch address/scripthash POST call #20

Open
wants to merge 1 commit into
base: new-index
Choose a base branch
from

Conversation

gr0kchain
Copy link

Added a batch POST call. This is similar to the address and scripthash get calls, but allows retrieving more than one address at a time instead of having to flood the elects server with get requests for each address.

@shesek
Copy link
Collaborator

shesek commented Jun 8, 2020

Thanks for the PR!

I've been thinking to implement this with a more generic POST /batch endpoint that lets you batch requests to any GET endpoint, by specifying an array of URI paths. For example:

$ curl -X POST https://blockstream.info/api/batch \
       -d '["/address/<address1>/stats","/address/<address1>/txs","/address/<address2>/stats","/address/<address2>/txs"]'

This could be accomplished by emulating HTTP calls via handle_request(), without sending actual HTTP requests.

But I can see this being useful even if only available for the /address/:address/stats endpoint. I would change the endpoint to accept a JSON array of addresses instead of a comma-separated list, though.

What do you think @greenaddress?

@gr0kchain
Copy link
Author

Invoking the existing single object calls through some batch wrapper does seem feasible. I'd however avoid having to pass through the amount of overhead in the request. The repetitiveness of the the URL templates seem to add unnecessary bloat to the payload.

@shesek
Copy link
Collaborator

shesek commented Jun 17, 2020

Gzipping the request would make the url template repetitiveness much less of an issue, at least bandwidth wise.

@gr0kchain
Copy link
Author

gr0kchain commented Jun 18, 2020

That would, but gzipping it without the repetitiveness would be even better. Either way, I think the shortest path to getting this working is as you've suggested. Perhaps a reduction could be as follows, where the patterns for the requests are parsed and batched by path and array of elements.

curl -X POST https://blockstream.info/api/batch \
       -d 
'[{
"/address/stats" : [<address1>, <address2>],
"/address/txs" : [<address1>, <address2>]
}]'

@tiero
Copy link

tiero commented Nov 23, 2020

Any update on this? Super valuable feature

junderw pushed a commit to junderw/electrs that referenced this pull request Sep 15, 2023
@junderw
Copy link

junderw commented Sep 15, 2023

Sorry, I pushed something to my personal fork and for some reason it took the PR references from the mempool repo and converted them to this repo and made a mention, bumping the issue. Looks like a bug with GitHub.

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

Successfully merging this pull request may close these issues.

5 participants