Skip to content

Commit e95b2ff

Browse files
committed
Minor text edit
1 parent 2670e9c commit e95b2ff

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

12_reading_inputs_and_type_coercion.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# Reading Inputs and Type Coercion
22

33
Each input in a transaction contains the following information:
4-
* previous output txid (32 bytes length)
5-
* previous output index (4 bytes length, represented as a u32 integer)
6-
* ScriptSig (variable length preceded by compact size integer)
7-
* sequence (4 bytes length, represented as a u32 integer)
4+
* the previous output txid (32 bytes length)
5+
* the previous output index (4 bytes length, represented as a u32 integer)
6+
* a ScriptSig (variable length preceded by compact size integer)
7+
* a sequence number (4 bytes length, represented as a u32 integer).
88

9-
The ScriptSig can be a variable length and so is preceded by a compact size integer which indicates the length of the field in bytes.
10-
Prior to Segwit, the ScriptSig was where the signature would be provided for unlocking the funds of the referenced output (as indicated by the previous output txid and previous output index).
9+
The ScriptSig can be have variable length and so is preceded by a compact size integer which indicates the length of the field in bytes.
10+
Prior to Segwit, the ScriptSig was where a digital signature would be provided for unlocking the funds of the referenced output (as indicated by the previous output txid and previous output index).
1111
Now, for Segwit transactions, this field is empty with a compact size length of 0x00 as the signature is no longer contained in the input data, but is instead "*segregated*" from the rest of the transaction in a separate witness field.
1212
For more information on SegWit, see [this section](https://github.com/bitcoinbook/bitcoinbook/blob/6d1c26e1640ae32b28389d5ae4caf1214c2be7db/ch06_transactions.adoc#segregated-witness) from Mastering Bitcoin, Chapter 6.
1313

14-
So let's update our code.
15-
We have the input length now so we know how many times to read the input information.
14+
We already have the input length so we know how many times to read the input information.
1615
We'll start by using a for loop and iterate over a range.
1716
Since we don't need the range index number, we can just replace the unused variable with an underscore, `_`.
1817
More details on loops in Rust can be [found here](https://doc.rust-lang.org/book/ch03-05-control-flow.html#looping-through-a-collection-with-for).
@@ -117,7 +116,8 @@ https://doc.rust-lang.org/std/io/trait.Read.html#tymethod.read
117116

118117
This is interesting.
119118
Technically, it only accepts a mutable reference to a slice.
120-
But we've actually been passing in a mutable reference to an array! Remember an array is a fixed size of type `[u8; n]` and not a slice of type `[u8]`.
119+
But we've actually been passing in a mutable reference to an array!
120+
Remember an array is a fixed size of type `[u8; n]` and not a slice of type `[u8]`.
121121
So how has this been working at all?
122122
I thought we had to be explicit with types in Rust?
123123

@@ -148,7 +148,7 @@ fn read_script(transaction_bytes: &mut &[u8]) -> Vec<u8> {
148148
}
149149
```
150150

151-
Lastly, we need to read the sequence, which are the last 4 bytes.
151+
Lastly, we need to read the the last 4 bytes for the sequence number.
152152
A description of what the sequence number represents can be found in Mastering Bitcoin, Chapter 6.
153153

154154
```rust
@@ -162,7 +162,8 @@ A description of what the sequence number represents can be found in Mastering B
162162
...
163163
```
164164

165-
Alright, now that we have each of the components of an input, what should we do with it? It makes sense to collect all this data together into one unified structure rather than just separate variables.
165+
Alright, now that we have each of the components of an input, what should we do with it?
166+
It makes sense to collect all this data together into one unified structure rather than just separate variables.
166167
The right type for this is Rust's `Struct` type, which we'll explore in the next lesson.
167168
Onwards!
168169

0 commit comments

Comments
 (0)