Skip to content

Commit 079d8cd

Browse files
committed
rpc: extract wallet "warnings" fields to a util helper
1 parent f73782a commit 079d8cd

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/rpc/output_script.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static RPCHelpMan createmultisig()
162162
// Only warns if the user has explicitly chosen an address type we cannot generate
163163
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
164164
}
165-
if (!warnings.empty()) result.pushKV("warnings", warnings);
165+
PushWarnings(warnings, result);
166166

167167
return result;
168168
},

src/rpc/util.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,3 +1174,9 @@ UniValue GetServicesNames(ServiceFlags services)
11741174

11751175
return servicesNames;
11761176
}
1177+
1178+
void PushWarnings(const UniValue& warnings, UniValue& obj)
1179+
{
1180+
if (warnings.empty()) return;
1181+
obj.pushKV("warnings", warnings);
1182+
}

src/rpc/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,12 @@ class RPCHelpMan
381381
const RPCExamples m_examples;
382382
};
383383

384+
/**
385+
* Push warning messages to an RPC "warnings" field as a JSON array of strings.
386+
*
387+
* @param[in] warnings Warning messages to push.
388+
* @param[out] obj UniValue object to push the warnings array object to.
389+
*/
390+
void PushWarnings(const UniValue& warnings, UniValue& obj);
391+
384392
#endif // BITCOIN_RPC_UTIL_H

src/wallet/rpc/addresses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ RPCHelpMan addmultisigaddress()
300300
// Only warns if the user has explicitly chosen an address type we cannot generate
301301
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
302302
}
303-
if (!warnings.empty()) result.pushKV("warnings", warnings);
303+
PushWarnings(warnings, result);
304304

305305
return result;
306306
},

src/wallet/rpc/backup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ static UniValue ProcessImport(CWallet& wallet, const UniValue& data, const int64
12251225

12261226
result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, "Missing required fields"));
12271227
}
1228-
if (warnings.size()) result.pushKV("warnings", warnings);
1228+
PushWarnings(warnings, result);
12291229
return result;
12301230
}
12311231

@@ -1579,7 +1579,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
15791579
result.pushKV("success", UniValue(false));
15801580
result.pushKV("error", e);
15811581
}
1582-
if (warnings.size()) result.pushKV("warnings", warnings);
1582+
PushWarnings(warnings, result);
15831583
return result;
15841584
}
15851585

0 commit comments

Comments
 (0)