diff --git a/submissions/toyin5/week-2/task_1.rs b/submissions/toyin5/week-2/task_1.rs new file mode 100644 index 0000000..273bb7a --- /dev/null +++ b/submissions/toyin5/week-2/task_1.rs @@ -0,0 +1,3 @@ +fn btc_value_in_usd(btc: f64, rate: f64) -> f64{ + return btc * rate; +} \ No newline at end of file diff --git a/submissions/toyin5/week-2/task_2.rs b/submissions/toyin5/week-2/task_2.rs new file mode 100644 index 0000000..8a03a2c --- /dev/null +++ b/submissions/toyin5/week-2/task_2.rs @@ -0,0 +1,27 @@ +fn mine_blocks(limit: u8) { + for height in 1..=limit { + println!("Mining block #{}", height); + let difficulty: u64 = (height as u64 / 2).saturating_add(2); + println!("Difficulty set to {}", difficulty); + + + let mut attempts: u64 = 1; + while attempts % difficulty != 0 { + attempts += 1; + } + println!("Block #{} mined after {} attempts", height, attempts); + + if is_a_product_of_5(height as u32) { + println!("Block #{}. Checkpoint reached", height); + } + } +} + +fn main() { + let block_limit = 10; + mine_blocks(block_limit); +} + +fn is_a_product_of_5(n: u32) -> bool { + n % 5 == 0 +} \ No newline at end of file diff --git a/submissions/toyin5/week-2/task_3.rs b/submissions/toyin5/week-2/task_3.rs new file mode 100644 index 0000000..ef4bf6d --- /dev/null +++ b/submissions/toyin5/week-2/task_3.rs @@ -0,0 +1,28 @@ +enum Network { + Mainnet, + Testnet, + Regtest, +} + +fn get_rpc_url(network: &Network) -> &str { + match network { + Network::Mainnet => "https://localhost:8332", + Network::Testnet => "https://localhost:18332", + Network::Regtest => "https://localhost:18443", + } +} + +fn main() { + let networks = [Network::Mainnet, Network::Testnet, Network::Regtest]; + + for network in networks.iter() { + match network { + Network::Mainnet => println!("Connected to Bitcoin Mainnet - Main Environment"), + Network::Testnet => println!("Connected to Bitcoin Testnet - Testing Environment"), + Network::Regtest => println!("Connected to Bitcoin Regtest - Local Development"), + } + println!("RPC URL: {}", get_rpc_url(network)); + println!("-------------------"); + } +} +