1
- // Copyright (c) 2009-2015 The Bitcoin Core developers
1
+ // Copyright (c) 2009-2018 The Bitcoin Core developers
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
@@ -190,18 +190,18 @@ static CAmount ExtractAndValidateValue(const std::string& strValue)
190
190
191
191
static void MutateTxVersion (CMutableTransaction& tx, const std::string& cmdVal)
192
192
{
193
- int64_t newVersion = atoi64 (cmdVal) ;
194
- if (newVersion < 1 || newVersion > CTransaction::MAX_STANDARD_VERSION)
195
- throw std::runtime_error (" Invalid TX version requested" );
193
+ int64_t newVersion;
194
+ if (! ParseInt64 (cmdVal, &newVersion) || newVersion < 1 || newVersion > CTransaction::MAX_STANDARD_VERSION)
195
+ throw std::runtime_error (" Invalid TX version requested: ' " + cmdVal + " ' " );
196
196
197
197
tx.nVersion = (int ) newVersion;
198
198
}
199
199
200
200
static void MutateTxLocktime (CMutableTransaction& tx, const std::string& cmdVal)
201
201
{
202
- int64_t newLocktime = atoi64 (cmdVal) ;
203
- if (newLocktime < 0LL || newLocktime > 0xffffffffLL )
204
- throw std::runtime_error (" Invalid TX locktime requested" );
202
+ int64_t newLocktime;
203
+ if (! ParseInt64 (cmdVal, &newLocktime) || newLocktime < 0LL || newLocktime > 0xffffffffLL )
204
+ throw std::runtime_error (" Invalid TX locktime requested: ' " + cmdVal + " ' " );
205
205
206
206
tx.nLockTime = (unsigned int ) newLocktime;
207
207
}
@@ -225,10 +225,10 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
225
225
static const unsigned int maxVout = MaxBlockSize () / minTxOutSz;
226
226
227
227
// extract and validate vout
228
- std::string strVout = vStrInputParts[1 ];
229
- int vout = atoi (strVout) ;
230
- if (( vout < 0 ) || ( vout > ( int ) maxVout))
231
- throw std::runtime_error (" invalid TX input vout" );
228
+ const std::string& strVout = vStrInputParts[1 ];
229
+ int64_t vout;
230
+ if (! ParseInt64 (strVout, & vout) || vout < 0 || vout > static_cast < int64_t >( maxVout))
231
+ throw std::runtime_error (" invalid TX input vout ' " + strVout + " ' " );
232
232
233
233
// extract the optional sequence number
234
234
uint32_t nSequenceIn=std::numeric_limits<unsigned int >::max ();
@@ -433,10 +433,9 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
433
433
static void MutateTxDelInput (CMutableTransaction& tx, const std::string& strInIdx)
434
434
{
435
435
// parse requested deletion index
436
- int inIdx = atoi (strInIdx);
437
- if (inIdx < 0 || inIdx >= (int )tx.vin .size ()) {
438
- std::string strErr = " Invalid TX input index '" + strInIdx + " '" ;
439
- throw std::runtime_error (strErr.c_str ());
436
+ int64_t inIdx;
437
+ if (!ParseInt64 (strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast <int64_t >(tx.vin .size ())) {
438
+ throw std::runtime_error (" Invalid TX input index '" + strInIdx + " '" );
440
439
}
441
440
442
441
// delete input from transaction
@@ -446,10 +445,9 @@ static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInId
446
445
static void MutateTxDelOutput (CMutableTransaction& tx, const std::string& strOutIdx)
447
446
{
448
447
// parse requested deletion index
449
- int outIdx = atoi (strOutIdx);
450
- if (outIdx < 0 || outIdx >= (int )tx.vout .size ()) {
451
- std::string strErr = " Invalid TX output index '" + strOutIdx + " '" ;
452
- throw std::runtime_error (strErr.c_str ());
448
+ int64_t outIdx;
449
+ if (!ParseInt64 (strOutIdx, &outIdx) || outIdx < 0 || outIdx >= static_cast <int64_t >(tx.vout .size ())) {
450
+ throw std::runtime_error (" Invalid TX output index '" + strOutIdx + " '" );
453
451
}
454
452
455
453
// delete output from transaction
@@ -547,7 +545,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
547
545
548
546
uint256 txid = ParseHashStr (prevOut[" txid" ].get_str (), " txid" );
549
547
550
- int nOut = atoi ( prevOut[" vout" ].getValStr () );
548
+ const int nOut = prevOut[" vout" ].get_int ( );
551
549
if (nOut < 0 )
552
550
throw std::runtime_error (" vout must be positive" );
553
551
0 commit comments