Skip to content

Commit 4f3f5cb

Browse files
committed
Remove redundant txConst parameter to FillPSBT
1 parent fe5d22b commit 4f3f5cb

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,13 +3735,13 @@ void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map<CPubK
37353735
hd_keypaths.emplace(vchPubKey, std::move(info));
37363736
}
37373737

3738-
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const CTransaction* txConst, int sighash_type, bool sign, bool bip32derivs)
3738+
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, int sighash_type, bool sign, bool bip32derivs)
37393739
{
37403740
LOCK(pwallet->cs_wallet);
37413741
// Get all of the previous transactions
37423742
bool complete = true;
3743-
for (unsigned int i = 0; i < txConst->vin.size(); ++i) {
3744-
const CTxIn& txin = txConst->vin[i];
3743+
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
3744+
const CTxIn& txin = psbtx.tx->vin[i];
37453745
PSBTInput& input = psbtx.inputs.at(i);
37463746

37473747
// If we don't know about this input, skip it and let someone else deal with it
@@ -3764,8 +3764,8 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
37643764
}
37653765

37663766
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
3767-
for (unsigned int i = 0; i < txConst->vout.size(); ++i) {
3768-
const CTxOut& out = txConst->vout.at(i);
3767+
for (unsigned int i = 0; i < psbtx.tx->vout.size(); ++i) {
3768+
const CTxOut& out = psbtx.tx->vout.at(i);
37693769
PSBTOutput& psbt_out = psbtx.outputs.at(i);
37703770

37713771
// Fill a SignatureData with output info
@@ -3830,14 +3830,10 @@ UniValue walletprocesspsbt(const JSONRPCRequest& request)
38303830
// Get the sighash type
38313831
int nHashType = ParseSighashString(request.params[2]);
38323832

3833-
// Use CTransaction for the constant parts of the
3834-
// transaction to avoid rehashing.
3835-
const CTransaction txConst(*psbtx.tx);
3836-
38373833
// Fill transaction with our data and also sign
38383834
bool sign = request.params[1].isNull() ? true : request.params[1].get_bool();
38393835
bool bip32derivs = request.params[3].isNull() ? false : request.params[3].get_bool();
3840-
bool complete = FillPSBT(pwallet, psbtx, &txConst, nHashType, sign, bip32derivs);
3836+
bool complete = FillPSBT(pwallet, psbtx, nHashType, sign, bip32derivs);
38413837

38423838
UniValue result(UniValue::VOBJ);
38433839
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
@@ -3943,13 +3939,9 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
39433939
psbtx.outputs.push_back(PSBTOutput());
39443940
}
39453941

3946-
// Use CTransaction for the constant parts of the
3947-
// transaction to avoid rehashing.
3948-
const CTransaction txConst(*psbtx.tx);
3949-
39503942
// Fill transaction with out data but don't sign
39513943
bool bip32derivs = request.params[4].isNull() ? false : request.params[4].get_bool();
3952-
FillPSBT(pwallet, psbtx, &txConst, 1, false, bip32derivs);
3944+
FillPSBT(pwallet, psbtx, 1, false, bip32derivs);
39533945

39543946
// Serialize the PSBT
39553947
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);

src/wallet/rpcwallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ bool EnsureWalletIsAvailable(CWallet *, bool avoidException);
3030

3131
UniValue getaddressinfo(const JSONRPCRequest& request);
3232
UniValue signrawtransactionwithwallet(const JSONRPCRequest& request);
33-
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const CTransaction* txConst, int sighash_type = 1, bool sign = true, bool bip32derivs = false);
33+
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, int sighash_type = 1, bool sign = true, bool bip32derivs = false);
3434
#endif //BITCOIN_WALLET_RPCWALLET_H

src/wallet/test/psbt_wallet_tests.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
5959
CDataStream ssData(ParseHex("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000"), SER_NETWORK, PROTOCOL_VERSION);
6060
ssData >> psbtx;
6161

62-
// Use CTransaction for the constant parts of the
63-
// transaction to avoid rehashing.
64-
const CTransaction txConst(*psbtx.tx);
65-
6662
// Fill transaction with our data
67-
FillPSBT(&m_wallet, psbtx, &txConst, 1, false, true);
63+
FillPSBT(&m_wallet, psbtx, 1, false, true);
6864

6965
// Get the final tx
7066
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);

0 commit comments

Comments
 (0)