Introduce wrappers around CZCViewingKey
This commit is contained in:
parent
472f75bc2d
commit
8bf3a3d700
|
@ -379,6 +379,21 @@ boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string EncodeViewingKey(const libzcash::ViewingKey& vk)
|
||||||
|
{
|
||||||
|
return CZCViewingKey(vk).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::optional<libzcash::ViewingKey> DecodeViewingKey(const std::string& str)
|
||||||
|
{
|
||||||
|
CZCViewingKey vk(str);
|
||||||
|
try {
|
||||||
|
return vk.Get();
|
||||||
|
} catch (const std::runtime_error&) {
|
||||||
|
return boost::none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string EncodeSpendingKey(const libzcash::SpendingKey& zkey)
|
std::string EncodeSpendingKey(const libzcash::SpendingKey& zkey)
|
||||||
{
|
{
|
||||||
return CZCSpendingKey(zkey).ToString();
|
return CZCSpendingKey(zkey).ToString();
|
||||||
|
|
|
@ -182,6 +182,9 @@ bool IsValidDestinationString(const std::string& str, const CChainParams& params
|
||||||
std::string EncodePaymentAddress(const libzcash::PaymentAddress& zaddr);
|
std::string EncodePaymentAddress(const libzcash::PaymentAddress& zaddr);
|
||||||
boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string& str);
|
boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string& str);
|
||||||
|
|
||||||
|
std::string EncodeViewingKey(const libzcash::ViewingKey& vk);
|
||||||
|
boost::optional<libzcash::ViewingKey> DecodeViewingKey(const std::string& str);
|
||||||
|
|
||||||
std::string EncodeSpendingKey(const libzcash::SpendingKey& zkey);
|
std::string EncodeSpendingKey(const libzcash::SpendingKey& zkey);
|
||||||
boost::optional<libzcash::SpendingKey> DecodeSpendingKey(const std::string& str);
|
boost::optional<libzcash::SpendingKey> DecodeSpendingKey(const std::string& str);
|
||||||
|
|
||||||
|
|
|
@ -705,8 +705,11 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp)
|
||||||
}
|
}
|
||||||
|
|
||||||
string strVKey = params[0].get_str();
|
string strVKey = params[0].get_str();
|
||||||
CZCViewingKey viewingkey(strVKey);
|
auto viewingkey = DecodeViewingKey(strVKey);
|
||||||
auto vkey = viewingkey.Get();
|
if (!viewingkey) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid viewing key");
|
||||||
|
}
|
||||||
|
auto vkey = *viewingkey;
|
||||||
auto addr = vkey.address();
|
auto addr = vkey.address();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -815,6 +818,5 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
|
||||||
vk = k.viewing_key();
|
vk = k.viewing_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
CZCViewingKey viewingkey(vk);
|
return EncodeViewingKey(vk);
|
||||||
return viewingkey.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3067,12 +3067,10 @@ UniValue zc_raw_keygen(const UniValue& params, bool fHelp)
|
||||||
auto addr = k.address();
|
auto addr = k.address();
|
||||||
auto viewing_key = k.viewing_key();
|
auto viewing_key = k.viewing_key();
|
||||||
|
|
||||||
CZCViewingKey viewingkey(viewing_key);
|
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("zcaddress", EncodePaymentAddress(addr)));
|
result.push_back(Pair("zcaddress", EncodePaymentAddress(addr)));
|
||||||
result.push_back(Pair("zcsecretkey", EncodeSpendingKey(k)));
|
result.push_back(Pair("zcsecretkey", EncodeSpendingKey(k)));
|
||||||
result.push_back(Pair("zcviewingkey", viewingkey.ToString()));
|
result.push_back(Pair("zcviewingkey", EncodeViewingKey(viewing_key)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue