Support using non-hex utf8 strings with z_sendmany memo

This commit is contained in:
Duke
2025-05-29 15:40:07 -04:00
parent cc1c0b30b0
commit a520a3e655

View File

@@ -5209,8 +5209,16 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
memo = memoValue.get_str();
if (!isZaddr) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo cannot be used with a taddr. It can only be used with a zaddr.");
} else if(memo.substr(0,5) == "utf8:") {
// Support a prefix "utf8:" which allows giving utf8 text instead of hex
auto str = memo.substr(5);
if (utf8::is_valid(str)) {
memo = HexStr(str);
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid utf8 in memo");
}
} else if (!IsHex(memo)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected memo data in hexadecimal format.");
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected memo data in hexadecimal format or to use 'utf8:' prefix.");
}
if (memo.length() > HUSH_MEMO_SIZE*2) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, size of memo is larger than maximum allowed %d", HUSH_MEMO_SIZE ));