Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show First 20 Lines • Show All 616 Lines • ▼ Show 20 Lines | for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) { | ||||
uint256 txid = ParseHashUV(prevOut["txid"], "txid"); | uint256 txid = ParseHashUV(prevOut["txid"], "txid"); | ||||
int nOut = atoi(prevOut["vout"].getValStr()); | int nOut = atoi(prevOut["vout"].getValStr()); | ||||
if (nOut < 0) { | if (nOut < 0) { | ||||
throw std::runtime_error("vout must be positive"); | throw std::runtime_error("vout must be positive"); | ||||
} | } | ||||
COutPoint out(txid, nOut); | |||||
std::vector<uint8_t> pkData( | std::vector<uint8_t> pkData( | ||||
ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey")); | ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey")); | ||||
CScript scriptPubKey(pkData.begin(), pkData.end()); | CScript scriptPubKey(pkData.begin(), pkData.end()); | ||||
{ | { | ||||
CCoinsModifier coins = view.ModifyCoins(txid); | const Coin &coin = view.AccessCoin(out); | ||||
if (coins->IsAvailable(nOut) && | if (!coin.IsSpent() && | ||||
coins->vout[nOut].scriptPubKey != scriptPubKey) { | coin.GetTxOut().scriptPubKey != scriptPubKey) { | ||||
std::string err("Previous output scriptPubKey mismatch:\n"); | std::string err("Previous output scriptPubKey mismatch:\n"); | ||||
err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + | err = err + ScriptToAsmStr(coin.GetTxOut().scriptPubKey) + | ||||
"\nvs:\n" + ScriptToAsmStr(scriptPubKey); | "\nvs:\n" + ScriptToAsmStr(scriptPubKey); | ||||
throw std::runtime_error(err); | throw std::runtime_error(err); | ||||
} | } | ||||
if ((unsigned int)nOut >= coins->vout.size()) { | CTxOut txout; | ||||
coins->vout.resize(nOut + 1); | txout.scriptPubKey = scriptPubKey; | ||||
} | txout.nValue = 0; | ||||
coins->vout[nOut].scriptPubKey = scriptPubKey; | |||||
coins->vout[nOut].nValue = 0; | |||||
if (prevOut.exists("amount")) { | if (prevOut.exists("amount")) { | ||||
coins->vout[nOut].nValue = AmountFromValue(prevOut["amount"]); | txout.nValue = AmountFromValue(prevOut["amount"]); | ||||
} | } | ||||
view.AddCoin(out, Coin(txout, 1, false), true); | |||||
} | } | ||||
// If redeemScript given and private keys given, add redeemScript to the | // If redeemScript given and private keys given, add redeemScript to the | ||||
// tempKeystore so it can be signed: | // tempKeystore so it can be signed: | ||||
if (scriptPubKey.IsPayToScriptHash() && | if (scriptPubKey.IsPayToScriptHash() && | ||||
prevOut.exists("redeemScript")) { | prevOut.exists("redeemScript")) { | ||||
UniValue v = prevOut["redeemScript"]; | UniValue v = prevOut["redeemScript"]; | ||||
std::vector<uint8_t> rsData(ParseHexUV(v, "redeemScript")); | std::vector<uint8_t> rsData(ParseHexUV(v, "redeemScript")); | ||||
▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines |