diff --git a/bitcoin-hashing-toolkit-project/Cargo.lock b/bitcoin-hashing-toolkit-project/Cargo.lock new file mode 100644 index 0000000..269973e --- /dev/null +++ b/bitcoin-hashing-toolkit-project/Cargo.lock @@ -0,0 +1,419 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "base58" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" + +[[package]] +name = "bitcoin-do" +version = "0.1.1" +dependencies = [ + "base58", + "clap", + "hex", + "owo-colors", + "ripemd", + "secp256k1", + "sha2", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cc" +version = "1.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "clap" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "libc" +version = "0.2.178" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "owo-colors" +version = "4.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest", +] + +[[package]] +name = "secp256k1" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" +dependencies = [ + "rand", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +dependencies = [ + "cc", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "zerocopy" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/bitcoin-hashing-toolkit-project/Cargo.toml b/bitcoin-hashing-toolkit-project/Cargo.toml new file mode 100644 index 0000000..44dd6c4 --- /dev/null +++ b/bitcoin-hashing-toolkit-project/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "bitcoin-do" +version = "0.1.1" +edition = "2021" +description = "A CLI tool and Rust library for Bitcoin cryptography operations including SHA256, RIPEMD160, HASH160, secp256k1 key generation, and address derivation" +license = "MIT" +keywords = ["bitcoin", "cryptography", "crypto", "blockchain", "secp256k1"] +categories = ["cryptography", "development-tools"] + +[dependencies] +clap = { version = "4.5.39", features = ["derive"]} +owo-colors = "4.2.1" +sha2 = "0.10" +ripemd = "0.1" +secp256k1 = { version = "0.29", features = ["rand-std"]} +base58 = "0.2" +hex = "0.4" \ No newline at end of file diff --git a/bitcoin-hashing-toolkit-project/README.md b/bitcoin-hashing-toolkit-project/README.md new file mode 100644 index 0000000..806a815 --- /dev/null +++ b/bitcoin-hashing-toolkit-project/README.md @@ -0,0 +1,62 @@ +# Bitcoin-do + +A CLI tool and Rust library for Bitcoin-related cryptography operations. + +## Features + +- **SHA256**: Compute SHA256 hash of input data +- **RIPEMD160**: Compute RIPEMD160 hash of input data +- **HASH160**: Compute HASH160 (RIPEMD160 of SHA256) of input data +- **Key Generation**: Generate secp256k1 keypairs +- **Address Derivation**: Derive P2PKH Bitcoin addresses from public keys + +## Installation + +### As a CLI Tool + +```bash +cargo install bitcoin-do +``` + +### As a Library + +Add to your `Cargo.toml`: + +```toml +[dependencies] +bitcoin-do = "0.1.2" +``` + +## Usage + +### CLI Examples + +Generate a new keypair: + +```bash +bitcoin-do generate-key +``` + +Derive address from public key: + +```bash +bitcoin-do derive-address 02... +``` + +Hash some data (hex input): + +```bash +bitcoin-do sha256 68656c6c6f +``` + +```bash +bitcoin-do Hash160 68656c6c6f +``` + +```bash +bitcoin-do Ripemd160 68656c6c6f +``` + +## License + +MIT diff --git a/bitcoin-hashing-toolkit-project/src/lib.rs b/bitcoin-hashing-toolkit-project/src/lib.rs new file mode 100644 index 0000000..463741e --- /dev/null +++ b/bitcoin-hashing-toolkit-project/src/lib.rs @@ -0,0 +1,62 @@ +use secp256k1::{Secp256k1, SecretKey, PublicKey}; +use sha2::{Sha256, Digest}; +use ripemd::Ripemd160; +use base58::ToBase58; +use hex; + +// Compute SHA256 hash of input data and return as hex string +pub fn sha256(data: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(data); + let result = hasher.finalize(); + hex::encode(result) +} + +// Compute RIPEMD160 hash of input data and return as hex string +pub fn ripemd160(data: &[u8]) -> String { + let mut hasher = Ripemd160::new(); + hasher.update(data); + let result = hasher.finalize(); + hex::encode(result) +} + +// Compute HASH160 (RIPEMD160 of SHA256) of input data and return as hex string +pub fn hash160(data: &[u8]) -> String { + let sha = sha2::Sha256::digest(data); + let mut ripemd = Ripemd160::new(); + ripemd.update(sha); + let result = ripemd.finalize(); + hex::encode(result) +} + +// Generate a new secp256k1 keypair +pub fn generate_keypair() -> (SecretKey, PublicKey) { + let secp = Secp256k1::new(); + let (secret_key, public_key) = secp.generate_keypair(&mut secp256k1::rand::thread_rng()); + (secret_key, public_key) +} + +// Derive Bitcoin P2PKH address from public key (compressed) +pub fn derive_address(public_key: &PublicKey) -> String { + let compressed_pubkey = public_key.serialize(); + let hash160 = hash160(&compressed_pubkey); + let hash160_bytes = hex::decode(&hash160).unwrap(); + + // Version byte for mainnet P2PKH + let mut address_bytes = vec![0x00]; + address_bytes.extend(&hash160_bytes); + + // Checksum: first 4 bytes of sha256(sha256(address_bytes)) + let checksum = { + let mut hasher = Sha256::new(); + hasher.update(&address_bytes); + let hash1 = hasher.finalize(); + let mut hasher2 = Sha256::new(); + hasher2.update(&hash1); + let hash2 = hasher2.finalize(); + hash2[..4].to_vec() + }; + + address_bytes.extend(&checksum); + address_bytes.to_base58() +} \ No newline at end of file diff --git a/bitcoin-hashing-toolkit-project/src/main.rs b/bitcoin-hashing-toolkit-project/src/main.rs new file mode 100644 index 0000000..882d936 --- /dev/null +++ b/bitcoin-hashing-toolkit-project/src/main.rs @@ -0,0 +1,94 @@ +use clap::{Parser, Subcommand}; +use owo_colors::OwoColorize; +use bitcoin_do::{sha256, ripemd160, hash160, generate_keypair, derive_address}; +use secp256k1::PublicKey; +use hex; + +#[derive(Parser)] +#[command(name = "bitcoin-do")] +#[command(about = "This tool provides essential cryptograpic functions for Bitcoin development: +- Hashing functions: SHA256, RIPEMD160, HASH160 +- Key generation: secp256k1 keypairs +- Address derivation: P2PKH Bitcoin addresses + +Examples: + Generate a new keypair: + bitcoin-do generate-key + + Derive address from public key: + bitcoin-do derive-address 02... + + Hash some data: + bitcoin-do sha256 68656c6c6f")] + +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + // Compute SHA256 hash of hex data + Sha256 { data: String }, + // Compute RIPEMD160 hash of hex data + Ripemd160 { data: String }, + // Compute HASH160 (RIPEMD160 of SHA256) of hex dat + Hash160 { data: String }, + // Generate a new secp256k1 keypair + GenerateKey, + // Derive Bitcoin address from public key (hex) + DeriveAddress { pubkey: String }, +} + +fn main() { + let cli = Cli::parse(); + + match cli.command { + Commands::Sha256 { data } => { + match hex::decode(&data) { + Ok(bytes) => { + let hash = sha256(&bytes); + println!("Your SHA256: {}", hash.green()); + } + Err(_) => eprintln!("{}", "Invalid hex data".red()), + } + } + Commands::Ripemd160 { data } => { + match hex::decode(&data) { + Ok(bytes) => { + let hash = ripemd160(&bytes); + println!("Your RIPEMD160: {}", hash.green()); + } + Err(_) => eprintln!("{}", "Invalid hex data".red()), + } + } + Commands::Hash160 { data } => { + match hex::decode(&data) { + Ok(bytes) => { + let hash = hash160(&bytes); + println!("Your HASH160: {}", hash.green()); + } + Err(_) => eprintln!("{}", "Invalid hex data".red()), + } + } + Commands::GenerateKey => { + let (priv_key, pub_key) = generate_keypair(); + println!("Your Bitcoin Private Key: {}", hex::encode(priv_key.secret_bytes()).yellow()); + println!("Your Bitcoin Public Key: {}", hex::encode(pub_key.serialize()).cyan()); + } + Commands::DeriveAddress { pubkey } => { + match hex::decode(&pubkey) { + Ok(bytes) => { + match PublicKey::from_slice(&bytes){ + Ok(pk) => { + let address = derive_address(&pk); + println!("Your Bitcoin Address: {}", address.magenta()); + } + Err(_) => eprintln!("{}", "Invalid public key".red()), + } + } + Err(_) => eprintln!("{}", "Invalid hex public key".red()), + } + } + } +} diff --git a/code/Cargo.lock b/code/Cargo.lock index a4ee902..dc11edc 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -3,5 +3,5 @@ version = 4 [[package]] -name = "rust_for_bitcoin" +name = "Tosin_week2_assignment" version = "0.1.0" diff --git a/code/Cargo.toml b/code/Cargo.toml index 4f9a0c1..b6e1549 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust_for_bitcoin" +name = "Tosin_week2_assignment" version = "0.1.0" edition = "2024" diff --git a/code/src/main.rs b/code/src/main.rs index b59e34c..6f833a0 100644 --- a/code/src/main.rs +++ b/code/src/main.rs @@ -1,3 +1,34 @@ +mod task1; +mod task2; +mod task3; + +use task1::btc_value_in_usd; +use task2::mine_blocks; +use task3::{get_rpc_url, Network }; + + +fn main() { + println!("Hello, world!"); + + println!("Task 1"); + let btc_val = 0.5; + let rate = 115_194.75; + let btc_usd = btc_value_in_usd(btc_val, rate); + println!("The price of {btc_val} in usd is {btc_usd}"); + + println!("Task 2"); + mine_blocks(15); + + println!("Task 3"); + let network = Network::Mainnet; + let rpc = get_rpc_url(&network); + println!("The rpc of mainnet is {rpc}"); + + let network = Network::Testnet; + let rpc = get_rpc_url(&network); + println!("The rpc of testnet is {rpc}"); + + // import week_2 module mod week_2; // entry point to run all topics covered diff --git a/code/src/week_2/task_1.rs b/code/src/week_2/task_1.rs index 831f186..b12c1b0 100644 --- a/code/src/week_2/task_1.rs +++ b/code/src/week_2/task_1.rs @@ -2,6 +2,7 @@ pub fn btc_value_in_usd(btc: f64, rate: f64) -> f64 { btc * rate } + //main run main pub fn main() { let btc = 0.25; //a dream amount diff --git a/code/src/week_2/task_2.rs b/code/src/week_2/task_2.rs index 138bd95..c1a2251 100644 --- a/code/src/week_2/task_2.rs +++ b/code/src/week_2/task_2.rs @@ -1,21 +1,22 @@ -fn mine_blocks(limit: u8) { +pub fn mine_blocks(limit: u8) { let mut difficulty = 1; - for height in 1..=limit { - println!("Mining block #{}", height); + for height in 0..limit { + let block_no = height + 1; + println!("Mining block #{block_no}"); - // Simulate difficulty - while difficulty < 3 { - println!("Simulating difficulty level {}", difficulty); - difficulty += 1; // the number of starting zero's + while difficulty < height { + difficulty += 1; + println!("Simluating difficulty {difficulty}"); + println!(" "); } if height % 5 == 0 { - println!("Checkpoint reached"); + println!("Checkpoint reached ✅"); + println!(" "); } - } -} + } pub fn main() { mine_blocks(10); } diff --git a/code/src/week_2/task_3.rs b/code/src/week_2/task_3.rs index 7353608..0671f10 100644 --- a/code/src/week_2/task_3.rs +++ b/code/src/week_2/task_3.rs @@ -1,16 +1,17 @@ -enum Network { +pub enum Network { Mainnet, Testnet, - Regtest, + Regtest } -fn get_rpc_url(network: &Network) -> &str { +pub fn get_rpc_url(network : &Network) -> &str { match network { - Network::Mainnet => "https://mainnet.example.com", - Network::Testnet => "https://testnet.example.com", - Network::Regtest => "http://localhost:8332", + Network::Mainnet => "https://a_mainnet_rpc_url.com", + Network::Testnet => "https://a_testnet_rpc_url.com", + Network::Regtest => "https://a_regtest_rpc_url.com", } } +} fn print_network_details(network: &Network) { match network {