btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.25k stars 2.37k forks source link

rpcclient: signrawtransaction method is deprecated in bitcoin core, but not updated in btcd #1722

Closed ghost closed 3 years ago

ghost commented 3 years ago

i modify signrawtransaction method in btcd to use signrawtransactionwithkey. please update it.

Roasbeef commented 3 years ago

The new command was added in this PR: https://github.com/btcsuite/btcd/pull/1642

btcd doesn't implement the new command, so we'll still keep it around for the rpcclient.

galileo-pkm commented 2 years ago

It seems that you missed the point: for bitcoind there are signrawtransactionwithkey and signrawtransactionwithwallet commands. Rpcclient library methods SignRawTransaction2,3 etc all use the depreciated signrawtransaction but should be using the new signrawtransactionwithkey. If you want to maintain the compatibility with bitcoind the easiest route is to update both the rpclient library and btcd.

Edit: Also the new (signrawtransactionwithkey) RPC method is slightly different. Old one:


1. "hexstring"     (string, required) The transaction hex string
2. "prevtxs"       (string, optional) An json array of previous dependent transaction outputs
     [               (json array of json objects, or 'null' if none provided)
       {
         "txid":"id",             (string, required) The transaction id
         "vout":n,                  (numeric, required) The output number
         "scriptPubKey": "hex",   (string, required) script key
         "redeemScript": "hex",   (string, required for P2SH or P2WSH) redeem script
         "amount": value            (numeric, required) The amount spent
       }
       ,...
    ]
3. "privkeys"     (string, optional) A json array of base58-encoded private keys for signing
    [                  (json array of strings, or 'null' if none provided)
      "privatekey"   (string) private key in base58-encoding
      ,...
    ]
4. "sighashtype"     (string, optional, default=ALL) The signature hash type. Must be one of
       "ALL"
       "NONE"
       "SINGLE"
       "ALL|ANYONECANPAY"
       "NONE|ANYONECANPAY"
       "SINGLE|ANYONECANPAY"

New one:

Arguments:
1. hexstring                        (string, required) The transaction hex string
2. privkeys                         (json array, required) The base58-encoded private keys for signing
     [
       "privatekey",                (string) private key in base58-encoding
       ...
     ]
3. prevtxs                          (json array, optional) The previous dependent transaction outputs
     [
       {                            (json object)
         "txid": "hex",             (string, required) The transaction id
         "vout": n,                 (numeric, required) The output number
         "scriptPubKey": "hex",     (string, required) script key
         "redeemScript": "hex",     (string) (required for P2SH) redeem script
         "witnessScript": "hex",    (string) (required for P2WSH or P2SH-P2WSH) witness script
         "amount": amount,          (numeric or string) (required for Segwit inputs) the amount spent
       },
       ...
     ]
4. sighashtype                      (string, optional, default="DEFAULT for Taproot, ALL otherwise") The signature hash type. Must be one of:
                                    "DEFAULT"
                                    "ALL"
                                    "NONE"
                                    "SINGLE"
                                    "ALL|ANYONECANPAY"
                                    "NONE|ANYONECANPAY"
                                    "SINGLE|ANYONECANPAY"

signrawtransaction has been deprecated since 0.17 (at least) so I have no idea how this went unnoticed.

Roasbeef commented 2 years ago

@galileo-pkm I think I understood the OP. If you'd like to add a new command for signrawtransactionwithkey then we'd review the PR. Generally we stopped keeping up in lock step w/ bitcoind since for example: we don't package a wallet within this project, so the commands are never used in line or tested in the project.

If you take a look at the way the RPC client works, it's relatively straight forward to add a new command externally: https://github.com/btcsuite/btcd/blob/v0.23.1/rpcclient/examples/customcommand/main.go

This gives projects everything they need to keep up with the bitcoind API changes/breakages they'd like to keep up with.

galileo-pkm commented 2 years ago

Thank you, I will take a look at the example provided.

galileo-pkm commented 2 years ago

PR submitted: https://github.com/btcsuite/btcd/pull/1885