Skip to content

Commit

Permalink
WIP blindpsbt rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Oct 8, 2020
1 parent 2441ba4 commit 317baef
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4658,6 +4658,62 @@ UniValue walletprocesspsbt(const JSONRPCRequest& request)
return result;
}

UniValue walletblindpsbt(const JSONRPCRequest& request)
{
if (!g_con_elementsmode)
throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n");

std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();

if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue;
}

if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
throw std::runtime_error(
RPCHelpMan{"walletblindpsbt",
"\nUpdate a PSBT with input information from our wallet and then sign inputs\n"
"that we can sign for.\n\n"
HelpRequiringPassphrase(pwallet) + "\n",
{
{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction base64 string"},
},
RPCResult{
"{\n"
" \"psbt\" : \"value\", (string) The base64-encoded partially signed transaction\n"
" ]\n"
"}\n"
},
RPCExamples{
HelpExampleCli("walletblindpsbt", "\"psbt\"")
},
}.ToString());

RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VSTR});

// Unserialize the transaction
PartiallySignedTransaction psbtx;
std::string error;
if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error));
}

// TODO: Gather our input data

// TODO: Gather our issuances to blind

// Blind the PSBT
BlindPSBT(psbtx, our_input_data, our_issuances_to_blind);

UniValue result(UniValue::VOBJ);
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << psbtx;
result.pushKV("psbt", EncodeBase64(ssTx.str()));

return result;
}

UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
{
if (!g_con_elementsmode)
Expand Down

0 comments on commit 317baef

Please sign in to comment.