MCPcopy Index your code
hub / github.com/petertodd/python-bitcoinlib / _EvalScript

Function _EvalScript

bitcoin/core/scripteval.py:362–707  ·  view source on GitHub ↗

Evaluate a script

(stack, scriptIn, txTo, inIdx, flags=())

Source from the content-addressed store, hash-verified

360
361
362def _EvalScript(stack, scriptIn, txTo, inIdx, flags=()):
363 """Evaluate a script
364
365 """
366 if len(scriptIn) > MAX_SCRIPT_SIZE:
367 raise EvalScriptError('script too large; got %d bytes; maximum %d bytes' %
368 (len(scriptIn), MAX_SCRIPT_SIZE),
369 stack=stack,
370 scriptIn=scriptIn,
371 txTo=txTo,
372 inIdx=inIdx,
373 flags=flags)
374
375 altstack = []
376 vfExec = []
377 pbegincodehash = 0
378 nOpCount = [0]
379 for (sop, sop_data, sop_pc) in scriptIn.raw_iter():
380 fExec = _CheckExec(vfExec)
381
382 def err_raiser(cls, *args):
383 """Helper function for raising EvalScriptError exceptions
384
385 cls - subclass you want to raise
386
387 *args - arguments
388
389 Fills in the state of execution for you.
390 """
391 raise cls(*args,
392 sop=sop,
393 sop_data=sop_data,
394 sop_pc=sop_pc,
395 stack=stack, scriptIn=scriptIn, txTo=txTo, inIdx=inIdx, flags=flags,
396 altstack=altstack, vfExec=vfExec, pbegincodehash=pbegincodehash, nOpCount=nOpCount[0])
397
398
399 if sop in DISABLED_OPCODES:
400 err_raiser(EvalScriptError, 'opcode %s is disabled' % OPCODE_NAMES[sop])
401
402 if sop > OP_16:
403 nOpCount[0] += 1
404 if nOpCount[0] > MAX_SCRIPT_OPCODES:
405 err_raiser(MaxOpCountError)
406
407 def check_args(n):
408 if len(stack) < n:
409 err_raiser(MissingOpArgumentsError, sop, stack, n)
410
411
412 if sop <= OP_PUSHDATA4:
413 if len(sop_data) > MAX_SCRIPT_ELEMENT_SIZE:
414 err_raiser(EvalScriptError,
415 'PUSHDATA of length %d; maximum allowed is %d' %
416 (len(sop_data), MAX_SCRIPT_ELEMENT_SIZE))
417
418 elif fExec:
419 stack.append(sop_data)

Callers 1

EvalScriptFunction · 0.85

Calls 15

ripemd160Function · 0.90
EvalScriptErrorClass · 0.85
_CheckExecFunction · 0.85
err_raiserFunction · 0.85
_BinOpFunction · 0.85
_UnaryOpFunction · 0.85
check_argsFunction · 0.85
CScriptClass · 0.85
_CheckMultiSigFunction · 0.85
FindAndDeleteFunction · 0.85
_CheckSigFunction · 0.85
_CastToBoolFunction · 0.85

Tested by

no test coverage detected