diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index ba3c4ca650..e6a7f270be 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -2062,6 +2062,9 @@ UniValue createpsbt(const JSONRPCRequest& request) {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"}, {"sequence", RPCArg::Type::NUM, /* default */ "depends on the value of the 'replaceable' and 'locktime' arguments", "The sequence number"}, + {"pegin_bitcoin_tx", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The raw bitcoin transaction (in hex) depositing bitcoin to the mainchain_address generated by getpeginaddress"}, + {"pegin_txout_proof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A rawtxoutproof (in hex) generated by the mainchain daemon's `gettxoutproof` containing a proof of only bitcoin_tx"}, + {"pegin_claim_script", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The witness program generated by getpeginaddress."}, }, }, }, @@ -2111,7 +2114,7 @@ UniValue createpsbt(const JSONRPCRequest& request) ); std::vector output_pubkeys; - CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3], request.params[4], &output_pubkeys, false /* allow_peg_in */); + CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3], request.params[4], &output_pubkeys); // Make a blank psbt PartiallySignedTransaction psbtx(rawTx); @@ -2119,6 +2122,42 @@ UniValue createpsbt(const JSONRPCRequest& request) psbtx.outputs[i].blinding_pubkey = output_pubkeys[i]; } + // Add peg-in stuff if it's there + for (unsigned int i = 0; i < rawTx.vin.size(); ++i) { + if (psbtx.tx->vin[i].m_is_pegin) { + CScriptWitness& pegin_witness = psbtx.tx->witness.vtxinwit[i].m_pegin_witness; + CAmount val; + VectorReader vr_val(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[0], 0); + vr_val >> val; + psbtx.inputs[i].value = val; + VectorReader vr_asset(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[1], 0); + vr_asset >> psbtx.inputs[i].asset; + VectorReader vr_genesis(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[2], 0); + vr_genesis >> psbtx.inputs[i].genesis_hash; + psbtx.inputs[i].claim_script.assign(pegin_witness.stack[3].begin(), pegin_witness.stack[3].end()); + + VectorReader vr_tx(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[4], 0); + VectorReader vr_proof(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[5], 0); + if (Params().GetConsensus().ParentChainHasPow()) { + Sidechain::Bitcoin::CTransactionRef tx_btc; + vr_tx >> tx_btc; + psbtx.inputs[i].peg_in_tx = tx_btc; + Sidechain::Bitcoin::CMerkleBlock tx_proof; + vr_proof >> tx_proof; + psbtx.inputs[i].txout_proof = tx_proof; + } else { + CTransactionRef tx_btc; + vr_tx >> tx_btc; + psbtx.inputs[i].peg_in_tx = tx_btc; + CMerkleBlock tx_proof; + vr_proof >> tx_proof; + psbtx.inputs[i].txout_proof = tx_proof; + } + pegin_witness.SetNull(); + psbtx.tx->vin[i].m_is_pegin = false; + } + } + return EncodePSBT(psbtx); } diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 25ea4d9f52..11a0631721 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -524,10 +524,7 @@ class PSBTTest(BitcoinTestFramework): # Some Confidential-Assets-specific tests self.run_ca_tests() - # Check that peg-ins are disallowed - assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].createpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_bitcoin_tx": "00"}], [{self.nodes[0].getnewaddress(): 1}]) - assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].createpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_txout_proof": "00"}], [{self.nodes[0].getnewaddress(): 1}]) - assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].createpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_claim_script": "00"}], [{self.nodes[0].getnewaddress(): 1}]) + # Check that peg-ins are disallowed for walletcreatefundedpsbt assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].walletcreatefundedpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_bitcoin_tx": "00"}], [{self.nodes[0].getnewaddress(): 1}]) assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].walletcreatefundedpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_txout_proof": "00"}], [{self.nodes[0].getnewaddress(): 1}]) assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].walletcreatefundedpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_claim_script": "00"}], [{self.nodes[0].getnewaddress(): 1}])