MCPcopy
hub / github.com/petertodd/python-bitcoinlib / _UnaryOp

Function _UnaryOp

bitcoin/core/scripteval.py:237–265  ·  view source on GitHub ↗
(opcode, stack, err_raiser)

Source from the content-addressed store, hash-verified

235}
236
237def _UnaryOp(opcode, stack, err_raiser):
238 if len(stack) < 1:
239 err_raiser(MissingOpArgumentsError, opcode, stack, 1)
240 bn = _CastToBigNum(stack[-1], err_raiser)
241 stack.pop()
242
243 if opcode == OP_1ADD:
244 bn += 1
245
246 elif opcode == OP_1SUB:
247 bn -= 1
248
249 elif opcode == OP_NEGATE:
250 bn = -bn
251
252 elif opcode == OP_ABS:
253 if bn < 0:
254 bn = -bn
255
256 elif opcode == OP_NOT:
257 bn = int(bn == 0)
258
259 elif opcode == OP_0NOTEQUAL:
260 bn = int(bn != 0)
261
262 else:
263 raise AssertionError("Unknown unary opcode encountered; this should not happen")
264
265 stack.append(bitcoin.core._bignum.bn2vch(bn))
266
267
268# OP_LSHIFT and OP_RSHIFT are *not* included in this list as they are disabled

Callers 1

_EvalScriptFunction · 0.85

Calls 2

err_raiserFunction · 0.85
_CastToBigNumFunction · 0.85

Tested by

no test coverage detected