Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
mod week_2;

// entry point to run all topics covered

fn main() {
// call functions from session_3 modules
week_2::function::run();
week_2::loops::run();
week_2::primitive_types::run();
week_2::greg_task_2::mine_blocks(10);

week_2::greg_task_3::get_rpc_url(&week_2::greg_task_3::Network::Mainnet);

}
4 changes: 4 additions & 0 deletions code/src/week_2/greg_task_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn btc_value_in_usd(btc: f64, rate: f64) -> f64{
btc * rate
}
fn main(){}
17 changes: 17 additions & 0 deletions code/src/week_2/greg_task_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub fn mine_blocks(limit: u8) {
let mut difficulty = 1;

for height in 1..=limit {
println!("Mining block #{}", height);
while difficulty < 5 {
difficulty += 1
}

if height % 5 == 0 {
println!("Checkpoint reached");
} else {
let block_after_checkpoint=height % 5;
println!("blocks after check Point #{block_after_checkpoint}");
}
}
}
13 changes: 13 additions & 0 deletions code/src/week_2/greg_task_3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub enum Network {
Mainnet,
Testnet,
Regtest,
}

pub fn get_rpc_url(network: &Network) -> &str {
match network {
Network::Mainnet => "https//btc_mainnet_rpc.com",
Network::Regtest => "https//btc_Regtest_rpc.com",
Network::Testnet => "https//btc_testnet_rpc.com",
}
}
5 changes: 4 additions & 1 deletion code/src/week_2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ pub mod function;
pub mod loops;
pub mod primitive_types;
pub mod slices;
pub mod variables;
pub mod variables;
pub mod greg_task_1;
pub mod greg_task_2;
pub mod greg_task_3;