def execute(cls, stack: 'MichelsonStack', stdout: List[str], context: AbstractContext): address = cast(KeyHashType, stack.pop1()) address.assert_type_equal(KeyHashType) res = NatType.from_value(context.get_voting_power(str(address))) stack.push(res) stdout.append(format_stdout(cls.prim, [address], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast(IntType, stack.pop1()) a.assert_type_equal(IntType) res = NatType.from_value(abs(int(a))) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): src = cast(Union[StringType, BytesType, ListType, SetType, MapType], stack.pop1()) src.assert_type_in(StringType, BytesType, ListType, SetType, MapType) res = NatType.from_value(len(src)) stack.push(res) stdout.append(format_stdout(cls.prim, [src], [res])) return cls()
def execute_shift(prim: str, stack: MichelsonStack, stdout: List[str], shift: Callable[[Tuple[int, int]], int]): a, b = cast(Tuple[NatType, NatType], stack.pop2()) a.assert_type_equal(NatType) b.assert_type_equal(NatType) assert int(b) < 257, f'shift overflow {int(b)}, should not exceed 256' c = shift((int(a), int(b))) res = NatType.from_value(c) stack.push(res) stdout.append(format_stdout(prim, [a, b], [res]))
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast(IntType, stack.pop1()) a.assert_type_equal(IntType) if int(a) >= 0: res = OptionType.from_some(NatType.from_value(int(a))) else: res = OptionType.none(NatType) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) return cls()
def execute(cls, stack: 'MichelsonStack', stdout: List[str], context: AbstractContext): res = NatType.from_value(context.get_level()) stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: 'MichelsonStack', stdout: List[str], context: AbstractContext): res = NatType.from_value(context.get_total_voting_power()) stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) return cls()