mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Add getwalletpakinfo RPC call
This commit is contained in:
parent
f06e6f648e
commit
d391782cd9
2 changed files with 52 additions and 0 deletions
|
|
@ -1275,3 +1275,53 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
extern CTxDestination DeriveBitcoinOfflineAddress(const CExtPubKey& xpub, const uint32_t counter);
|
||||
|
||||
UniValue getwalletpakinfo(const JSONRPCRequest& request)
|
||||
{
|
||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||
CWallet* const pwallet = wallet.get();
|
||||
|
||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (request.fHelp || request.params.size() != 0)
|
||||
throw std::runtime_error(
|
||||
"getwalletpakinfo\n"
|
||||
"\nReturns relevant pegout authorization key (PAK) information about this wallet. Throws an error if initpegoutwallet` has not been invoked on this wallet.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
"\"derivation_path\" (string) The next index to be used by the wallet for `sendtomainchain`.\n"
|
||||
"\"bitcoin_xpub\" (string) The Bitcoin xpubkey loaded in the wallet for pegouts.\n"
|
||||
"\"liquid_pak\" (string) Pubkey in hex corresponding to the Liquid PAK loaded in the wallet for pegouts.\n"
|
||||
"\"liquid_pak_address\" (string) The corresponding address for `liquid_pak`. Useful for `dumpprivkey` for wallet backup or transfer.\n"
|
||||
"\"address_lookahead\"(array) The three next Bitcoin addresses the wallet will use for `sendtomainchain` based on the internal counter.\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwallet->cs_wallet);
|
||||
|
||||
if (pwallet->offline_counter == -1) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "This wallet has not been initialized for PAK-enforced peg-outs.");
|
||||
}
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
std::stringstream ss;
|
||||
ss << pwallet->offline_counter;
|
||||
ret.push_back(Pair("derivation_path", "/0/"+ss.str()));
|
||||
|
||||
CExtPubKey& xpub = pwallet->offline_xpub;
|
||||
|
||||
ret.pushKV("bitcoin_xpub", EncodeExtPubKey(xpub));
|
||||
ret.pushKV("liquid_pak", HexStr(pwallet->online_key));
|
||||
ret.pushKV("liquid_pak_address", EncodeDestination((pwallet->online_key.GetID())));
|
||||
|
||||
UniValue address_list(UniValue::VARR);
|
||||
for (unsigned int i = 0; i < 3; i++) {
|
||||
address_list.push_back(EncodeParentDestination(DeriveBitcoinOfflineAddress(xpub, pwallet->offline_counter+i)));
|
||||
}
|
||||
ret.push_back(Pair("address_lookahead", address_list));
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5648,6 +5648,7 @@ extern UniValue importprunedfunds(const JSONRPCRequest& request);
|
|||
extern UniValue removeprunedfunds(const JSONRPCRequest& request);
|
||||
extern UniValue importmulti(const JSONRPCRequest& request);
|
||||
extern UniValue rescanblockchain(const JSONRPCRequest& request);
|
||||
extern UniValue getwalletpakinfo(const JSONRPCRequest& request);
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
{ // category name actor (function) argNames
|
||||
|
|
@ -5708,6 +5709,7 @@ static const CRPCCommand commands[] =
|
|||
{ "wallet", "createrawpegin", &createrawpegin, {"bitcoin_tx", "txoutproof", "claim_script"} },
|
||||
{ "wallet", "sendtomainchain", &sendtomainchain, {"address", "amount", "subtractfeefromamount"} },
|
||||
{ "wallet", "initpegoutwallet", &initpegoutwallet, {"bitcoin_xpub", "bip32_counter", "liquid_pak"} },
|
||||
{ "wallet", "getwalletpakinfo", &getwalletpakinfo, {} },
|
||||
|
||||
|
||||
/** Account functions (deprecated) */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue