mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
rpc: simplify addpeeraddress and improve code constness
This commit is contained in:
parent
6b1926cf1e
commit
b36e0cd1b9
1 changed files with 12 additions and 16 deletions
|
@ -931,26 +931,22 @@ static RPCHelpMan addpeeraddress()
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& addr_string{request.params[0].get_str()};
|
||||||
|
const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
|
|
||||||
std::string addr_string = request.params[0].get_str();
|
|
||||||
uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
|
|
||||||
|
|
||||||
CNetAddr net_addr;
|
CNetAddr net_addr;
|
||||||
if (!LookupHost(addr_string, net_addr, false)) {
|
bool success{false};
|
||||||
obj.pushKV("success", false);
|
|
||||||
return obj;
|
if (LookupHost(addr_string, net_addr, false)) {
|
||||||
}
|
CAddress address{CAddress({net_addr, port}, ServiceFlags(NODE_NETWORK | NODE_WITNESS))};
|
||||||
CAddress address = CAddress({net_addr, port}, ServiceFlags(NODE_NETWORK|NODE_WITNESS));
|
address.nTime = GetAdjustedTime();
|
||||||
address.nTime = GetAdjustedTime();
|
// The source address is set equal to the address. This is equivalent to the peer
|
||||||
// The source address is set equal to the address. This is equivalent to the peer
|
// announcing itself.
|
||||||
// announcing itself.
|
if (node.addrman->Add(address, address)) success = true;
|
||||||
if (!node.addrman->Add(address, address)) {
|
|
||||||
obj.pushKV("success", false);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.pushKV("success", true);
|
obj.pushKV("success", success);
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue