diff options
author | Jeff Garzik <jgarzik@bitpay.com> | 2013-08-28 16:29:52 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@bitpay.com> | 2013-08-28 16:29:52 -0400 |
commit | e5e9904c1c87fcdddf01e563ffe28cc56aea4f29 (patch) | |
tree | 30c0cc52e398b3c2899ff9e6b914e7337b7ad2b5 /src | |
parent | bb7d0fc12fcfbb2a91e39cb49f2a0873344dbae0 (diff) |
RPC: add getrawchangeaddress, for raw transaction change destinations
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 1 | ||||
-rw-r--r-- | src/bitcoinrpc.h | 1 | ||||
-rw-r--r-- | src/rpcwallet.cpp | 23 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index d22809ce69..47c7383564 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -208,6 +208,7 @@ static const CRPCCommand vRPCCommands[] = { "getmininginfo", &getmininginfo, true, false }, { "getnewaddress", &getnewaddress, true, false }, { "getaccountaddress", &getaccountaddress, true, false }, + { "getrawchangeaddress", &getrawchangeaddress, true, false }, { "setaccount", &setaccount, true, false }, { "getaccount", &getaccount, false, false }, { "getaddressesbyaccount", &getaddressesbyaccount, true, false }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 4d5599be84..1aa2e70d26 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -161,6 +161,7 @@ extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHe extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getrawchangeaddress(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index d07d3408b9..978c44e1a9 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -176,6 +176,29 @@ Value getaccountaddress(const Array& params, bool fHelp) } +Value getrawchangeaddress(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "getrawchangeaddress\n" + "Returns a new Bitcoin address, for receiving change. " + "This is for use with raw transactions, NOT normal use."); + + if (!pwalletMain->IsLocked()) + pwalletMain->TopUpKeyPool(); + + CReserveKey reservekey(pwalletMain); + CPubKey vchPubKey; + if (!reservekey.GetReservedKey(vchPubKey)) + throw JSONRPCError(RPC_WALLET_ERROR, "Error: Unable to obtain key for change"); + + reservekey.KeepKey(); + + CKeyID keyID = vchPubKey.GetID(); + + return CBitcoinAddress(keyID).ToString(); +} + Value setaccount(const Array& params, bool fHelp) { |