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
3 changes: 3 additions & 0 deletions submissions/toyin5/week-2/task_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn btc_value_in_usd(btc: f64, rate: f64) -> f64{
return btc * rate;
}
27 changes: 27 additions & 0 deletions submissions/toyin5/week-2/task_2.rs
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions submissions/toyin5/week-2/task_3.rs
Original file line number Diff line number Diff line change
@@ -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!("-------------------");
}
}