mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Use ModifyCoins instead of mutable GetCoins.
Replace the mutable non-copying GetCoins method with a ModifyCoins, which returns an encapsulated iterator, so we can keep track of concurrent modifications (as iterators can be invalidated by those) and run cleanup code after a modification is finished. This also removes the overloading of the 'GetCoins' name.
This commit is contained in:
@@ -384,21 +384,19 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
|
||||
vector<unsigned char> pkData(ParseHexUV(prevOut, "scriptPubKey"));
|
||||
CScript scriptPubKey(pkData.begin(), pkData.end());
|
||||
|
||||
CCoins coins;
|
||||
if (view.GetCoins(txid, coins)) {
|
||||
if (coins.IsAvailable(nOut) && coins.vout[nOut].scriptPubKey != scriptPubKey) {
|
||||
{
|
||||
CCoinsModifier coins = view.ModifyCoins(txid);
|
||||
if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) {
|
||||
string err("Previous output scriptPubKey mismatch:\n");
|
||||
err = err + coins.vout[nOut].scriptPubKey.ToString() + "\nvs:\n"+
|
||||
err = err + coins->vout[nOut].scriptPubKey.ToString() + "\nvs:\n"+
|
||||
scriptPubKey.ToString();
|
||||
throw runtime_error(err);
|
||||
}
|
||||
// what todo if txid is known, but the actual output isn't?
|
||||
if ((unsigned int)nOut >= coins->vout.size())
|
||||
coins->vout.resize(nOut+1);
|
||||
coins->vout[nOut].scriptPubKey = scriptPubKey;
|
||||
coins->vout[nOut].nValue = 0; // we don't know the actual output value
|
||||
}
|
||||
if ((unsigned int)nOut >= coins.vout.size())
|
||||
coins.vout.resize(nOut+1);
|
||||
coins.vout[nOut].scriptPubKey = scriptPubKey;
|
||||
coins.vout[nOut].nValue = 0; // we don't know the actual output value
|
||||
view.SetCoins(txid, coins);
|
||||
|
||||
// if redeemScript given and private keys given,
|
||||
// add redeemScript to the tempKeystore so it can be signed:
|
||||
|
||||
Reference in New Issue
Block a user