| 840 | // ELEMENTS CALLS |
| 841 | |
| 842 | static RPCHelpMan tweakfedpegscript() |
| 843 | { |
| 844 | return RPCHelpMan{"tweakfedpegscript", |
| 845 | "\nReturns a tweaked fedpegscript.\n", |
| 846 | { |
| 847 | {"claim_script", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "Script to tweak the fedpegscript with. For example obtained as a result of getpeginaddress."}, |
| 848 | {"fedpegscript", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "Fedpegscript to be used with the claim_script. By default this is the current fedpegscript."}, |
| 849 | }, |
| 850 | RPCResult{ |
| 851 | RPCResult::Type::OBJ, "", "", |
| 852 | { |
| 853 | {RPCResult::Type::STR_HEX, "script", "The fedpegscript tweaked with claim_script"}, |
| 854 | {RPCResult::Type::STR, "address", "The address corresponding to the tweaked fedpegscript"}, |
| 855 | } |
| 856 | }, |
| 857 | RPCExamples{""}, |
| 858 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 859 | { |
| 860 | if (!IsHex(request.params[0].get_str())) { |
| 861 | throw JSONRPCError(RPC_TYPE_ERROR, "the first argument must be a hex string"); |
| 862 | } |
| 863 | |
| 864 | ChainstateManager& chainman = EnsureAnyChainman(request.context); |
| 865 | CScript fedpegscript = GetValidFedpegScripts(chainman.ActiveChain().Tip(), Params().GetConsensus(), true /* nextblock_validation */).front().second; |
| 866 | |
| 867 | if (!request.params[1].isNull()) { |
| 868 | if (IsHex(request.params[1].get_str())) { |
| 869 | std::vector<unsigned char> fedpeg_byte = ParseHex(request.params[1].get_str()); |
| 870 | fedpegscript = CScript(fedpeg_byte.begin(), fedpeg_byte.end()); |
| 871 | } else { |
| 872 | throw JSONRPCError(RPC_TYPE_ERROR, "fedpegscript must be a hex string"); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | std::vector<unsigned char> scriptData = ParseHex(request.params[0].get_str()); |
| 877 | CScript claim_script = CScript(scriptData.begin(), scriptData.end()); |
| 878 | |
| 879 | CScript tweaked_script = calculate_contract(fedpegscript, claim_script); |
| 880 | CScript redeem_script = GetScriptForDestination(WitnessV0ScriptHash(tweaked_script)); |
| 881 | CTxDestination p2wsh{WitnessV0ScriptHash(tweaked_script)}; |
| 882 | CTxDestination p2shwsh{ScriptHash(GetScriptForDestination(p2wsh))}; |
| 883 | |
| 884 | UniValue ret(UniValue::VOBJ); |
| 885 | ret.pushKV("script", HexStr(tweaked_script)); |
| 886 | ret.pushKV("p2wsh", EncodeParentDestination(p2wsh)); |
| 887 | ret.pushKV("p2shwsh", EncodeParentDestination(p2shwsh)); |
| 888 | |
| 889 | return ret; |
| 890 | }, |
| 891 | }; |
| 892 | } |
| 893 | |
| 894 | UniValue FormatPAKList(CPAKList &paklist) { |
| 895 | UniValue paklist_value(UniValue::VOBJ); |
nothing calls this directly
no test coverage detected