// Schema definition for block request/response messages.

syntax = "proto3";

package api.v1;

// Block enumeration direction.
enum Direction {
	// Enumerate in ascending order (from child to parent).
	Ascending = 0;
	// Enumerate in descending order (from parent to canonical child).
	Descending = 1;
}

// Request block data from a peer.
message BlockRequest {
	// Unique request id.
	uint64 id = 1;
	// Bits of block data to request.
	uint32 fields = 2;
	// Start from this block.
	oneof from_block {
		// Start with given hash.
		bytes hash = 3;
		// Start with given block number.
		bytes number = 4;
	}
	// End at this block. An implementation defined maximum is used when unspecified.
	bytes to_block = 5; // optional
	// Sequence direction.
	Direction direction = 6;
	// Maximum number of blocks to return. An implementation defined maximum is used when unspecified.
	uint32 max_blocks = 7; // optional
}

// Response to `BlockRequest`
message BlockResponse {
	// Id of a request this response was made for.
	uint64 id = 1;
	// Block data for the requested sequence.
	repeated BlockData blocks = 2;
}

// Block data sent in the response.
message BlockData {
	// Block header hash.
	bytes hash = 1;
	// Block header if requested.
	bytes header = 2; // optional
	// Block body if requested.
	repeated bytes body = 3; // optional
	// Block receipt if requested.
	bytes receipt = 4; // optional
	// Block message queue if requested.
	bytes message_queue = 5; // optional
	// Justification if requested.
	bytes justification = 6; // optional
}

