Skip to content

Commit

Permalink
Merge pull request ElementsProject#16 from maaku/insertscriptsig-rpc
Browse files Browse the repository at this point in the history
Insertscriptsig rpc
  • Loading branch information
kallewoof authored Jul 31, 2017
2 parents 69a4614 + 85ccce4 commit 0945d38
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "blindrawtransaction", 2, "ignoreblindfail" },
{ "createrawtransaction", 0, "inputs" },
{ "createrawtransaction", 1, "outputs" },
{ "insertscriptsig", 1, "tx" },
{ "insertscriptsig", 1, "index" },
{ "insertscriptsig", 1, "script" },
{ "dumpissuanceblindingkey", 1, "vin" },
{ "importissuanceblindingkey", 1, "vin" },
{ "createrawtransaction", 2, "locktime" },
Expand Down
45 changes: 45 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,50 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
return EncodeHexTx(rawTx);
}

UniValue insertscriptsig(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 3)
throw runtime_error(
"insertscriptsig \"tx\" index \"scriptSig\"\n"

"\nReplaces the scriptSig of the specified input with the serialized string. "
"Fails if scriptWitness is not-null.\n"

"\nArguments:\n"
"1. \"tx\" (string, required) The hex string of the raw transaction.\n"
"2. index (integer, required) The position of the index to be modified.\n"
"3. \"scriptSig\" (string, required) The scriptSig to insert.\n"

"\nResult:\n"
"\"hex\" (string) The modified transaction hash in hex.\n"
);

RPCTypeCheck(request.params, boost::assign::list_of
(UniValue::VSTR)
(UniValue::VNUM)
(UniValue::VSTR)
);

// parse hex string from parameter
CMutableTransaction rawTx;
if (!DecodeHexTx(rawTx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");

int nIn = request.params[1].get_int();
if (nIn < 0 || (size_t)nIn >= rawTx.vin.size())
throw JSONRPCError(RPC_INVALID_PARAMETER, "input index out of range");
if (rawTx.wit.vtxinwit.size() > (size_t)nIn && !rawTx.wit.vtxinwit[nIn].IsNull())
throw JSONRPCError(RPC_INVALID_PARAMETER, "input has witness when trying to add scriptSig");

if (!IsHex(request.params[2].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "script decode failed");

std::vector<unsigned char> vchScript = ParseHexV(request.params[2], "scriptsig");
rawTx.vin[nIn].scriptSig = CScript(vchScript.begin(), vchScript.end());

return EncodeHexTx(rawTx);
}

// Rewind the outputs to unblinded, and push placeholders for blinding info
void FillBlinds(CMutableTransaction& tx, bool fUseWallet, std::vector<uint256>& output_value_blinds, std::vector<uint256>& output_asset_blinds, std::vector<CPubKey>& output_pubkeys, std::vector<CKey>& asset_keys, std::vector<CKey>& token_keys) {
for (size_t nOut = 0; nOut < tx.vout.size(); nOut++) {
Expand Down Expand Up @@ -1617,6 +1661,7 @@ static const CRPCCommand commands[] =
// --------------------- ------------------------ ----------------------- ----------
{ "rawtransactions", "getrawtransaction", &getrawtransaction, true, {"txid","verbose"} },
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true, {"inputs","outputs","locktime"} },
{ "rawtransactions", "insertscriptsig", &insertscriptsig, true, {"tx","index","script"} },
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true, {"hexstring"} },
{ "rawtransactions", "compilescript", &compilescript, true, {"code"} },
{ "rawtransactions", "decodescript", &decodescript, true, {"hexstring"} },
Expand Down

0 comments on commit 0945d38

Please sign in to comment.