mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
external_signer: use const where appropriate
This commit is contained in:
@@ -14,14 +14,14 @@
|
|||||||
|
|
||||||
#ifdef ENABLE_EXTERNAL_SIGNER
|
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||||
|
|
||||||
ExternalSigner::ExternalSigner(const std::string& command, const std::string& fingerprint, std::string chain, std::string name): m_command(command), m_fingerprint(fingerprint), m_chain(chain), m_name(name) {}
|
ExternalSigner::ExternalSigner(const std::string& command, const std::string& fingerprint, const std::string chain, const std::string name): m_command(command), m_fingerprint(fingerprint), m_chain(chain), m_name(name) {}
|
||||||
|
|
||||||
const std::string ExternalSigner::NetworkArg() const
|
const std::string ExternalSigner::NetworkArg() const
|
||||||
{
|
{
|
||||||
return " --chain " + m_chain;
|
return " --chain " + m_chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, std::string chain)
|
bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string chain)
|
||||||
{
|
{
|
||||||
// Call <command> enumerate
|
// Call <command> enumerate
|
||||||
const UniValue result = RunCommandParseJSON(command + " enumerate");
|
const UniValue result = RunCommandParseJSON(command + " enumerate");
|
||||||
@@ -42,10 +42,10 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
|
|||||||
if (fingerprint.isNull()) {
|
if (fingerprint.isNull()) {
|
||||||
throw ExternalSignerException(strprintf("'%s' received invalid response, missing signer fingerprint", command));
|
throw ExternalSignerException(strprintf("'%s' received invalid response, missing signer fingerprint", command));
|
||||||
}
|
}
|
||||||
std::string fingerprintStr = fingerprint.get_str();
|
const std::string fingerprintStr = fingerprint.get_str();
|
||||||
// Skip duplicate signer
|
// Skip duplicate signer
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
for (ExternalSigner signer : signers) {
|
for (const ExternalSigner& signer : signers) {
|
||||||
if (signer.m_fingerprint.compare(fingerprintStr) == 0) duplicate = true;
|
if (signer.m_fingerprint.compare(fingerprintStr) == 0) duplicate = true;
|
||||||
}
|
}
|
||||||
if (duplicate) break;
|
if (duplicate) break;
|
||||||
@@ -64,7 +64,7 @@ UniValue ExternalSigner::DisplayAddress(const std::string& descriptor) const
|
|||||||
return RunCommandParseJSON(m_command + " --fingerprint \"" + m_fingerprint + "\"" + NetworkArg() + " displayaddress --desc \"" + descriptor + "\"");
|
return RunCommandParseJSON(m_command + " --fingerprint \"" + m_fingerprint + "\"" + NetworkArg() + " displayaddress --desc \"" + descriptor + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue ExternalSigner::GetDescriptors(int account)
|
UniValue ExternalSigner::GetDescriptors(const int account)
|
||||||
{
|
{
|
||||||
return RunCommandParseJSON(m_command + " --fingerprint \"" + m_fingerprint + "\"" + NetworkArg() + " getdescriptors --account " + strprintf("%d", account));
|
return RunCommandParseJSON(m_command + " --fingerprint \"" + m_fingerprint + "\"" + NetworkArg() + " getdescriptors --account " + strprintf("%d", account));
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
|
|||||||
bool match = false;
|
bool match = false;
|
||||||
for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
|
for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
|
||||||
const PSBTInput& input = psbtx.inputs[i];
|
const PSBTInput& input = psbtx.inputs[i];
|
||||||
for (auto entry : input.hd_keypaths) {
|
for (const auto& entry : input.hd_keypaths) {
|
||||||
if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) match = true;
|
if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) match = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,8 +89,8 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string command = m_command + " --stdin --fingerprint \"" + m_fingerprint + "\"" + NetworkArg();
|
const std::string command = m_command + " --stdin --fingerprint \"" + m_fingerprint + "\"" + NetworkArg();
|
||||||
std::string stdinStr = "signtx \"" + EncodeBase64(ssTx.str()) + "\"";
|
const std::string stdinStr = "signtx \"" + EncodeBase64(ssTx.str()) + "\"";
|
||||||
|
|
||||||
const UniValue signer_result = RunCommandParseJSON(command, stdinStr);
|
const UniValue signer_result = RunCommandParseJSON(command, stdinStr);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
//! @param[in] fingerprint master key fingerprint of the signer
|
//! @param[in] fingerprint master key fingerprint of the signer
|
||||||
//! @param[in] chain "main", "test", "regtest" or "signet"
|
//! @param[in] chain "main", "test", "regtest" or "signet"
|
||||||
//! @param[in] name device name
|
//! @param[in] name device name
|
||||||
ExternalSigner(const std::string& command, const std::string& fingerprint, std::string chain, std::string name);
|
ExternalSigner(const std::string& command, const std::string& fingerprint, const std::string chain, const std::string name);
|
||||||
|
|
||||||
//! Master key fingerprint of the signer
|
//! Master key fingerprint of the signer
|
||||||
std::string m_fingerprint;
|
std::string m_fingerprint;
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
//! @param[in,out] signers vector to which new signers (with a unique master key fingerprint) are added
|
//! @param[in,out] signers vector to which new signers (with a unique master key fingerprint) are added
|
||||||
//! @param chain "main", "test", "regtest" or "signet"
|
//! @param chain "main", "test", "regtest" or "signet"
|
||||||
//! @returns success
|
//! @returns success
|
||||||
static bool Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, std::string chain);
|
static bool Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string chain);
|
||||||
|
|
||||||
//! Display address on the device. Calls `<command> displayaddress --desc <descriptor>`.
|
//! Display address on the device. Calls `<command> displayaddress --desc <descriptor>`.
|
||||||
//! @param[in] descriptor Descriptor specifying which address to display.
|
//! @param[in] descriptor Descriptor specifying which address to display.
|
||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
//! Calls `<command> getdescriptors --account <account>`
|
//! Calls `<command> getdescriptors --account <account>`
|
||||||
//! @param[in] account which BIP32 account to use (e.g. `m/44'/0'/account'`)
|
//! @param[in] account which BIP32 account to use (e.g. `m/44'/0'/account'`)
|
||||||
//! @returns see doc/external-signer.md
|
//! @returns see doc/external-signer.md
|
||||||
UniValue GetDescriptors(int account);
|
UniValue GetDescriptors(const int account);
|
||||||
|
|
||||||
//! Sign PartiallySignedTransaction on the device.
|
//! Sign PartiallySignedTransaction on the device.
|
||||||
//! Calls `<command> signtransaction` and passes the PSBT via stdin.
|
//! Calls `<command> signtransaction` and passes the PSBT via stdin.
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ static RPCHelpMan enumeratesigners()
|
|||||||
{
|
{
|
||||||
const std::string command = gArgs.GetArg("-signer", "");
|
const std::string command = gArgs.GetArg("-signer", "");
|
||||||
if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>");
|
if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>");
|
||||||
std::string chain = gArgs.GetChainName();
|
const std::string chain = gArgs.GetChainName();
|
||||||
UniValue signers_res = UniValue::VARR;
|
UniValue signers_res = UniValue::VARR;
|
||||||
try {
|
try {
|
||||||
std::vector<ExternalSigner> signers;
|
std::vector<ExternalSigner> signers;
|
||||||
ExternalSigner::Enumerate(command, signers, chain);
|
ExternalSigner::Enumerate(command, signers, chain);
|
||||||
for (ExternalSigner signer : signers) {
|
for (const ExternalSigner& signer : signers) {
|
||||||
UniValue signer_res = UniValue::VOBJ;
|
UniValue signer_res = UniValue::VOBJ;
|
||||||
signer_res.pushKV("fingerprint", signer.m_fingerprint);
|
signer_res.pushKV("fingerprint", signer.m_fingerprint);
|
||||||
signer_res.pushKV("name", signer.m_name);
|
signer_res.pushKV("name", signer.m_name);
|
||||||
|
|||||||
Reference in New Issue
Block a user