Skip to content

Commit 57b252e

Browse files
committed
[Modularization] use pointers when adding or replacing RPC commands
Using pointers signals the responsibility of managing object lifetime is in the hand of the caller.
1 parent bbee2eb commit 57b252e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/rpcserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,10 @@ const CRPCCommand *CRPCTable::operator[](string name) const
398398
return (*it).second;
399399
}
400400

401-
void CRPCTable::AddOrReplaceCommand(const CRPCCommand command)
401+
void CRPCTable::AddOrReplaceCommand(const CRPCCommand* pcommand)
402402
{
403403
// add new command to the dispatch table
404-
mapCommands[command.name] = &command;
404+
mapCommands[pcommand->name] = pcommand;
405405
}
406406

407407
bool HTTPAuthorized(map<string, string>& mapHeaders)

src/rpcserver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ class CRPCTable
114114
std::string help(std::string name) const;
115115

116116
/**
117-
* add or replace a CRPCCommand to the dispatch table
118-
* @param command rpc command to add or replace
119-
*/
120-
void AddOrReplaceCommand(const CRPCCommand command);
117+
* Add or replace a CRPCCommand to the dispatch table
118+
* @param pcommand RPC command to add or replace
119+
*/
120+
void AddOrReplaceCommand(const CRPCCommand* pcommand);
121121

122122
/**
123123
* Execute a method.

src/test/rpc_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ BOOST_AUTO_TEST_CASE(rpc_flex_table)
166166
{
167167
Value r = CallRPC(string("ping"));
168168
BOOST_CHECK(r.is_null());
169-
170-
const CRPCCommand newCmd = { "network","testcmd", &ping_overwrite_tests,true,false };
171-
tableRPC.AddOrReplaceCommand(newCmd);
172-
169+
170+
const CRPCCommand newCmd = { "network", "testcmd", &ping_overwrite_tests, true, false };
171+
tableRPC.AddOrReplaceCommand(&newCmd);
172+
173173
BOOST_CHECK_NO_THROW(r = CallRPC(string("testcmd")));
174174
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "Test").get_str(), "123");
175-
176-
const CRPCCommand newPingCmd = { "network","ping", &ping_overwrite_tests,true,false };
177-
tableRPC.AddOrReplaceCommand(newPingCmd);
178-
175+
176+
const CRPCCommand newPingCmd = { "network", "ping", &ping_overwrite_tests, true, false };
177+
tableRPC.AddOrReplaceCommand(&newPingCmd);
178+
179179
BOOST_CHECK_NO_THROW(r = CallRPC(string("ping")));
180180
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "Test").get_str(), "123");
181181
}

0 commit comments

Comments
 (0)