MCPcopy Create free account
hub / github.com/ElementsProject/elements / getwalletpakinfo

Function getwalletpakinfo

src/wallet/rpc/backup.cpp:1961–2047  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1959// ELEMENTS:
1960
1961RPCHelpMan getwalletpakinfo()
1962{
1963 return RPCHelpMan{"getwalletpakinfo",
1964 "\nReturns relevant pegout authorization key (PAK) information about this wallet. Throws an error if initpegoutwallet` has not been invoked on this wallet.\n",
1965 {},
1966 RPCResult{
1967 RPCResult::Type::OBJ, "", "",
1968 {
1969 {RPCResult::Type::STR, "bip32_counter", "next index to be used by the wallet for `sendtomainchain`"},
1970 {RPCResult::Type::STR, "bitcoin_descriptor", "Bitcoin script descriptor loaded in the wallet for pegouts"},
1971 {RPCResult::Type::STR, "pakentry", "PAK entry to be used at network initialization time in the form of: `pak=<bitcoin_pak>:<liquid_pak>`"},
1972 {RPCResult::Type::STR_HEX, "liquid_pak", "pubkey corresponding to the Liquid PAK loaded in the wallet for pegouts"},
1973 {RPCResult::Type::STR, "liquid_pak_address", "corresponding address for `liquid_pak`. Useful for `dumpprivkey` for wallet backup or transfer"},
1974 {RPCResult::Type::ARR_FIXED, "address_lookahead", "the three next Bitcoin addresses the wallet will use for `sendtomainchain` based on the internal counter",
1975 {RPCResult{RPCResult::Type::STR, "", ""}}},
1976 }
1977 },
1978 RPCExamples{""},
1979 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1980{
1981
1982 std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
1983 if (!wallet) return NullUniValue;
1984 CWallet* const pwallet = wallet.get();
1985
1986 LOCK(pwallet->cs_wallet);
1987
1988 if (pwallet->offline_counter == -1) {
1989 throw JSONRPCError(RPC_MISC_ERROR, "This wallet has not been initialized for PAK-enforced peg-outs.");
1990 }
1991
1992 UniValue ret(UniValue::VOBJ);
1993 std::stringstream ss;
1994 ss << pwallet->offline_counter;
1995 ret.pushKV("bip32_counter", ss.str());
1996
1997 const std::string desc_str = pwallet->offline_desc;
1998
1999 FlatSigningProvider provider;
2000 std::string error;
2001 const auto& desc = Parse(desc_str, provider, error);
2002
2003 ret.pushKV("bitcoin_descriptor", desc_str);
2004 {
2005 CPubKey masterpub = pwallet->offline_xpub.pubkey;
2006 secp256k1_pubkey masterpub_secp;
2007 int secp256k1_ret = secp256k1_ec_pubkey_parse(secp256k1_ctx, &masterpub_secp, masterpub.begin(), masterpub.size());
2008 if (secp256k1_ret != 1) {
2009 throw JSONRPCError(RPC_WALLET_ERROR, "bitcoin_descriptor could not be parsed.");
2010 }
2011
2012
2013 // Negate the pubkey
2014 secp256k1_ret = secp256k1_ec_pubkey_negate(secp256k1_ctx, &masterpub_secp);
2015
2016 std::vector<unsigned char> negatedpubkeybytes;
2017 negatedpubkeybytes.resize(33);
2018 size_t len = 33;

Callers

nothing calls this directly

Calls 15

JSONRPCErrorFunction · 0.85
ParseFunction · 0.85
EncodeDestinationFunction · 0.85
PKHashClass · 0.85
ExtractDestinationFunction · 0.85
EncodeParentDestinationFunction · 0.85
strMethod · 0.80
ExpandMethod · 0.80

Tested by

no test coverage detected