def op_checkmultisig(vm, instr): if len(vm.stack) < 1: raise Exception("OP_CHECKMULTISIG: Stack too small for pubkey_count") pubkey_count = cast_to_number(vm.stack.pop()) if len(vm.stack) < pubkey_count: raise Exception("OP_CHECKMULTISIG: Stack too small for pubkeys") pubkeys = vm.stack[-pubkey_count:] del vm.stack[-pubkey_count:] if len(vm.stack) < 1: raise Exception("OP_CHECKMULTISIG: Stack too small for sig_count") sig_count = cast_to_number(vm.stack.pop()) if len(vm.stack) < sig_count: raise Exception("OP_CHECKMULTISIG: Stack too small for sigs") sigs = vm.stack[-sig_count:] del vm.stack[-sig_count:] vm.stack.append (valtype_from_boolean(check_multisig(vm, sigs, pubkeys)))
def op_checkmultisig(vm, instr): if len(vm.stack) < 1: raise Exception("OP_CHECKMULTISIG: Stack too small for pubkey_count") pubkey_count = cast_to_number(vm.stack.pop()) if len(vm.stack) < pubkey_count: raise Exception("OP_CHECKMULTISIG: Stack too small for pubkeys") pubkeys = vm.stack[-pubkey_count:] del vm.stack[-pubkey_count:] if len(vm.stack) < 1: raise Exception("OP_CHECKMULTISIG: Stack too small for sig_count") sig_count = cast_to_number(vm.stack.pop()) if len(vm.stack) < sig_count: raise Exception("OP_CHECKMULTISIG: Stack too small for sigs") sigs = vm.stack[-sig_count:] del vm.stack[-sig_count:] vm.stack.append(valtype_from_boolean(check_multisig(vm, sigs, pubkeys)))
def op_pick(vm, instr): if len(vm.stack) < 2: raise Exception("OP_PICK: Not enought arguments") n = cast_to_number(vm.stack.pop()) if (n < 0) or (n >= len(vm.stack) ): raise Exception("OP_PICK: N is out of range") elm = vm.stack[-n-1] vm.stack.append(elm)
def arithmetic_op(vm, func, arity): if len(vm.stack) < arity: raise Exception("Not enought arguments") args = [cast_to_number(vm.stack.pop()) for _ in range(arity)] result = func(*reversed(args)) vm.stack.append(valtype_from_number(result))