コード例 #1
0
 def from_comb(cls, comb: PairType) -> 'TicketType':
     ticketer, item, amount = cast(
         Tuple[AddressType, MichelsonType, NatType],
         tuple(comb.iter_comb()))
     return cls(
         item=item,
         ticketer=str(ticketer),
         amount=int(amount),
     )
コード例 #2
0
 def to_comb(self) -> PairType:
     return PairType.from_comb(items=[
         AddressType(self.ticketer), self.item,
         NatType(self.amount)
     ])
コード例 #3
0
 def from_python_object(cls, py_obj) -> 'MichelsonType':
     type_impl = PairType.create_type(
         args=[AddressType, cls.args[0], NatType])
     comb = type_impl.from_python_object(py_obj)
     return cls.from_comb(comb)
コード例 #4
0
 def from_micheline_value(cls, val_expr) -> 'TicketType':
     type_impl = PairType.create_type(
         args=[AddressType, cls.args[0], NatType])
     comb = type_impl.from_micheline_value(val_expr)
     return cls.from_comb(comb)
コード例 #5
0
ファイル: checker.py プロジェクト: tezos-checker/checker
def compile_view_fa2_token_metadata(tokens: List[TokenMetadata]):
    from pytezos.michelson.types.core import BytesType, NatType, StringType
    from pytezos.michelson.types.map import MapType
    from pytezos.michelson.types.pair import PairType

    # this map is of type:
    #   map nat (nat, map string bytes)
    elt = MapType.from_items([(
        NatType.from_value(token.id),
        PairType.from_comb([
            NatType.from_value(token.id),
            MapType.from_items([
                (StringType.from_value(key), BytesType.from_value(value))
                for key, value in sorted(token.attrs.items())
            ]),
        ]),
    ) for token in tokens])

    # Below code takes a '(nat, state)', looks up the 'nat' from the map above ('elt'),
    # and returns the result.
    code = [
        # get the 'fst' of the '(nat, state)' pair
        {
            "prim": "CAR"
        },
        # push the 'elt' to the stack
        {
            "prim": "PUSH",
            "args": [elt.as_micheline_expr(),
                     elt.to_micheline_value()]
        },
        # swap the top two elements (to match 'get's parameter order)
        {
            "prim": "SWAP"
        },
        # lookup the given 'nat' from the map
        {
            "prim": "GET"
        },
        # fail if we don't get something, return otherwise
        {
            "prim":
            "IF_NONE",
            "args": [  # if none
                [
                    {
                        "prim":
                        "PUSH",
                        "args": [{
                            "prim": "string"
                        }, {
                            "string": "FA2_UNKNOWN_TOKEN"
                        }],
                    },
                    {
                        "prim": "FAILWITH"
                    },
                ],
                # if not none
                [],
            ],
        },
    ]

    return {
        "name": "token_metadata",
        "code": code,
        "parameter": {
            "prim": "nat"
        },
        "returnType": {
            "prim":
            "pair",
            "args": [
                {
                    "prim": "nat"
                },
                {
                    "prim": "map",
                    "args": [{
                        "prim": "string"
                    }, {
                        "prim": "bytes"
                    }]
                },
            ],
        },
    }
コード例 #6
0
ファイル: ticket.py プロジェクト: kengkiat/pytezos
 def from_comb(cls, comb: PairType) -> 'TicketType':
     ticketer, item, amount = tuple(comb.iter_comb())  # type: AddressType, MichelsonType, NatType
     return cls(item=item,
                ticketer=str(ticketer),
                amount=int(amount))