      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
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146

    use primitives::hash::H256;
    use ser::Serializable;
    use primitives::bytes::Bytes;
    use chain::{Transaction, IndexedTransaction, TransactionInput, TransactionOutput, OutPoint};

    #[derive(Debug, Default, Clone)]
    pub struct ChainBuilder {
    	pub transactions: Vec<Transaction>,
    }

    #[derive(Debug, Default, Clone)]
    pub struct TransactionBuilder {
    	pub transaction: Transaction,
    }

    impl ChainBuilder {
    	pub fn new() -> ChainBuilder {
    		ChainBuilder {
    			transactions: Vec::new(),
    		}
    	}

    	pub fn at(&self, transaction_index: usize) -> Transaction {
    		self.transactions[transaction_index].clone()
    	}

    	pub fn hash(&self, transaction_index: usize) -> H256 {
    		self.transactions[transaction_index].hash()
    	}

    	pub fn size(&self, transaction_index: usize) -> usize {
    		self.transactions[transaction_index].serialized_size()
    	}
    }

    impl Into<Transaction> for TransactionBuilder {
    	fn into(self) -> Transaction {
    		self.transaction
    	}
    }

    impl Into<IndexedTransaction> for TransactionBuilder {
    	fn into(self) -> IndexedTransaction {
    		IndexedTransaction {
    			hash: self.transaction.hash(),
    			raw: self.transaction,
    		}
    	}
    }

    impl TransactionBuilder {
    	pub fn with_version(version: i32) -> TransactionBuilder {
    		let builder = TransactionBuilder::default();
    		builder.set_version(version)
    	}

    	pub fn with_output(value: u64) -> TransactionBuilder {
    		let builder = TransactionBuilder::default();
    		builder.add_output(value)
    	}

    	pub fn with_default_input(output_index: u32) -> TransactionBuilder {
    		let builder = TransactionBuilder::default();
    		builder.add_input(&Transaction::default(), output_index)
    	}

    	pub fn reset(self) -> TransactionBuilder {
    		TransactionBuilder::default()
    	}

    	pub fn into_input(self, output_index: u32) -> TransactionBuilder {
    		let builder = TransactionBuilder::default();
    		builder.add_input(&self.transaction, output_index)
    	}

    	pub fn set_version(mut self, version: i32) -> TransactionBuilder {
    		self.transaction.version = version;
    		self
    	}

    	pub fn add_output(mut self, value: u64) -> TransactionBuilder {
    		self.transaction.outputs.push(TransactionOutput {
    			value: value,
    			script_pubkey: Bytes::new_with_len(0),
    		});
    		self
    	}

    	pub fn set_output(mut self, value: u64) -> TransactionBuilder {
    		self.transaction.outputs = vec![TransactionOutput {
    			value: value,
    			script_pubkey: Bytes::new_with_len(0),
    		}];
    		self
    	}

    	pub fn add_default_input(self, output_index: u32) -> TransactionBuilder {
    		self.add_input(&Transaction::default(), output_index)
    	}

    	pub fn add_input(mut self, transaction: &Transaction, output_index: u32) -> TransactionBuilder {
    		self.transaction.inputs.push(TransactionInput {
    			previous_output: OutPoint {
    				hash: transaction.hash(),
    				index: output_index,
    			},
    			script_sig: Bytes::new_with_len(0),
    			sequence: 0xffffffff,
    			script_witness: vec![],
    		});
    		self
    	}

    	pub fn set_default_input(self, output_index: u32) -> TransactionBuilder {
    		self.set_input(&Transaction::default(), output_index)
    	}

    	pub fn set_input(mut self, transaction: &Transaction, output_index: u32) -> TransactionBuilder {
    		self.transaction.inputs = vec![TransactionInput {
    			previous_output: OutPoint {
    				hash: transaction.hash(),
    				index: output_index,
    			},
    			script_sig: Bytes::new_with_len(0),
    			sequence: 0xffffffff,
    			script_witness: vec![],
    		}];
    		self
    	}

    	pub fn lock(mut self) -> Self {
    		self.transaction.inputs[0].sequence = 0;
    		self.transaction.lock_time = 500000;
    		self
    	}

    	pub fn store(self, chain: &mut ChainBuilder) -> Self {
    		chain.transactions.push(self.transaction.clone());
    		self
    	}

    	pub fn hash(self) -> H256 {
    		self.transaction.hash()
    	}
    }

# 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`)