From e5e9904c1c87fcdddf01e563ffe28cc56aea4f29 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Wed, 28 Aug 2013 16:29:52 -0400 Subject: RPC: add getrawchangeaddress, for raw transaction change destinations --- src/rpcwallet.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/rpcwallet.cpp') 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) { -- cgit v1.2.3