     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75

    use std::collections::HashSet;

    /// Block template request mode
    #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
    pub enum BlockTemplateRequestMode {
    	/// Work as described in BIP0022:
    	/// https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki
    	#[serde(rename="template")]
    	Template,
    	/// Work as described in BIP0023:
    	/// https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki
    	#[serde(rename="proposal")]
    	Proposal,
    }

    /// Block template request parameters as described in:
    /// https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki
    /// https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki
    /// https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes
    /// https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki
    #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, Clone)]
    pub struct BlockTemplateRequest {
    	/// Request mode
    	pub mode: Option<BlockTemplateRequestMode>,
    	/// Capabilities, supported by client
    	pub capabilities: Option<HashSet<String>>,
    	/// Softfork deployments, supported by client
    	pub rules: Option<HashSet<String>>,
    }

    #[cfg(test)]
    mod tests {
    	use serde_json;
    	use super::*;

    	#[test]
    	fn block_template_request_mode_serialize() {
    		assert_eq!(serde_json::to_string(&BlockTemplateRequestMode::Template).unwrap(), r#""template""#);
    		assert_eq!(serde_json::to_string(&BlockTemplateRequestMode::Proposal).unwrap(), r#""proposal""#);
    	}

    	#[test]
    	fn block_template_request_mode_deserialize() {
    		assert_eq!(serde_json::from_str::<BlockTemplateRequestMode>(r#""template""#).unwrap(), BlockTemplateRequestMode::Template);
    		assert_eq!(serde_json::from_str::<BlockTemplateRequestMode>(r#""proposal""#).unwrap(), BlockTemplateRequestMode::Proposal);
    	}

    	#[test]
    	fn block_template_request_serialize() {
    		assert_eq!(serde_json::to_string(&BlockTemplateRequest::default()).unwrap(), r#"{"mode":null,"capabilities":null,"rules":null}"#);
    		assert_eq!(serde_json::to_string(&BlockTemplateRequest {
    			mode: Some(BlockTemplateRequestMode::Template),
    			capabilities: Some(vec!["a".to_owned()].into_iter().collect()),
    			rules: Some(vec!["b".to_owned()].into_iter().collect()),
    		}).unwrap(), r#"{"mode":"template","capabilities":["a"],"rules":["b"]}"#);
    	}

    	#[test]
    	fn block_template_request_deserialize() {
    		assert_eq!(
    			serde_json::from_str::<BlockTemplateRequest>(r#"{"mode":null,"capabilities":null,"rules":null}"#).unwrap(),
    			BlockTemplateRequest {
    				mode: None,
    				capabilities: None,
    				rules: None,
    			});
    		assert_eq!(
    			serde_json::from_str::<BlockTemplateRequest>(r#"{"mode":"template","capabilities":["a"],"rules":["b"]}"#).unwrap(),
    			BlockTemplateRequest {
    				mode: Some(BlockTemplateRequestMode::Template),
    				capabilities: Some(vec!["a".to_owned()].into_iter().collect()),
    				rules: Some(vec!["b".to_owned()].into_iter().collect()),
    			});
    	}
    }

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)