@@ -886,16 +886,41 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
886
886
EnsureWalletIsUnlocked ();
887
887
888
888
std::string strAddress = request.params [0 ].get_str ();
889
- CDynamicAddress address;
890
- if (!address.SetString (strAddress))
891
- throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid Dynamic address" );
892
- CKeyID keyID;
893
- if (!address.GetKeyID (keyID))
894
- throw JSONRPCError (RPC_TYPE_ERROR, " Address does not refer to a key" );
895
- CKey vchSecret;
896
- if (!pwalletMain->GetKey (keyID, vchSecret))
897
- throw JSONRPCError (RPC_WALLET_ERROR, " Private key for address " + strAddress + " is not known" );
898
- return CDynamicSecret (vchSecret).ToString ();
889
+ CTxDestination dest = DecodeDestination (strAddress);
890
+ if (!IsValidDestination (dest))
891
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid address " + strAddress);
892
+
893
+ if (dest.type () == typeid (CStealthAddress)) {
894
+ CStealthAddress sxAddr = boost::get<CStealthAddress>(dest);
895
+ if (!pwalletMain->GetStealthAddress (sxAddr.GetSpendKeyID (), sxAddr))
896
+ throw JSONRPCError (RPC_WALLET_ERROR, " Private key for address " + strAddress + " is not known" );
897
+
898
+ UniValue result (UniValue::VOBJ);
899
+
900
+ result.push_back (Pair (" scan_private_key" , CDynamicSecret (sxAddr.scan_secret ).ToString ()));
901
+
902
+ CKey vchSpendSecret;
903
+ if (!pwalletMain->GetKey (sxAddr.spend_secret_id , vchSpendSecret))
904
+ throw JSONRPCError (RPC_WALLET_ERROR, " Private key for spend address " + CDynamicAddress (sxAddr.spend_secret_id ).ToString () + " is not known" );
905
+
906
+ result.push_back (Pair (" spend_private_key" , CDynamicSecret (vchSpendSecret).ToString ()));
907
+ result.push_back (Pair (" prefix_number_bits" , (int )sxAddr.prefix .number_bits ));
908
+ result.push_back (Pair (" prefix_bitfield" , (int )sxAddr.prefix .bitfield ));
909
+
910
+ return result;
911
+ } else {
912
+ CDynamicAddress address;
913
+ if (!address.SetString (strAddress))
914
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid Dynamic address" );
915
+ CKeyID keyID;
916
+ if (!address.GetKeyID (keyID))
917
+ throw JSONRPCError (RPC_TYPE_ERROR, " Address does not refer to a key" );
918
+ CKey vchSecret;
919
+ if (!pwalletMain->GetKey (keyID, vchSecret))
920
+ throw JSONRPCError (RPC_WALLET_ERROR, " Private key for address " + strAddress + " is not known" );
921
+ return CDynamicSecret (vchSecret).ToString ();
922
+ }
923
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Unknown address type: " + strAddress + " Must be a standard or stealth address." );
899
924
}
900
925
901
926
UniValue dumpbdapkeys (const JSONRPCRequest& request)
0 commit comments