Skip to content

Commit 646e76f

Browse files
committed
Be able to create peg-in PSBTs in createpegin
1 parent b5590b2 commit 646e76f

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,9 @@ UniValue createpsbt(const JSONRPCRequest& request)
20622062
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
20632063
{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
20642064
{"sequence", RPCArg::Type::NUM, /* default */ "depends on the value of the 'replaceable' and 'locktime' arguments", "The sequence number"},
2065+
{"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"},
2066+
{"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"},
2067+
{"pegin_claim_script", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The witness program generated by getpeginaddress."},
20652068
},
20662069
},
20672070
},
@@ -2111,14 +2114,50 @@ UniValue createpsbt(const JSONRPCRequest& request)
21112114
);
21122115

21132116
std::vector<CPubKey> output_pubkeys;
2114-
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3], request.params[4], &output_pubkeys, false /* allow_peg_in */);
2117+
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3], request.params[4], &output_pubkeys);
21152118

21162119
// Make a blank psbt
21172120
PartiallySignedTransaction psbtx(rawTx);
21182121
for (unsigned int i = 0; i < rawTx.vout.size(); ++i) {
21192122
psbtx.outputs[i].blinding_pubkey = output_pubkeys[i];
21202123
}
21212124

2125+
// Add peg-in stuff if it's there
2126+
for (unsigned int i = 0; i < rawTx.vin.size(); ++i) {
2127+
if (psbtx.tx->vin[i].m_is_pegin) {
2128+
CScriptWitness& pegin_witness = psbtx.tx->witness.vtxinwit[i].m_pegin_witness;
2129+
CAmount val;
2130+
VectorReader vr_val(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[0], 0);
2131+
vr_val >> val;
2132+
psbtx.inputs[i].value = val;
2133+
VectorReader vr_asset(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[1], 0);
2134+
vr_asset >> psbtx.inputs[i].asset;
2135+
VectorReader vr_genesis(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[2], 0);
2136+
vr_genesis >> psbtx.inputs[i].genesis_hash;
2137+
psbtx.inputs[i].claim_script.assign(pegin_witness.stack[3].begin(), pegin_witness.stack[3].end());
2138+
2139+
VectorReader vr_tx(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[4], 0);
2140+
VectorReader vr_proof(SER_NETWORK, PROTOCOL_VERSION, pegin_witness.stack[5], 0);
2141+
if (Params().GetConsensus().ParentChainHasPow()) {
2142+
Sidechain::Bitcoin::CTransactionRef tx_btc;
2143+
vr_tx >> tx_btc;
2144+
psbtx.inputs[i].peg_in_tx = tx_btc;
2145+
Sidechain::Bitcoin::CMerkleBlock tx_proof;
2146+
vr_proof >> tx_proof;
2147+
psbtx.inputs[i].txout_proof = tx_proof;
2148+
} else {
2149+
CTransactionRef tx_btc;
2150+
vr_tx >> tx_btc;
2151+
psbtx.inputs[i].peg_in_tx = tx_btc;
2152+
CMerkleBlock tx_proof;
2153+
vr_proof >> tx_proof;
2154+
psbtx.inputs[i].txout_proof = tx_proof;
2155+
}
2156+
pegin_witness.SetNull();
2157+
psbtx.tx->vin[i].m_is_pegin = false;
2158+
}
2159+
}
2160+
21222161
return EncodePSBT(psbtx);
21232162
}
21242163

test/functional/rpc_psbt.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,7 @@ def run_test(self):
524524
# Some Confidential-Assets-specific tests
525525
self.run_ca_tests()
526526

527-
# Check that peg-ins are disallowed
528-
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}])
529-
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}])
530-
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}])
527+
# Check that peg-ins are disallowed for walletcreatefundedpsbt
531528
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}])
532529
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}])
533530
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}])

0 commit comments

Comments
 (0)