From 48e0a989c1101103df1986ba9acc033a0a455a51 Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 29 May 2025 02:39:58 -0400 Subject: [PATCH] Decode utf8 in opreturn and convert to hex --- src/wallet/rpcwallet.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 54a5310dd..1852db336 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5157,9 +5157,14 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) if(params.size() == 5) { opretValue = params[4].get_str(); + // Support a prefix "utf8:" which allows giving utf8 text instead of hex if(opretValue.get_str().substr(0,5) == "utf8:") { - // TODO: 1) remove the first 5 chars - // 2) convert remaining text to hex and store in opretValue + auto str = opretValue.get_str().substr(5); + if (utf8::is_valid(str)) { + opretValue = HexStr(str); + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid utf8 in opreturn"); + } } }