-
Notifications
You must be signed in to change notification settings - Fork 38.8k
[REST] Add send raw transaction #6844
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
Conversation
|
This makes sense to me. It was already possible to do over RPC, but there
is no need for authentication.
Something similar could be done for submitting blocks?
|
|
ut ACK. Nits:
|
@jgarzik why not just: Also, concept ACK, this would be great |
doc/REST-interface.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be a GET... if this is intended to be a REST-ful interface.
Some proxies won't allow URL's longer than 2000 chars anyway, so using this hacky [in-the-url] approach will be prone to issues.
|
utACK, except the nits posted are blockers to the merge IMHO. |
|
agree w/ @dcousens |
|
+1 for POST /rest/tx I would also think supporting BIN (and JSON) as input format could make sense and would be consistent. utACK. |
01b1536 to
ff5f52c
Compare
|
Thanks for the fast feedback. I've changed it to POST /rest/tx Regarding the format: So far there is support for JSON / HEX / BIN for some of the REST methods. IMHO it should be either all methods support all formats or there is only one until there is a demand / request for other formats. I think the REST API was mostly created for webclients, which are probably most confortable with JSON or plaintext, or what was the intention when REST was added? If we want to have support for several formats, I would vote for using the HTTP header files instead of a file-ending for the request:
SubmitBlock over REST is a good idea but I'll leave it out for another PR :) |
doc/REST-interface.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should specify:
"application/octet-stream"for plain-old-data"text/plain"for hex"application/json"for JSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will ones we agreed on it :)
In the code in this version it's like in the other methods, determined by the ending, e.g.
POST 127.0.0.1:18332/rest/tx.hex
|
@lclc agreed we should use the |
|
@lclc I have no doubt the file name extensions were made for easily viewing the data via a browser URL. Not for API usage. |
|
As background, the discussion in IRC generally concluded that Content-type as the only method of specifying file type was not good. Command line users (curl, wget) and web browser URL bars generally make it easy to alter a URL, yet difficult to specify Content-type. |
|
@jgarzik then lets take the approach of |
|
It is fair to open the topic - not disputing that. What is the best for the most likely users? If most users are automated, content-type would seem reasonable. |
|
If we want to have it easy to alter the URL I would vote for using GET for everything ;) With the RPC interface we already have a easy to use API for command line usage. Does anyone know a project that is using the REST API? |
|
If I think about it without looking at other REST API designs, I like the file extension to determine the output format. Adding a file extension to the URL is much easier as adding a content-type request header. I could see:
Non post commands (currently everything expect If this makes sense, i think this PR would only need to evaluate the |
|
Using GET has some length limitations (not in RFC [there it is uint32max IIRC] but in most implementations). Using POST for posting data makes sense IMO. Another nice addition would be to support an array of transactions. I think the later, allowing tx submission without doing the JSON enc-/decoding, would be desirable. |
|
I don't think Bitcoin Core should do it different then everyone else because we think it's easier. Another topic to discuss there is adding a REST API version method. Regarding an array of transaction: |
|
@lclc: fair enough. |
|
Thanks. I'll add JSON & BIN as input formats next, determining them from the requested output format based on the 'file' ending in the URL (I expect if someone sends binary he wants binary back. Other scenarios can be covered ones we agree or disagree on Content-Type & Accept for data formats). |
Right. That exactly how |
|
In terms of HTTP "verbs", the method can be GET but should be POST or PUT. |
|
ff5f52c to
c818404
Compare
|
Re-reviewing latest version:
ACK with those updates |
|
Thanks for the review. It's strange that Travis says the checks passed even when they actually didn't (https://travis-ci.org/bitcoin/bitcoin/builds/87533414). Makes sense, moved the POST /rest/tx (without /) code to rest_tx_sendrawtx (although the naming isn't consistent anymore now, anyone has a better idea for a function name?). My binary tests (see latest part of rest.py) are still failing. Maybe someone has an idea whats wrong there or in the code? Thanks. |
c818404 to
91687ba
Compare
src/rest.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 6th argument is not fRejectAbsurdFee currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, set both to false now.
91687ba to
d28e974
Compare
src/rest.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you set it to false? A better (but not perfect) solution would be something like maflcko@18f5df4#diff-52257e4c1cedbf5e302f183065cab880L812
But #6726 is not yet merged and needs more work anyway. So let's just consider this as NIT and I will clean it up in a later PR if this gets merged before #6726.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also travis fails with "absurdly-high-fee" so you'd have to pass it on, I guess. (Haven't looked closely, yet)
But then this is more like a blocking NIT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's job of the API user / wallet to check if the fee is too high or not, instead of trusting the node to check this and care about it.
The Travis error regarding "absurdly-high-fee" comes later, not because of this but because of the RPC-call to cross-check the result I do there. I'm aware of that, but it already fails earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no wallet when you use raw transactions...
The rpc interface checks for high fee by default and you can disable it with an additional argument. Any chance you could implement something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere there is a wallet to create that raw transaction.
IMO it should be checked on the sender side (the user of the REST API) if
the fee is too high and not trust the node with this.
E.g. someone could implement a web wallet that only relies on some nodes it
doesn't control so you trust that node that it actually cares if you added
a too high fee or not. False security.
E.g. Nodes operated by miners have no incentive to tell the user of their
REST API the truth.
Am 28.10.2015 11:23 schrieb "MarcoFalke" [email protected]:
In src/rest.cpp
#6844 (comment):
- else
- {
if (!DecodeHexTx(tx, strTx))return RESTERR(req, HTTP_BAD_REQUEST, strprintf("TX decode failed %s",strTx));- }
- uint256 hashTx = tx.GetHash();
- CCoinsViewCache &view = *pcoinsTip;
- const CCoins* existingCoins = view.AccessCoins(hashTx);
- bool fHaveMempool = mempool.exists(hashTx);
- bool fHaveChain = existingCoins && existingCoins->nHeight < 1000000000;
- if (!fHaveMempool && !fHaveChain) {
// push to local node and sync with walletsCValidationState state;bool fMissingInputs;if (!AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, false, false)) {There is no wallet when you use raw transactions...
The rpc interface checks for high fee by default and you can disable it
with an additional argument. Any chance you could implement something like
that?—
Reply to this email directly or view it on GitHub
https://github.com/bitcoin/bitcoin/pull/6844/files#r43237619.
|
Ok. @MarcoFalke that's not the problem. You can run the same tx with hex (currently commented out) and it works. I'll look at this again when I've changed the Fee thing |
src/rest.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this parameter still here?
Isn't the POST expecting a pure octet stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you're expecting: transaction=<binary>, that seems very odd.
It should just be <binary>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This needs to be removed. strBody should treated as equivalent to strTx.
|
@lclc So why would travis fail if that's not the problem? You can try to set it to |
|
@lclc I'm happy to take over this if you're busy |
|
Sorry didn't have time for this, started at a new job (in Bitcoin), been abroad the last 3 weeks :) @dcousens If you like to finish it that would be great, so maybe this makes it into 0.12. I can give you merge rights on my Github fork so we don't lose the discussions in here? Otherwise I'll work on it again at the last weekend before December. |
|
@lclc sounds good, add me when you can. |
d28e974 to
8c28d71
Compare
8c28d71 to
7f63a2e
Compare
|
Needs rebase. |
|
I'm still not entirely convinced that submitting anything belongs on this interface. I've always felt that the REST interface was read-only on purpose - a way to query data that is public anyway without authentication. Making is possible to submit something changes the security expectations. |
|
Closing this PR for now, to keep this interface read-only. |
I think that is a valid reason 👍 |
Adding sendrawtransaction to the REST API enables web-clients like https://coinb.in/ (and many others) to work with Bitcoin Core nodes instead of using a centralized wallet API service.
So far the REST API was read-only but I don't know if this was intentionally or not.
Python tests will follow ones it's clear when there are some Concept ACK for this PR.
Or if someone likes to write some Python code for this PR let me know. I don't have much Python experience yet so it might take a while :)
Thanks Jonas Schnelli for the pre-PR feedback.