Proposal: RPC Interface Improvements #5120

issue scmorse opened this issue on October 22, 2014
  1. scmorse commented at 10:07 PM on October 22, 2014: none

    We (at <a href="http://www.ziftr.com/">ziftr</a>) are working on a cryptocurrency API and may want to alter the RPC interface in our copy of the codebase. We think that the alterations to the RPC interface that we would like to make may be useful to others, and we hope that any work we do will be available to the bitcoin community. Here we are outlining the proposal to get some feedback about how one could implement these changes.

    Essentially, we want to split up the work that is done in <tt>signrawtransaction</tt> so that the different parts can be used individually. This will make the RPC calls more modular, offering more flexibility to any developer who is using the daemon's RPC interface.

    The basic idea is that <tt>signrawtransaction</tt> currently has to calculate the hashes that need to be signed, sign them with the appropriate private keys, and then bundle everything up into a raw transaction. We would like to make it so that each of these could be done separately. For us, this means the middle step, the calculation of signatures, being done on a different device.

    The first change we would like to make is to add an RPC method call named <tt>getdatatosign</tt>. This takes the raw transaction and a few optional parameters, and calculates all data that must be signed. The returned value from this could be fed directly to <tt>signrawtransaction</tt>.

    // Creates an array of data that needs to be signed

    <pre> getdatatosign "hexstring" ( [{"txid":"id", "vout":n, "scriptPubKey":"hex", "redeemScript":"hex"}, ...] sighashtype ) </pre>

    Return data format:

    <pre> [ { "txid":"id", "vout":n, "scriptPubKey":"hex", "redeemScript":"hex", /* Only present if p2sh. */ "tosign":"hex", "pubkey": "hex", /* Present if not pay to pub key, which is most of the time. */ "r":"", "s":"" } ] </pre>

    // If r and s are filled in, possibly by someone else who owns the keys, // then this can just bundle them up into the transaction ready to send.  // If they don't exist, the daemon will look for the appropriate // keys to sign with and fill them in (or use the given private keys). // The datatosign, r, and s fields are not required to be keys in the // JSON object, so that this change is backwards compatible. 

    <pre> signrawtransaction "hexstring" ( [{"txid":"id", "vout":n, "scriptPubKey":"hex", "redeemScript":"hex", "datatosign":"hex", "r":"hex", "s":"hex" }] ["privatekey1",...] sighashtype ) </pre>

    <pre> { "hex": "0100000001ba8bb652d537989726d242bf99153fb4e5de262ecbaa975ab1715abbb0597fe7000000006b483045022100e6db653e65c48838fc7d58f7696b20bb74d27b315a0a3cba3e80f6b9e5fc0d3402207a2613efe02663d8f8933922a328b8333d0acd31d43c738e2fbcc58d3f3ace87012102c1e842bd2c8314f0699d606a1c712e26abc9836d6f76fc64ee3f73f31b753945ffffffff0110a8a600000000001976a9142badcf56c4fb168773ff661606e5c9b8eb55d5fd88ac00000000", "complete": true } </pre>

    Essentially, this just exports some of the work that currently is done in <tt>signrawtransaction</tt> to a second method, and <tt>signrawtransaction</tt> can still be used as it was before, but now it can make a call to <tt>getdatatosign</tt> to do the first part of its work.

    These may not be the optimal method names, parameters, or return values for such methods, but hopefully they convey the proposal. The goal is that this will make the rpc calls more modular, so that developers will have more flexibility in their applications. In particular, it will make it easier for applications where the signing is to be done on a different device.

    I'm sure there are details that need to be worked out, but I think the core idea here is a good one. Please let me know if there is anything here you think can be improved! Any feedback on this proposal would be greatly appreciated.

  2. laanwj added the label RPC on Oct 23, 2014
  3. gavinandresen commented at 2:33 PM on October 23, 2014: contributor

    Are you proposing an incompatible change to the existing signrawtransaction RPC call?

  4. scmorse commented at 2:38 PM on October 23, 2014: none

    No, I don't believe so, I think everything would be backwards compatible. There would be new JSON arguments that could be added, but they wouldn't be required to be there. And signrawtransaction would still work exactly as before when not used with these extra new JSON params. Signrawtransaction could just make a call to getdatatosign to do part of its work.

  5. jgarzik commented at 2:45 PM on October 23, 2014: contributor

    Check out the new bitcoin-tx utility. It is straightforward to add new "calls" as discrete elements there. bitcoin-tx offers the same capabilities with createrawtransaction and sendrawtransaction.

    For any RPCs which are "pure functions" -- they do not rely on bitcoind wallet data -- they can be used via this utility instead. bitcoin-tx does not use RPC calls (at present), and does not access wallet data.

    Long term, "pure function" style use will be exported via utilities rather than RPCs. e.g. You do not need to contact a server, simply to execute decoderawtransaction.

  6. scmorse commented at 3:14 PM on October 23, 2014: none

    <p>So maybe <tt>getdatatosign</tt> should just be another utility added to <tt>bitcoin-tx</tt>? That seems to make sense. Could <tt>signrawtransaction</tt> still make use of the <tt>getdatatosign</tt> if this were the case?</p>

    <p>Would <tt>signrawtransaction</tt> be a method of <tt>bitcoin-tx</tt>? Is there any documentation on how the calls will be split up between <tt>bitcoin-cli</tt> and <tt>bitcoin-tx</tt>?</p>

  7. jgarzik commented at 3:16 PM on October 23, 2014: contributor

    @scmorse getrawtransaction?

  8. scmorse commented at 3:17 PM on October 23, 2014: none

    Sorry, meant <tt>signrawtransaction</tt>. Changed my prev comment.

  9. benjiqq commented at 10:28 AM on November 1, 2014: none

    @scmorse Thanks for the work. Could you provide a Use-case for this?

    I think its important to distinguish between internal utilities and API's. bitcoin-tx is not exposed to user-space in the same way the RPC is. RPC is widely known and documented.

  10. scmorse commented at 4:04 PM on November 2, 2014: none

    This could be part of a <tt>bitcoin-tx</tt> utility, but it also can make use of information in the actual blockchain, so having it as part of the actual <tt>bitcoin-cli</tt> as well seems to make sense.

    Sure, I can tell you how we are planning to use this and give an example.

    We are creating an API that uses our servers to make and deal with raw transactions so that the user doesn't have to. Essentially, we use the <tt>getdatatosign</tt> RPC call to get the data that needs to be signed, send it to the phones, they sign it with their keys and return the result (R,S, pub key). Our server can then use these to complete the transaction.

    I actually just finished coding this up, using the Litecoin project as a starting point, and did an example of it working, so I'll show it below. This all takes place on the Litecoin testnet.

    SAMPLE REQUEST FROM PHONE:

    <pre> { "fee_per_kb": 10000, "surplus_refund_address": "mrVKajRiXK7vCn3auzx2qb7Gd3cDUSiC6L", "inputs_addresses": [ "mjYN7McYzwius96QGpDDZYXaaCR1ZkAX3a", "mz7veJL7NPAsJqu5nuLWvRhpNkVHW6PjbR" ], "outputs_addresses": [ { "address": "mrVKajRiXK7vCn3auzx2qb7Gd3cDUSiC6L", "amount": 5999000000 } ] } </pre>

    SERVER FINDS THESE TX OUTS:

    <pre> (From tx: eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488) [ { "value":30.00000000, "n":3, "scriptPubKey":{ "asm":"OP_DUP OP_HASH160 2c24cca04e5115cac70191543293c41fc8589f56 OP_EQUALVERIFY OP_CHECKSIG", "hex":"76a9142c24cca04e5115cac70191543293c41fc8589f5688ac", "reqSigs":1, "type":"pubkeyhash", "addresses":[ "mjYN7McYzwius96QGpDDZYXaaCR1ZkAX3a" ] } }, { "value":30.00000000, "n":4, "scriptPubKey":{ "asm":"OP_DUP OP_HASH160 cc0f71d3b6c2238d73aab4cab4226262eca9f1d4 OP_EQUALVERIFY OP_CHECKSIG", "hex":"76a914cc0f71d3b6c2238d73aab4cab4226262eca9f1d488ac", "reqSigs":1, "type":"pubkeyhash", "addresses":[ "mz7veJL7NPAsJqu5nuLWvRhpNkVHW6PjbR" ] } } ] </pre>

    FIRST MAKES THE RAW TRANSACTION:

    <pre> $ ./litecoind createrawtransaction '[{"txid":"eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488", "vout":3}, {"txid":"eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488", "vout":4}]' '{"mrVKajRiXK7vCn3auzx2qb7Gd3cDUSiC6L":59.99000000}' </pre>

    <pre> 010000000288e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0300000000ffffffff88e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0400000000ffffffff01c0799165010000001976a914785a5258008e272dd1a434eef745fb1277abeee688ac00000000 </pre>

    GET THE DATA THAT NEEDS TO BE SIGNED AND SEND IT TO THE PHONES:

    <pre> $ ./litecoind getdatatosign 010000000288e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0300000000ffffffff88e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0400000000ffffffff01c0799165010000001976a914785a5258008e272dd1a434eef745fb1277abeee688ac00000000 </pre>

    <pre> [ { "txid" : "eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488", "vout" : 3, "scriptPubKey" : "76a9142c24cca04e5115cac70191543293c41fc8589f5688ac", "tosign" : "b4432ef245832428642ce9e83c6396f40fcf0e1e1614f2e85540b2568fd4d89d", "pubkey" : "", "r" : "", "s" : "", "address" : "mjYN7McYzwius96QGpDDZYXaaCR1ZkAX3a", "type" : "pubkeyhash" }, { "txid" : "eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488", "vout" : 4, "scriptPubKey" : "76a914cc0f71d3b6c2238d73aab4cab4226262eca9f1d488ac", "tosign" : "4eba4e820bf61c91f48e805f4920418a092602070eb1dbdeae925e74c8ceb7a0", "pubkey" : "", "r" : "", "s" : "", "address" : "mz7veJL7NPAsJqu5nuLWvRhpNkVHW6PjbR", "type" : "pubkeyhash" } ] </pre>

    PHONES FILL IN THE DATA AND SEND BACK:

    <pre> "hex":"010000000288e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0300000000ffffffff88e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0400000000ffffffff01c0799165010000001976a914785a5258008e272dd1a434eef745fb1277abeee688ac00000000" ... [ { "txid" : "eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488", "vout" : 3, "scriptPubKey" : "76a9142c24cca04e5115cac70191543293c41fc8589f5688ac", "tosign" : "b4432ef245832428642ce9e83c6396f40fcf0e1e1614f2e85540b2568fd4d89d", "pubkey" : "030995f693606d7102dbce24273f939b7de15487713d8e884afcce3d37c359d767", "r" : "ef0dfc1d06f39d9b01fa8248d2718e5b5e26430e820385671ee4f30b104162cd", "s" : "979442b7d7838ae0cc29479ddc41d0b76810c0711e86104225b716159dbc31d2", "address" : "mjYN7McYzwius96QGpDDZYXaaCR1ZkAX3a", "type" : "pubkeyhash" }, { "txid" : "eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488", "vout" : 4, "scriptPubKey" : "76a914cc0f71d3b6c2238d73aab4cab4226262eca9f1d488ac", "tosign" : "4eba4e820bf61c91f48e805f4920418a092602070eb1dbdeae925e74c8ceb7a0", "pubkey" : "0304ae97fe2acba599df9b523ec5219ae421cdae67657d57bd0c2c47c27dd42742", "r" : "a7aa7f41e3889c48599db2d91ce69968155ea3e0e4643d9ceb4dbc44da9da3b5", "s" : "4b0ed41fe0e0ec4a6459165e628f1269b63ae8e90309d340688a49d2d8d48b5d", "address" : "mz7veJL7NPAsJqu5nuLWvRhpNkVHW6PjbR", "type" : "pubkeyhash" } ] </pre>

    SERVER BUNDLES THE RESULT INTO A TRANSACTION USING signrawtransaction:

    <pre> $ ./litecoind signrawtransaction "010000000288e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0300000000ffffffff88e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb0400000000ffffffff01c0799165010000001976a914785a5258008e272dd1a434eef745fb1277abeee688ac00000000" '[{"txid" : "eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488","vout" : 3,"scriptPubKey" : "76a9142c24cca04e5115cac70191543293c41fc8589f5688ac","tosign" : "b4432ef245832428642ce9e83c6396f40fcf0e1e1614f2e85540b2568fd4d89d","pubkey" : "030995f693606d7102dbce24273f939b7de15487713d8e884afcce3d37c359d767","r" : "ef0dfc1d06f39d9b01fa8248d2718e5b5e26430e820385671ee4f30b104162cd","s" : "979442b7d7838ae0cc29479ddc41d0b76810c0711e86104225b716159dbc31d2","address" : "mjYN7McYzwius96QGpDDZYXaaCR1ZkAX3a","type" : "pubkeyhash"},{"txid" : "eb780798c67a9ec63129eace11d72df16f1ffacaf5ef23519d235f7ff670e488","vout" : 4,"scriptPubKey" : "76a914cc0f71d3b6c2238d73aab4cab4226262eca9f1d488ac","tosign" : "4eba4e820bf61c91f48e805f4920418a092602070eb1dbdeae925e74c8ceb7a0","pubkey" : "0304ae97fe2acba599df9b523ec5219ae421cdae67657d57bd0c2c47c27dd42742","r" : "a7aa7f41e3889c48599db2d91ce69968155ea3e0e4643d9ceb4dbc44da9da3b5","s" : "4b0ed41fe0e0ec4a6459165e628f1269b63ae8e90309d340688a49d2d8d48b5d","address" : "mz7veJL7NPAsJqu5nuLWvRhpNkVHW6PjbR","type" : "pubkeyhash"}]' { "hex" : "010000000288e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb030000006c493046022100ef0dfc1d06f39d9b01fa8248d2718e5b5e26430e820385671ee4f30b104162cd022100979442b7d7838ae0cc29479ddc41d0b76810c0711e86104225b716159dbc31d20121030995f693606d7102dbce24273f939b7de15487713d8e884afcce3d37c359d767ffffffff88e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb040000006b483045022100a7aa7f41e3889c48599db2d91ce69968155ea3e0e4643d9ceb4dbc44da9da3b502204b0ed41fe0e0ec4a6459165e628f1269b63ae8e90309d340688a49d2d8d48b5d01210304ae97fe2acba599df9b523ec5219ae421cdae67657d57bd0c2c47c27dd42742ffffffff01c0799165010000001976a914785a5258008e272dd1a434eef745fb1277abeee688ac00000000", "complete" : true } </pre>

    <pre> $ ./litecoind sendrawtransaction 010000000288e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb030000006c493046022100ef0dfc1d06f39d9b01fa8248d2718e5b5e26430e820385671ee4f30b104162cd022100979442b7d7838ae0cc29479ddc41d0b76810c0711e86104225b716159dbc31d20121030995f693606d7102dbce24273f939b7de15487713d8e884afcce3d37c359d767ffffffff88e470f67f5f239d5123eff5cafa1f6ff12dd711ceea2931c69e7ac6980778eb040000006b483045022100a7aa7f41e3889c48599db2d91ce69968155ea3e0e4643d9ceb4dbc44da9da3b502204b0ed41fe0e0ec4a6459165e628f1269b63ae8e90309d340688a49d2d8d48b5d01210304ae97fe2acba599df9b523ec5219ae421cdae67657d57bd0c2c47c27dd42742ffffffff01c0799165010000001976a914785a5258008e272dd1a434eef745fb1277abeee688ac00000000 </pre>

    <pre> 26c929fe09c59f02d613a5d501eafaacd0f1eb6d5400a06c78fba10d57013db8 </pre>

  11. scmorse closed this on Mar 28, 2017

  12. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me