Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,785 Lines • ▼ Show 20 Lines | bool CWallet::SignTransaction(CMutableTransaction &tx, | ||||
auto legacy_spk_man = GetLegacyScriptPubKeyMan(); | auto legacy_spk_man = GetLegacyScriptPubKeyMan(); | ||||
if (legacy_spk_man->SignTransaction(tx, coins, sighash, input_errors)) { | if (legacy_spk_man->SignTransaction(tx, coins, sighash, input_errors)) { | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
TransactionError CWallet::FillPSBT(PartiallySignedTransaction &psbtx, | |||||
bool &complete, SigHashType sighash_type, | |||||
bool sign, bool bip32derivs) const { | |||||
LOCK(cs_wallet); | |||||
// Get all of the previous transactions | |||||
complete = true; | |||||
for (size_t i = 0; i < psbtx.tx->vin.size(); ++i) { | |||||
const CTxIn &txin = psbtx.tx->vin[i]; | |||||
PSBTInput &input = psbtx.inputs.at(i); | |||||
if (PSBTInputSigned(input)) { | |||||
continue; | |||||
} | |||||
// Verify input looks sane. | |||||
if (!input.IsSane()) { | |||||
return TransactionError::INVALID_PSBT; | |||||
} | |||||
// If we have no utxo, grab it from the wallet. | |||||
if (input.utxo.IsNull()) { | |||||
const TxId &txid = txin.prevout.GetTxId(); | |||||
const auto it = mapWallet.find(txid); | |||||
if (it != mapWallet.end()) { | |||||
const CWalletTx &wtx = it->second; | |||||
CTxOut utxo = wtx.tx->vout[txin.prevout.GetN()]; | |||||
// Update UTXOs from the wallet. | |||||
input.utxo = utxo; | |||||
} | |||||
} | |||||
// Get the Sighash type | |||||
if (sign && input.sighash_type.getRawSigHashType() > 0 && | |||||
input.sighash_type != sighash_type) { | |||||
return TransactionError::SIGHASH_MISMATCH; | |||||
} | |||||
// Get the scriptPubKey to know which SigningProvider to use | |||||
CScript script; | |||||
if (!input.utxo.IsNull()) { | |||||
script = input.utxo.scriptPubKey; | |||||
} else { | |||||
// There's no UTXO so we can just skip this now | |||||
complete = false; | |||||
continue; | |||||
} | |||||
SignatureData sigdata; | |||||
input.FillSignatureData(sigdata); | |||||
std::unique_ptr<SigningProvider> provider = | |||||
GetSigningProvider(script, sigdata); | |||||
if (!provider) { | |||||
complete = false; | |||||
continue; | |||||
} | |||||
complete &= SignPSBTInput( | |||||
HidingSigningProvider(provider.get(), !sign, !bip32derivs), psbtx, | |||||
i, sighash_type); | |||||
} | |||||
// Fill in the bip32 keypaths and redeemscripts for the outputs so that | |||||
// hardware wallets can identify change | |||||
for (size_t i = 0; i < psbtx.tx->vout.size(); ++i) { | |||||
const CTxOut &out = psbtx.tx->vout.at(i); | |||||
std::unique_ptr<SigningProvider> provider = | |||||
GetSigningProvider(out.scriptPubKey); | |||||
if (provider) { | |||||
UpdatePSBTOutput( | |||||
HidingSigningProvider(provider.get(), true, !bip32derivs), | |||||
psbtx, i); | |||||
} | |||||
} | |||||
return TransactionError::OK; | |||||
} | |||||
bool CWallet::FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, | bool CWallet::FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, | ||||
int &nChangePosInOut, bilingual_str &error, | int &nChangePosInOut, bilingual_str &error, | ||||
bool lockUnspents, | bool lockUnspents, | ||||
const std::set<int> &setSubtractFeeFromOutputs, | const std::set<int> &setSubtractFeeFromOutputs, | ||||
CCoinControl coinControl) { | CCoinControl coinControl) { | ||||
std::vector<CRecipient> vecSend; | std::vector<CRecipient> vecSend; | ||||
// Turn the txout set into a CRecipient vector. | // Turn the txout set into a CRecipient vector. | ||||
▲ Show 20 Lines • Show All 1,998 Lines • Show Last 20 Lines |