@@ -583,6 +583,38 @@ UniValue echo(const JSONRPCRequest& request)
583583 return request.params ;
584584}
585585
586+ UniValue tweakfedpegscript (const JSONRPCRequest& request)
587+ {
588+ if (request.fHelp || request.params .size () != 1 )
589+ throw runtime_error (
590+ " tweakfedpegscript \" claim_script\"\n "
591+ " \n Returns a tweaked fedpegscript.\n "
592+ " \n Arguments:\n "
593+ " 1. \" claim_script\" (string, required) Script to tweak the fedpegscript with. For example obtained as a result of getpeginaddress.\n "
594+ " \n Result:\n "
595+ " {\n "
596+ " \" script\" (string) The fedpegscript tweaked with claim_script\n "
597+ " \" address\" (string) The address corresponding to the tweaked fedpegscript\n "
598+ " }\n "
599+ );
600+
601+
602+ if (!IsHex (request.params [0 ].get_str ())) {
603+ throw JSONRPCError (RPC_TYPE_ERROR, " the first argument must be a hex string" );
604+ }
605+
606+ std::vector<unsigned char > scriptData = ParseHex (request.params [0 ].get_str ());
607+ CScript claim_script = CScript (scriptData.begin (), scriptData.end ());
608+ CScript tweaked_script = calculate_contract (Params ().GetConsensus ().fedpegScript , claim_script);
609+ CParentBitcoinAddress addr (CScriptID (GetScriptForWitness (tweaked_script)));
610+
611+ UniValue ret (UniValue::VOBJ);
612+ ret.pushKV (" script" , HexStr (tweaked_script));
613+ ret.pushKV (" address" , addr.ToString ());
614+
615+ return ret;
616+ }
617+
586618static const CRPCCommand commands[] =
587619{ // category name actor (function) okSafeMode
588620 // --------------------- ------------------------ ----------------------- ----------
@@ -593,11 +625,12 @@ static const CRPCCommand commands[] =
593625 { " util" , " createblindedaddress" , &createblindedaddress, true , {} },
594626 { " util" , " verifymessage" , &verifymessage, true , {" address" ," signature" ," message" } },
595627 { " util" , " signmessagewithprivkey" , &signmessagewithprivkey, true , {" privkey" ," message" } },
628+ { " util" , " tweakfedpegscript" , &tweakfedpegscript, true , {" claim_script" } },
596629
597630 /* Not shown in help */
598631 { " hidden" , " setmocktime" , &setmocktime, true , {" timestamp" }},
599632 { " hidden" , " echo" , &echo, true , {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
600- { " hidden" , " echojson" , &echo, true , {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
633+ { " hidden" , " echojson" , &echo, true , {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
601634};
602635
603636void RegisterMiscRPCCommands (CRPCTable &t)
0 commit comments