def _encode_manager_delegation(w: bytearray, delegate): MICHELSON_LENGTH = 42 # length is fixed this time(no variable length fields) _encode_manager_common(w, MICHELSON_LENGTH, "PUSH") write_bytes_unchecked(w, delegate) helpers.write_instruction(w, "SOME") helpers.write_instruction(w, "SET_DELEGATE") helpers.write_instruction(w, "CONS")
def _encode_manager_to_manager_transfer(w: bytearray, manager_transfer): MICHELSON_LENGTH = 77 value_natural = bytearray() _encode_natural(value_natural, manager_transfer.amount) sequence_length = MICHELSON_LENGTH + len(value_natural) _encode_manager_common(w, sequence_length, "PUSH", to_contract=True) _encode_contract_id(w, manager_transfer.destination) helpers.write_instruction(w, "CONTRACT") helpers.write_instruction(w, "unit") helpers.write_instruction(w, "ASSERT_SOME") helpers.write_instruction(w, "PUSH") helpers.write_instruction(w, "mutez") _encode_natural(w, manager_transfer.amount) helpers.write_instruction(w, "UNIT") helpers.write_instruction(w, "TRANSFER_TOKENS") helpers.write_instruction(w, "CONS")
def _encode_manager_delegation_remove(w: bytearray): MICHELSON_LENGTH = 14 # length is fixed this time(no variable length fields) _encode_manager_common(w, MICHELSON_LENGTH, "NONE") helpers.write_instruction(w, "SET_DELEGATE") helpers.write_instruction(w, "CONS")
def _encode_manager_to_implicit_transfer(w: bytearray, manager_transfer): MICHELSON_LENGTH = 48 value_natural = bytearray() _encode_natural(value_natural, manager_transfer.amount) sequence_length = MICHELSON_LENGTH + len(value_natural) _encode_manager_common(w, sequence_length, "PUSH") write_bytes_unchecked(w, manager_transfer.destination.hash) helpers.write_instruction(w, "IMPLICIT_ACCOUNT") helpers.write_instruction(w, "PUSH") helpers.write_instruction(w, "mutez") _encode_natural(w, manager_transfer.amount) helpers.write_instruction(w, "UNIT") helpers.write_instruction(w, "TRANSFER_TOKENS") helpers.write_instruction(w, "CONS")
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)