MCPcopy Create free account
hub / github.com/ElementsProject/elements / updatepsbtpegin

Function updatepsbtpegin

src/rpc/rawtransaction.cpp:3280–3379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3278}
3279
3280static RPCHelpMan updatepsbtpegin()
3281{
3282 return RPCHelpMan{"updatepsbtpegin",
3283 "\nFill in Peg-in input data for a particular input in a PSBT. Data is filled if provided.\n",
3284 {
3285 {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO,"The elements PSBT to update"},
3286 {"input", RPCArg::Type::NUM, RPCArg::Optional::NO, "The index of the input to update"},
3287 {"value", RPCArg::Type::AMOUNT, RPCArg::Optional::OMITTED, "The value of the peg-in"},
3288 {"bitcoin_tx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The raw bitcoin transaction (in hex) depositing bitcoin to the mainchain_address generated by getpeginaddress"},
3289 {"txout_proof", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A rawtxoutproof (in hex) generated by the mainchain daemon'sgettxoutproof containing a proof of only bitcoin_tx"},
3290 {"claim_script", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The witness program generated by getpeginaddress."},
3291 {"genesis_hash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The hash of the genesis block of the chain the bitcoin_tx is in"},
3292 },
3293 RPCResult{
3294 RPCResult::Type::STR, "", "The resulting raw transaction (base64-encoded string)"
3295 },
3296 RPCExamples{
3297 HelpExampleCli("updatepsbtpegin", "psbt 0")
3298 },
3299 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
3300{
3301 if (!g_con_elementsmode)
3302 throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n");
3303
3304 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VNUM, UniValueType(), UniValue::VSTR, UniValue::VSTR, UniValue::VSTR, UniValue::VSTR}, true);
3305
3306 // Unserialize the transaction
3307 PartiallySignedTransaction psbtx;
3308 std::string error;
3309 if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
3310 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error));
3311 }
3312
3313 // Get the input to update
3314 int input_index = request.params[1].get_int();
3315 PSBTInput& input = psbtx.inputs[input_index];
3316
3317 // Peg-in value
3318 if (!request.params[2].isNull()) {
3319 CAmount value = AmountFromValue(request.params[2]);
3320 input.m_peg_in_value = value;
3321 }
3322
3323 // Peg-in tx
3324 if (!request.params[3].isNull()) {
3325 const std::vector<unsigned char> tx_data = ParseHex(request.params[3].get_str());
3326 CDataStream ss_tx(tx_data, SER_NETWORK, PROTOCOL_VERSION);
3327 try {
3328 if (Params().GetConsensus().ParentChainHasPow()) {
3329 Sidechain::Bitcoin::CTransactionRef tx;
3330 ss_tx >> tx;
3331 input.m_peg_in_tx = tx;
3332 } else {
3333 CTransactionRef tx;
3334 ss_tx >> tx;
3335 input.m_peg_in_tx = tx;
3336 }
3337 } catch (...) {

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
RPCTypeCheckFunction · 0.85
UniValueTypeClass · 0.85
DecodeBase64PSBTFunction · 0.85
JSONRPCErrorFunction · 0.85
ParseHexFunction · 0.85
ParseHexVFunction · 0.85
ParseHashVFunction · 0.85
EncodePSBTFunction · 0.85
get_intMethod · 0.80
ParentChainHasPowMethod · 0.80
AmountFromValueFunction · 0.70

Tested by

no test coverage detected