// Schema definition for light client messages.

syntax = "proto3";

package api.v1.light;

// A pair of arbitrary bytes.
message Pair {
	// The first element of the pair.
	bytes fst = 1;
	// The second element of the pair.
	bytes snd = 2;
}

// Enumerate all possible light client request messages.
message Request {
	// Unique request id.
	uint64 id = 1;
	oneof request {
		RemoteCallRequest remote_call_request = 2;
		RemoteReadRequest remote_read_request = 3;
		RemoteHeaderRequest remote_header_request = 4;
		RemoteReadChildRequest remote_read_child_request = 5;
		RemoteChangesRequest remote_changes_request = 6;
	}
}

// Enumerate all possible light client response messages.
message Response {
	/// Id of a request this response was made for.
	uint64 id = 1;
	oneof response {
		RemoteCallResponse remote_call_response = 2;
		RemoteReadResponse remote_read_response = 3;
		RemoteHeaderResponse remote_header_response = 4;
		RemoteChangesResponse remote_changes_response = 6;
	}
}

// Remote call request.
message RemoteCallRequest {
	// Block at which to perform call.
	bytes block = 2;
	// Method name.
	string method = 3;
	// Call data.
	bytes data = 4;
}

// Remote call response.
message RemoteCallResponse {
	// Execution proof.
	bytes proof = 2;
}

// Remote storage read request.
message RemoteReadRequest {
	// Block at which to perform call.
	bytes block = 2;
	// Storage keys.
	repeated bytes keys = 3;
}

// Remote read response.
message RemoteReadResponse {
	// Read proof.
	bytes proof = 2;
}

// Remote storage read child request.
message RemoteReadChildRequest {
	// Block at which to perform call.
	bytes block = 2;
	// Child Storage key.
	bytes storage_key = 3;
	// Child trie source information.
	bytes child_info = 4;
	/// Child type, its required to resolve `child_info`
	/// content and choose child implementation.
	uint32 child_type = 5;
	// Storage keys.
	repeated bytes keys = 6;
}

// Remote header request.
message RemoteHeaderRequest {
	// Block number to request header for.
	bytes block = 2;
}

// Remote header response.
message RemoteHeaderResponse {
	// Header. None if proof generation has failed (e.g. header is unknown).
	bytes header = 2; // optional
	// Header proof.
	bytes proof = 3;
}

/// Remote changes request.
message RemoteChangesRequest {
	// Hash of the first block of the range (including first) where changes are requested.
	bytes first = 2;
	// Hash of the last block of the range (including last) where changes are requested.
	bytes last = 3;
	// Hash of the first block for which the requester has the changes trie root. All other
	// affected roots must be proved.
	bytes min = 4;
	// Hash of the last block that we can use when querying changes.
	bytes max = 5;
	// Storage child node key which changes are requested.
	bytes storage_key = 6; // optional
	// Storage key which changes are requested.
	bytes key = 7;
}

// Remote changes response.
message RemoteChangesResponse {
	// Proof has been generated using block with this number as a max block. Should be
	// less than or equal to the RemoteChangesRequest::max block number.
	bytes max = 2;
	// Changes proof.
	repeated bytes proof = 3;
	// Changes tries roots missing on the requester' node.
	repeated Pair roots = 4;
	// Missing changes tries roots proof.
	bytes roots_proof = 5;
}

