Any hero need a rest. After this lesson you will learn how contract's understand instructions based on received messages. You are going to learn how to accept messages and revert them.

Let's hit the road!

Think back in advance

As you know from previous parts, your communication with a spaceship is based on sending messages. The account receives a slice, (partial) fingerprint of the cell with your message and processes it in the recv_external. You can't modify this slice but read and decide whether to accept it and execute other actions (and pay for it) or not.

The received slice contains only the message body - arbitrary data you add to required. You are free to design its structure and that's what we are about to do.

You are going to prove that you know the pilot's password and provide the data of the internal message to be sent to the outer space. Then the message body should contain:

Reading the message

The first argument of recv_external is slice in_msg. You already know how to read the data. Just to remind:

	slice a = in_msg~load_bits(256); 
	cell b = in_msg~load_ref();
  var res = (in_msg~load_ref(), 
		in_msg~load_uint(32),
		in_msg~load_uint(256),
		in_msg~load_dict());

Be or not to be

Imagine your spaceship successfully listen to external messages and even understand received parameters. But what if they are wrong? What if not your but Alien signed the data and try to control your creation?

The throw_if(int exit_code, int condition) and throw_unless(int exit_code, int condition) may pretty handful in this case. The first argument is the error code that is returned if the condition in the second parameter is true (for throw_if) or false (for throw_unless).

Lets test something:

	throw_if(32, action);
	throw_if(41, (cnt < k) & (bound + ((60 * 60) << 32) > query_id));
	throw_unless(40, cs~load_uint(8) == 0x12);
	throw_unless(44, msg_value);