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

Function sendtomainchain_pak

src/wallet/rpc/elements.cpp:547–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

545////////////////////////////
546
547RPCHelpMan sendtomainchain_pak()
548{
549 return RPCHelpMan{"sendtomainchain",
550 "\nSends Liquid funds to the Bitcoin mainchain, through the federated withdraw mechanism. The wallet internally generates the returned `bitcoin_address` via `bitcoin_descriptor` and `bip32_counter` previously set in `initpegoutwallet`. The counter will be incremented upon successful send, avoiding address re-use.\n"
551 + wallet::HELP_REQUIRING_PASSPHRASE,
552 {
553 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "Must be \"\". Only for non-PAK `sendtomainchain` compatibility."},
554 {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount being sent to `bitcoin_address`."},
555 {"subtractfeefromamount", RPCArg::Type::BOOL, RPCArg::Default{false}, "The fee will be deducted from the amount being pegged-out."},
556 {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, return extra information about the transaction."},
557 },
558 RPCResult{
559 RPCResult::Type::OBJ, "", "",
560 {
561 {RPCResult::Type::STR, "bitcoin_address", "destination address on Bitcoin mainchain"},
562 {RPCResult::Type::STR_HEX, "txid", "transaction ID of the resulting Liquid transaction"},
563 {RPCResult::Type::STR, "fee reason", "If verbose is set to true, the Liquid transaction fee reason"},
564 {RPCResult::Type::STR, "bitcoin_descriptor", "xpubkey of the child destination address"},
565 {RPCResult::Type::STR, "bip32_counter", "derivation counter for the `bitcoin_descriptor`"},
566 },
567 },
568 RPCExamples{
569 HelpExampleCli("sendtomainchain", "\"\" 0.1")
570 + HelpExampleRpc("sendtomainchain", "\"\" 0.1")
571 },
572 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
573{
574 std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
575 if (!pwallet) return NullUniValue;
576
577 LOCK(pwallet->cs_wallet);
578
579 EnsureWalletIsUnlocked(*pwallet);
580
581 if (!request.params[0].get_str().empty()) {
582 throw JSONRPCError(RPC_TYPE_ERROR, "`address` argument must be \"\" for PAK-enabled networks as the address is generated automatically.");
583 }
584
585 //amount
586 CAmount nAmount = AmountFromValue(request.params[1]);
587 if (nAmount < 100000)
588 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount for send, must send more than 0.00100000 BTC");
589
590 bool subtract_fee = false;
591 if (request.params.size() > 2) {
592 subtract_fee = request.params[2].get_bool();
593 }
594
595 CPAKList paklist = GetActivePAKList(pwallet->chain().getTip(), Params().GetConsensus());
596 if (paklist.IsReject()) {
597 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pegout freeze is under effect to aid a pak transition to a new list. Please consult the network operator.");
598 }
599
600 // Fetch pegout key data
601 int counter = pwallet->offline_counter;
602 CExtPubKey& xpub = pwallet->offline_xpub;
603 CPubKey& onlinepubkey = pwallet->online_key;
604

Callers 1

sendtomainchainFunction · 0.85

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
JSONRPCErrorFunction · 0.85
GetActivePAKListFunction · 0.85
ParseFunction · 0.85
EncodeExtPubKeyFunction · 0.85
DerivePubTweakFunction · 0.85

Tested by

no test coverage detected