diff --git a/submissions/devfoma/Week-1/Summary.md b/submissions/devfoma/week-1/Summary.md similarity index 100% rename from submissions/devfoma/Week-1/Summary.md rename to submissions/devfoma/week-1/Summary.md diff --git a/submissions/devfoma/Week-1/Week-1.md b/submissions/devfoma/week-1/Week-1.md similarity index 100% rename from submissions/devfoma/Week-1/Week-1.md rename to submissions/devfoma/week-1/Week-1.md diff --git a/submissions/devfoma/Week-1/public/block-creation.jpg b/submissions/devfoma/week-1/public/block-creation.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/block-creation.jpg rename to submissions/devfoma/week-1/public/block-creation.jpg diff --git a/submissions/devfoma/Week-1/public/branch-for-submissions.jpeg b/submissions/devfoma/week-1/public/branch-for-submissions.jpeg similarity index 100% rename from submissions/devfoma/Week-1/public/branch-for-submissions.jpeg rename to submissions/devfoma/week-1/public/branch-for-submissions.jpeg diff --git a/submissions/devfoma/Week-1/public/create-wallet.jpg b/submissions/devfoma/week-1/public/create-wallet.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/create-wallet.jpg rename to submissions/devfoma/week-1/public/create-wallet.jpg diff --git a/submissions/devfoma/Week-1/public/decode-raw-txn.jpg b/submissions/devfoma/week-1/public/decode-raw-txn.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/decode-raw-txn.jpg rename to submissions/devfoma/week-1/public/decode-raw-txn.jpg diff --git a/submissions/devfoma/Week-1/public/generate-address-and-load.jpg b/submissions/devfoma/week-1/public/generate-address-and-load.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/generate-address-and-load.jpg rename to submissions/devfoma/week-1/public/generate-address-and-load.jpg diff --git a/submissions/devfoma/Week-1/public/generate-block-and-confirm-txn.jpg b/submissions/devfoma/week-1/public/generate-block-and-confirm-txn.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/generate-block-and-confirm-txn.jpg rename to submissions/devfoma/week-1/public/generate-block-and-confirm-txn.jpg diff --git a/submissions/devfoma/Week-1/public/list-wallet.jpg b/submissions/devfoma/week-1/public/list-wallet.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/list-wallet.jpg rename to submissions/devfoma/week-1/public/list-wallet.jpg diff --git a/submissions/devfoma/Week-1/public/mine-block-and-confirm-txn-and-balance.jpg b/submissions/devfoma/week-1/public/mine-block-and-confirm-txn-and-balance.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/mine-block-and-confirm-txn-and-balance.jpg rename to submissions/devfoma/week-1/public/mine-block-and-confirm-txn-and-balance.jpg diff --git a/submissions/devfoma/Week-1/public/send-test-btc-and-metadata-txn.jpg b/submissions/devfoma/week-1/public/send-test-btc-and-metadata-txn.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/send-test-btc-and-metadata-txn.jpg rename to submissions/devfoma/week-1/public/send-test-btc-and-metadata-txn.jpg diff --git a/submissions/devfoma/Week-1/public/solved-fallbackfee-error.jpg b/submissions/devfoma/week-1/public/solved-fallbackfee-error.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/solved-fallbackfee-error.jpg rename to submissions/devfoma/week-1/public/solved-fallbackfee-error.jpg diff --git a/submissions/devfoma/Week-1/public/spendable-output.jpg b/submissions/devfoma/week-1/public/spendable-output.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/spendable-output.jpg rename to submissions/devfoma/week-1/public/spendable-output.jpg diff --git a/submissions/devfoma/Week-1/public/struture-metadata.jpg b/submissions/devfoma/week-1/public/struture-metadata.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/struture-metadata.jpg rename to submissions/devfoma/week-1/public/struture-metadata.jpg diff --git a/submissions/devfoma/Week-1/public/txn-error.jpg b/submissions/devfoma/week-1/public/txn-error.jpg similarity index 100% rename from submissions/devfoma/Week-1/public/txn-error.jpg rename to submissions/devfoma/week-1/public/txn-error.jpg diff --git a/submissions/devfoma/Week-1/public/verify-download-error.jpeg b/submissions/devfoma/week-1/public/verify-download-error.jpeg similarity index 100% rename from submissions/devfoma/Week-1/public/verify-download-error.jpeg rename to submissions/devfoma/week-1/public/verify-download-error.jpeg diff --git a/submissions/devfoma/Week-1/public/verify-node-setup.jpeg b/submissions/devfoma/week-1/public/verify-node-setup.jpeg similarity index 100% rename from submissions/devfoma/Week-1/public/verify-node-setup.jpeg rename to submissions/devfoma/week-1/public/verify-node-setup.jpeg diff --git a/submissions/devfoma/week-2/Cargo.lock b/submissions/devfoma/week-2/Cargo.lock new file mode 100644 index 0000000..bfb10e0 --- /dev/null +++ b/submissions/devfoma/week-2/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "Week-2" +version = "0.1.0" diff --git a/submissions/devfoma/week-2/Cargo.toml b/submissions/devfoma/week-2/Cargo.toml new file mode 100644 index 0000000..85f9708 --- /dev/null +++ b/submissions/devfoma/week-2/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "Week-2" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/submissions/devfoma/week-2/public/tasks.png b/submissions/devfoma/week-2/public/tasks.png new file mode 100644 index 0000000..2669cd4 Binary files /dev/null and b/submissions/devfoma/week-2/public/tasks.png differ diff --git a/submissions/devfoma/week-2/src/main.rs b/submissions/devfoma/week-2/src/main.rs new file mode 100644 index 0000000..3abc141 --- /dev/null +++ b/submissions/devfoma/week-2/src/main.rs @@ -0,0 +1,22 @@ +mod task_1; +mod task_2; +mod task_3; + +fn main() { + // Example usage of task_1 function + let btc_amount = 0.5; + let exchange_rate = 30000.0; // Example exchange rate: 1 BTC = 30,000 USD + + // calling the function from task_1 module + let usd_value = task_1::btc_value_in_usd(btc_amount, exchange_rate); + println!("The value of {} BTC in USD is: ${}", btc_amount, usd_value); + + // Example usage of task_2 function + task_2::mine_blocks(12); + + // Example usage of task_3 function + let rpc_url = task_3::get_rpc_url(&task_3::Network::Mainnet); + println!("RPC URL for Mainnet: {}", rpc_url); + + +} diff --git a/submissions/devfoma/week-2/src/task_1.rs b/submissions/devfoma/week-2/src/task_1.rs new file mode 100644 index 0000000..25ed40c --- /dev/null +++ b/submissions/devfoma/week-2/src/task_1.rs @@ -0,0 +1,14 @@ +// 1. Functions and Expressions +// - Write a function `btc_value_in_usd(btc: f64, rate: f64) -> f64` that returns btc * rate. + +// Demonstrate: +// - Function return types +// - Expression blocks (no semicolons for return) +// made the function public to be accessible from main.rs + +// My Solution: +#![allow(unused)] + +pub fn btc_value_in_usd(btc: f64, rate: f64) -> f64 { + btc * rate +} diff --git a/submissions/devfoma/week-2/src/task_2.rs b/submissions/devfoma/week-2/src/task_2.rs new file mode 100644 index 0000000..36f8672 --- /dev/null +++ b/submissions/devfoma/week-2/src/task_2.rs @@ -0,0 +1,27 @@ +// 2. Control Flow & Loops +// Write a function that simulates mining blocks: + +// ``` +// fn mine_blocks(limit: u8) { +// for height in 1..=limit { +// println!("Mining block #{}", height); +// } +// } +// ``` +// - Extend it using: +// - A while loop to simulate difficulty +// - An if-else block to print “Checkpoint reached” every 5 blocks. + +// My solution: +#![allow(unused)] + +pub fn mine_blocks(limit: u8) { + let mut height = 1; + while height <= limit { + println!("Mining block #{}", height); + if height % 5 == 0 { + println!("Checkpoint reached at block #{}", height); + } + height += 1; + } +} \ No newline at end of file diff --git a/submissions/devfoma/week-2/src/task_3.rs b/submissions/devfoma/week-2/src/task_3.rs new file mode 100644 index 0000000..42b7c40 --- /dev/null +++ b/submissions/devfoma/week-2/src/task_3.rs @@ -0,0 +1,31 @@ +// 3. Enums & Pattern Matching +// Refer to this enum `Network` +// ``` +// enum Network { +// Mainnet, +// Testnet, +// Regtest, +// } +// ``` + +// - Write a `match` block that prints details about the selected network. +// - Implement a function `fn get_rpc_url(network: &Network) -> &str` that returns different URLs. + + +// My Solution: + +#![allow(unused)] + +pub enum Network{ + Mainnet, + Testnet, + Regtest, +} + +pub fn get_rpc_url(network: &Network) -> &str { + match network{ + Network::Mainnet => "https://mainnet.rpc.url", + Network::Testnet => "https://testnet.rpc.url", + Network::Regtest => "http://localhost:18443", + } +} \ No newline at end of file diff --git a/submissions/devfoma/week-2/summary.md b/submissions/devfoma/week-2/summary.md new file mode 100644 index 0000000..9b6a4bf --- /dev/null +++ b/submissions/devfoma/week-2/summary.md @@ -0,0 +1,95 @@ + +# Week 2 — Rust Fundamentals: Reflection and Summary + +## Project Structure + +This week’s assignment was organized into a modular Rust project, where each task was implemented in a separate file for clarity and reusability. + +``` +src/ +├── main.rs +├── task_1.rs +├── task_2.rs +└── task_3.rs +``` + +**main.rs** — Serves as the program entry point. Integrates all tasks and demonstrates function calls from each module. +**task_1.rs** — Contains a function for calculating the value of Bitcoin in USD. +**task_2.rs** — Implements control flow and looping logic to simulate mining blocks and reaching checkpoints. +**task_3.rs** — Defines an enum and a pattern-matching function for selecting and returning network configurations. + +This modular setup ensured clean separation of concerns, easy debugging, and scalability as more features are introduced in future weeks. + +### my implementation for all tasks + +![Screenshot for Week 2 Tasks](public/tasks.png "Tasks Output") + + +## Reflection: Summary of Learning and Debugging Process + +### What I Learned + +This week focused on developing a deeper understanding of **Rust fundamentals** through practical, Bitcoin-oriented exercises. +I learned how to structure a Rust project modularly using multiple files, apply control flow, and implement functions and enums effectively. + +Specifically, I learned how to: + +* Define and call functions with parameters and return types. +* Use **expression-based returns** to write concise and efficient code. +* Apply **loops** and **conditional logic** to simulate real-world processes such as block mining. +* Structure code across multiple files using `mod` and `pub` for modularity and reusability. +* Implement and use **enums** with **pattern matching** to manage different system states and configurations. +* Organize logic in a clean, readable way while maintaining functional separation between modules. + +By completing these tasks, I gained confidence in writing Rust code that is both functional and scalable, while also reinforcing the importance of modular architecture in system-level development. + + + +### Challenges Faced + +1. **Understanding the `mod` and `pub` Relationship** + + * Initially, I encountered visibility errors when trying to call functions defined in other files. + * **Cause:** Functions were not marked as `pub`, making them private to their modules. + * **Solution:** Used the `pub` keyword to make functions public and accessible across files, and ensured that `mod filename;` was correctly declared at the top of `main.rs`. + +2. **Borrowing and Ownership in Function Calls** + + * Some initial confusion occurred when passing references (`&`) versus owned values. + * **Cause:** Functions like `get_rpc_url()` expected borrowed references, not owned data. + * **Solution:** Reviewed Rust’s ownership and borrowing rules and passed references using `&` when necessary to satisfy the borrow checker. + +3. **Debugging Module Import Errors** + + * Encountered `unresolved import` and `cannot find module` errors during file organization. + * **Cause:** File names and paths did not match the module declarations in `main.rs`. + * **Solution:** Ensured all task files (`task_1.rs`, `task_2.rs`, `task_3.rs`) were correctly located in the `src/` directory and declared with matching module names. + +4. **Output Formatting and Readability** + + * Initially, printed outputs from different tasks looked disorganized. + * **Solution:** Added clear print statements and separators to distinguish outputs from each task, improving readability during testing. + + + +### Debugging Approach + +Throughout the exercises, I focused on understanding **why** errors occurred rather than just fixing them quickly. +My debugging strategy included: + +* Reading compiler error messages carefully to identify the root cause. +* Checking for visibility and scope issues when working across modules. +* Running `cargo check` frequently to validate the project before execution. +* Making small, incremental changes and verifying outputs after each modification. +* Consulting the official Rust documentation and examples to confirm syntax and best practices. + +This systematic approach helped me become more confident in reading compiler feedback, structuring projects, and managing modular dependencies effectively. + + +### Key Takeaway + +This week’s exercises were instrumental in building a strong foundation for developing Bitcoin-related systems in Rust. +By implementing functions, control flows, and enums within a modular architecture, I now understand how to design structured, maintainable Rust applications. + +The process improved my ability to debug logically, manage visibility across modules, and structure programs that can scale into larger projects. +Most importantly, it bridged the gap between theoretical syntax learning and **practical system implementation**, setting the stage for more advanced topics such as **ownership, borrowing, and data structures** in the coming weeks.