Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.94 KB

File metadata and controls

56 lines (43 loc) · 1.94 KB

Rust for Bitcoin 2.0 — Week 2

Build a simplified Bitcoin transaction model while practising structs, enums, traits, ownership, borrowing, collections, and Result-based error handling.

The crate is intentionally incomplete. Search for TODO and implement each part; do not change the public type names or function signatures.

Recommended workflow

  1. Read ASSIGNMENT.md.
  2. Complete Parts 3–5 in transaction.rs and error.rs.
  3. Remove #[ignore] from the relevant test and run it.
  4. Complete the traits and borrowing functions in Parts 6–7.
  5. Build the payment example in main.rs.
  6. Complete UTXO selection and its tests.
  7. Add the remaining required tests yourself.
cargo test
cargo test -- --ignored
cargo run
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings

cargo test checks the starter project. Ignored tests intentionally exercise unfinished code; enable them progressively rather than leaving them ignored in the submission.

Written answers

Answer in your own words. Add the ownership compiler error from Part 7 as a fenced text block, then explain what caused it.

  1. What is a Bitcoin transaction input?
  2. What is a Bitcoin transaction output?
  3. What is a UTXO?
  4. What does an outpoint identify?
  5. How is a transaction fee calculated?
  6. Why use integers rather than floating-point numbers for bitcoin amounts?
  7. Why does total_input_value() borrow self?
  8. Why does add_input() take &mut self?
  9. What happens when an input is moved into a transaction?
  10. Why is Result preferable to panic! for validation failures?
  11. How do enums help model regular and coinbase inputs?
  12. How does the BitcoinValue trait reduce duplication?

Design notes

Describe any choices you made, including your UTXO-selection trade-offs and (if attempted) the optional transaction-state extension.

Example output

Paste the output of cargo run here once Part 8 is complete.