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
14 changes: 7 additions & 7 deletions code/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// import session_3 module
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();
}
println!("\nTASK 1");
week_2::task_1::main();
println!("\nTASK 2");
week_2::task_2::main();
println!("\nTASK 3");
week_2::task_3::main();
}
Empty file removed code/src/week_2/README.md
Empty file.
42 changes: 0 additions & 42 deletions code/src/week_2/function.rs

This file was deleted.

51 changes: 0 additions & 51 deletions code/src/week_2/loops.rs

This file was deleted.

9 changes: 3 additions & 6 deletions code/src/week_2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// // import all the files within session_3
pub mod function;
pub mod loops;
pub mod primitive_types;
pub mod slices;
pub mod variables;
pub mod task_1;
pub mod task_2;
pub mod task_3;
70 changes: 0 additions & 70 deletions code/src/week_2/primitive_types.rs

This file was deleted.

45 changes: 0 additions & 45 deletions code/src/week_2/slices.rs

This file was deleted.

12 changes: 5 additions & 7 deletions code/src/week_2/task_1.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

fn btc_value_in_usd(btc: f64, rate: f64) -> f64 {
btc * rate
btc * rate
}
//main run main
fn main() {
let btc = 0.25; //a dream amount
let rate = 65_000.0; // example rate here
pub fn main() {
let btc = 1.2;
let rate = 100000.00;
let value = btc_value_in_usd(btc, rate);
println!("{} BTC is worth ${} USD", btc, value);
println!("{} BTC is worth ${}", btc, value);
}
22 changes: 13 additions & 9 deletions code/src/week_2/task_2.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
fn mine_blocks(limit: u8) {
let mut difficulty = 1;

for height in 1..=limit {
println!("Mining block #{}", height);

// Simulate difficulty
while difficulty < 3 {
println!("Simulating difficulty level {}", difficulty);
difficulty += 1; // the number of starting zero's
// E.g, Each block requires 50 more attempts than its height number
let target = height as u32 * 50;
// Attempts for each block starts at 0
let mut attempts = 0;

while attempts < target {
attempts += 1;
}

println!("Block mined after {} attempts", attempts);

// Print checkpoint after every 5 blocks
if height % 5 == 0 {
println!("Checkpoint reached");
println!("CHECKPOINT REACHED!\n")
}
}
}

fn main() {
mine_blocks(10);
pub fn main() {
mine_blocks(28);
}
40 changes: 20 additions & 20 deletions code/src/week_2/task_3.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#![allow(unused)]
enum Network {
Mainnet,
Testnet,
Regtest,
}

fn get_rpc_url(network: &Network) -> &str {
fn print_network_details(network: &Network) {
match network {
Network::Mainnet => "https://mainnet.example.com",
Network::Testnet => "https://testnet.example.com",
Network::Regtest => "http://localhost:8332",
Network::Mainnet => println!(
"Network: Bitcoin Mainnet\nType: Production network with real BTC\nPort: 28391"
),
Network::Testnet => {
println!("Network: Bitcoin Testnet\nType: Test network with test BTC\nPort: 28231")
}
Network::Regtest => println!(
"Network: Bitcoin Regtest\nType: Regression test network with test BTC\nPort: 28211"
),
}
}

fn print_network_details(network: &Network) {
fn get_rpc_url(network: &Network) -> &str {
match network {
Network::Mainnet => println!("This is the main Bitcoin network."),
Network::Testnet => println!("This is the test Bitcoin network."),
Network::Regtest => println!("This is the regtest Bitcoin network."),
Network::Mainnet => "https://bitcoinrpc:mainnet:user1:12345",
Network::Testnet => "https://bitcoinrpc:testnet:user1:12345",
Network::Regtest => "https://bitcoinrpc:regtest:user1:12345",
}
}

fn main() {
let network = Network::Regtest;

print_network_details(&network);
println!("RPC URL: {}", get_rpc_url(&network));
let network = Network::Mainnet;

print_network_details(&network);
println!("RPC URL: {}", get_rpc_url(&network));
let network = Network::Testnet;
pub fn main() {
let network_1 = Network::Mainnet;
let network_2 = Network::Regtest;

print_network_details(&network);
println!("RPC URL: {}", get_rpc_url(&network));
print_network_details(&network_1);
println!("{}", get_rpc_url(&network_2));
}
Loading