Esempio n. 1
0
def _encode_manager_common(w: bytearray, sequence_length, operation, to_contract=False):
    IMPLICIT_ADDRESS_LENGTH = 21
    SMART_CONTRACT_ADDRESS_LENGTH = 22

    # 5 = tag and sequence_length (1 byte + 4 bytes)
    argument_length = sequence_length + 5

    helpers.write_bool(w, True)
    write_uint8(w, helpers.DO_ENTRYPOINT_TAG)
    write_uint32_be(w, argument_length)
    write_uint8(w, helpers.MICHELSON_SEQUENCE_TAG)
    write_uint32_be(w, sequence_length)
    helpers.write_instruction(w, "DROP")
    helpers.write_instruction(w, "NIL")
    helpers.write_instruction(w, "operation")
    helpers.write_instruction(w, operation)
    if to_contract is True:
        helpers.write_instruction(w, "address")
    else:
        helpers.write_instruction(w, "key_hash")
    if operation == "PUSH":
        write_bytes_unchecked(w, bytes([10]))  # byte sequence
        if to_contract is True:
            write_uint32_be(w, SMART_CONTRACT_ADDRESS_LENGTH)
        else:
            write_uint32_be(w, IMPLICIT_ADDRESS_LENGTH)
Esempio n. 2
0
def _get_operation_bytes(w: bytearray, msg):
    write_bytes(w, msg.branch)

    # when the account sends first operation in lifetime,
    # we need to reveal its public key
    if msg.reveal is not None:
        _encode_common(w, msg.reveal, "reveal")
        write_bytes(w, msg.reveal.public_key)

    # transaction operation
    if msg.transaction is not None:
        _encode_common(w, msg.transaction, "transaction")
        _encode_zarith(w, msg.transaction.amount)
        _encode_contract_id(w, msg.transaction.destination)
        _encode_data_with_bool_prefix(w, msg.transaction.parameters)
    # origination operation
    elif msg.origination is not None:
        _encode_common(w, msg.origination, "origination")
        write_bytes(w, msg.origination.manager_pubkey)
        _encode_zarith(w, msg.origination.balance)
        helpers.write_bool(w, msg.origination.spendable)
        helpers.write_bool(w, msg.origination.delegatable)
        _encode_data_with_bool_prefix(w, msg.origination.delegate)
        _encode_data_with_bool_prefix(w, msg.origination.script)
    # delegation operation
    elif msg.delegation is not None:
        _encode_common(w, msg.delegation, "delegation")
        _encode_data_with_bool_prefix(w, msg.delegation.delegate)
    elif msg.proposal is not None:
        _encode_proposal(w, msg.proposal)
    elif msg.ballot is not None:
        _encode_ballot(w, msg.ballot)
Esempio n. 3
0
    def test_tezos_encode_bool(self):
        w = bytearray()
        write_bool(w, True)
        self.assertEqual(bytes(w), bytes([255]))

        w = bytearray()
        write_bool(w, False)
        self.assertEqual(bytes(w), bytes([0]))
Esempio n. 4
0
def _encode_data_with_bool_prefix(w: bytearray, data):
    if data:
        helpers.write_bool(w, True)
        write_bytes_unchecked(w, data)
    else:
        helpers.write_bool(w, False)