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

Function sendtomainchain_base

src/wallet/rpc/elements.cpp:432–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432RPCHelpMan sendtomainchain_base()
433{
434 return RPCHelpMan{"sendtomainchain",
435 "\nSends sidechain funds to the given mainchain address, through the federated pegin mechanism\n"
436 + wallet::HELP_REQUIRING_PASSPHRASE,
437 {
438 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The destination address on Bitcoin mainchain"},
439 {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount being sent to Bitcoin mainchain"},
440 {"subtractfeefromamount", RPCArg::Type::BOOL, RPCArg::Default{false}, "The fee will be deducted from the amount being pegged-out."},
441 {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, return extra information about the transaction."},
442 },
443 {
444 RPCResult{"if verbose is not set or set to false",
445 RPCResult::Type::STR_HEX, "txid", "Transaction ID of the resulting sidechain transaction",
446 },
447 RPCResult{"if verbose is set to true",
448 RPCResult::Type::OBJ, "", "",
449 {
450 {RPCResult::Type::STR_HEX, "txid", "The transaction id."},
451 {RPCResult::Type::STR, "fee reason", "The transaction fee reason."}
452 },
453 },
454 },
455 RPCExamples{
456 HelpExampleCli("sendtomainchain", "\"mgWEy4vBJSHt3mC8C2SEWJQitifb4qeZQq\" 0.1")
457 + HelpExampleRpc("sendtomainchain", "\"mgWEy4vBJSHt3mC8C2SEWJQitifb4qeZQq\" 0.1")
458 },
459 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
460{
461 std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
462 if (!pwallet) return NullUniValue;
463
464 LOCK(pwallet->cs_wallet);
465
466 EnsureWalletIsUnlocked(*pwallet);
467
468 std::string error_str;
469 CTxDestination parent_address = DecodeParentDestination(request.params[0].get_str(), error_str);
470 if (!IsValidDestination(parent_address))
471 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid Bitcoin address: %s", error_str));
472
473 CAmount nAmount = AmountFromValue(request.params[1]);
474 if (nAmount <= 0)
475 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
476
477 bool subtract_fee = false;
478 if (request.params.size() > 2) {
479 subtract_fee = request.params[2].get_bool();
480 }
481
482 // Parse Bitcoin address for destination, embed script
483 CScript mainchain_script(GetScriptForDestination(parent_address));
484
485 uint256 genesisBlockHash = Params().ParentGenesisBlockHash();
486
487 // Asset type is implicit, no need to add to script
488 NullData nulldata;
489 nulldata << std::vector<unsigned char>(genesisBlockHash.begin(), genesisBlockHash.end());

Callers 1

sendtomainchainFunction · 0.85

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
DecodeParentDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
JSONRPCErrorFunction · 0.85
GetScriptForDestinationFunction · 0.85
SendMoneyFunction · 0.85
get_boolMethod · 0.80
AmountFromValueFunction · 0.50
ParamsClass · 0.50

Tested by

no test coverage detected