def main(operation: int) -> Any:

    # create an array
    stuff = ['a', 3, ['j', 3, 5], 'jk', 'lmnopqr']

    # serialize it
    to_save = serialize(stuff)
    put('serialized', to_save)

    if operation == 1:
        return to_save

    elif operation == 2:
        to_retrieve = get('serialized')
        return to_retrieve

    elif operation == 3:

        to_retrieve = get('serialized')
        deserialized = deserialize(to_retrieve)
        return deserialized

    elif operation == 4:

        to_retrieve = get('serialized')
        deserialized = deserialize(to_retrieve)
        return cast(list, deserialized)[2]

    return False
示例#2
0
def serialize_bool() -> bytes:
    return serialize(True)
def serialize_user_class() -> bytes:
    user_class = Example()
    return serialize(user_class)
 def set_account(self):
     storage.put(PREFIX_ACCOUNT + self.address, serialize(self))
def set_nft(token_id: bytes, token: NFT):
    storage.put(PREFIX_TOKEN + token_id, serialize(token))
示例#6
0
def set_value(token_id: bytes, example_class: Example):
    storage.put(b'00' + token_id, serialize(example_class))
示例#7
0
def serialize_dict() -> bytes:
    return serialize({1: 1, 2: 1, 3: 2})
示例#8
0
def serialize_str() -> bytes:
    return serialize('42')
示例#9
0
def serialize_sequence() -> bytes:
    return serialize([2, 3, 5, 7])
示例#10
0
def serialize_int() -> bytes:
    return serialize(42)