| 311 | } |
| 312 | |
| 313 | bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) |
| 314 | { |
| 315 | opcodeRet = OP_INVALIDOPCODE; |
| 316 | if (pvchRet) |
| 317 | pvchRet->clear(); |
| 318 | if (pc >= end) |
| 319 | return false; |
| 320 | |
| 321 | // Read instruction |
| 322 | if (end - pc < 1) |
| 323 | return false; |
| 324 | unsigned int opcode = *pc++; |
| 325 | |
| 326 | // Immediate operand |
| 327 | if (opcode <= OP_PUSHDATA4) |
| 328 | { |
| 329 | unsigned int nSize = 0; |
| 330 | if (opcode < OP_PUSHDATA1) |
| 331 | { |
| 332 | nSize = opcode; |
| 333 | } |
| 334 | else if (opcode == OP_PUSHDATA1) |
| 335 | { |
| 336 | if (end - pc < 1) |
| 337 | return false; |
| 338 | nSize = *pc++; |
| 339 | } |
| 340 | else if (opcode == OP_PUSHDATA2) |
| 341 | { |
| 342 | if (end - pc < 2) |
| 343 | return false; |
| 344 | nSize = ReadLE16(&pc[0]); |
| 345 | pc += 2; |
| 346 | } |
| 347 | else if (opcode == OP_PUSHDATA4) |
| 348 | { |
| 349 | if (end - pc < 4) |
| 350 | return false; |
| 351 | nSize = ReadLE32(&pc[0]); |
| 352 | pc += 4; |
| 353 | } |
| 354 | if (end - pc < 0 || (unsigned int)(end - pc) < nSize) |
| 355 | return false; |
| 356 | if (pvchRet) |
| 357 | pvchRet->assign(pc, pc + nSize); |
| 358 | pc += nSize; |
| 359 | } |
| 360 | |
| 361 | opcodeRet = static_cast<opcodetype>(opcode); |
| 362 | return true; |
| 363 | } |
| 364 | |
| 365 | bool IsOpSuccess(const opcodetype& opcode) |
| 366 | { |