Skip to content

Commit

Permalink
add getblsctseed rpc command
Browse files Browse the repository at this point in the history
alex v committed Aug 7, 2024
1 parent b36390d commit b38cd7d
Showing 4 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/wallet/rpc/backup.cpp
Original file line number Diff line number Diff line change
@@ -688,6 +688,30 @@ RPCHelpMan dumpprivkey()
}


RPCHelpMan getblsctseed()
{
return RPCHelpMan{
"getblsctseed",
"\nDumps the BLSCT wallet seed, which can be used to reconstruct the wallet.\n"
"Note: This command is only compatible with BLSCT wallets.\n",
{},
RPCResult{
RPCResult::Type::STR, "seed", "The BLSCT wallet seed"},
RPCExamples{HelpExampleCli("getblsctseed", "") + HelpExampleRpc("getblsctseed", "")},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return UniValue::VNULL;

const CWallet& wallet = *pwallet;
const blsct::KeyMan& blsct_km = EnsureConstBlsctKeyMan(wallet);

auto seed = blsct_km.GetMasterSeedKey();

return seed.GetScalar().GetString();
},
};
}

RPCHelpMan dumpwallet()
{
return RPCHelpMan{"dumpwallet",
21 changes: 21 additions & 0 deletions src/wallet/rpc/util.cpp
Original file line number Diff line number Diff line change
@@ -131,6 +131,27 @@ const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wal
return *spk_man;
}

blsct::KeyMan& EnsureBlsctKeyMan(CWallet& wallet, bool also_create)
{
blsct::KeyMan* blsct_km = wallet.GetBLSCTKeyMan();
if (!blsct_km && also_create) {
blsct_km = wallet.GetOrCreateBLSCTKeyMan();
}
if (!blsct_km) {
throw JSONRPCError(RPC_WALLET_ERROR, "Only BLSCT wallets are supported by this command");
}
return *blsct_km;
}

const blsct::KeyMan& EnsureConstBlsctKeyMan(const CWallet& wallet)
{
const blsct::KeyMan* blsct_km = wallet.GetBLSCTKeyMan();
if (!blsct_km) {
throw JSONRPCError(RPC_WALLET_ERROR, "Only BLSCT wallets are supported by this command");
}
return *blsct_km;
}

std::string LabelFromValue(const UniValue& value)
{
static const std::string empty_string;
2 changes: 2 additions & 0 deletions src/wallet/rpc/util.h
Original file line number Diff line number Diff line change
@@ -41,7 +41,9 @@ bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string&

void EnsureWalletIsUnlocked(const CWallet&);
WalletContext& EnsureWalletContext(const std::any& context);
blsct::KeyMan& EnsureBlsctKeyMan(const CWallet& wallet, bool also_create = false);
LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan(CWallet& wallet, bool also_create = false);
const blsct::KeyMan& EnsureConstBlsctKeyMan(const CWallet& wallet);
const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wallet);

bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param);
2 changes: 2 additions & 0 deletions src/wallet/rpc/wallet.cpp
Original file line number Diff line number Diff line change
@@ -827,6 +827,7 @@ RPCHelpMan walletdisplayaddress();
#endif // ENABLE_EXTERNAL_SIGNER

// backup
RPCHelpMan getblsctseed();
RPCHelpMan dumpprivkey();
RPCHelpMan importprivkey();
RPCHelpMan importaddress();
@@ -905,6 +906,7 @@ Span<const CRPCCommand> GetWalletRPCCommands()
{"wallet", &getaddressesbylabel},
{"wallet", &getaddressinfo},
{"wallet", &getbalance},
{"wallet", &getblsctseed},
{"wallet", &getnewaddress},
{"wallet", &getrawchangeaddress},
{"wallet", &getreceivedbyaddress},

0 comments on commit b38cd7d

Please sign in to comment.