Skip to content

Commit dfcb26c

Browse files
committed
Merge #374: Port tweakfedpegscript from liquid-deamon
9bcfdd8 Port tweakfedpegscript from liquid (Mike)
2 parents c929443 + 9bcfdd8 commit dfcb26c

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

qa/rpc-tests/pegging.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,12 @@ def test_pegout(parent_chain_addr, sidechain):
201201

202202
sidechain.generate(101)
203203

204-
addrs = sidechain.getpeginaddress()
205-
txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24)
206-
# 10+2 confirms required to get into mempool and confirm
204+
getpeginaddr_res = sidechain.getpeginaddress()
205+
addr = getpeginaddr_res["mainchain_address"]
206+
claim_script = getpeginaddr_res["claim_script"]
207+
assert(addr == sidechain.tweakfedpegscript(claim_script)["address"])
208+
txid1 = bitcoin.sendtoaddress(addr, 24)
209+
207210
bitcoin.generate(1)
208211
time.sleep(2)
209212
proof = bitcoin.gettxoutproof([txid1])

src/rpc/misc.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
"\nReturns a tweaked fedpegscript.\n"
592+
"\nArguments:\n"
593+
"1. \"claim_script\" (string, required) Script to tweak the fedpegscript with. For example obtained as a result of getpeginaddress.\n"
594+
"\nResult:\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+
586618
static 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

603636
void RegisterMiscRPCCommands(CRPCTable &t)

0 commit comments

Comments
 (0)