Skip to content

Commit

Permalink
separated function
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravm committed Apr 11, 2024
1 parent ac55073 commit 50b0a71
Show file tree
Hide file tree
Showing 88 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions foo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ fn hex_to_little_endian(hex_number: &str) -> String {
hex::encode(little_endian_bytes)
}

fn main() {
let mut f = File::open("../mempool/0ac528562a1626863c0cb912eb725530c54e786e6485380c16633e4b9bce1720.json").unwrap();
let mut data = String::new();
f.read_to_string(&mut data).unwrap();
let data: serde_json::Value = serde_json::from_str(&data).unwrap();

fn create_transaction(data: serde_json::Value) -> String {
let mut raw_transaction = String::new();

let version = format!("{:08x}", data["version"].as_u64().unwrap());
Expand Down Expand Up @@ -69,29 +64,33 @@ fn main() {
raw_transaction += sighash_all;


let signature = data["vin"][0]["scriptsig_asm"].as_str().unwrap().split_whitespace().nth(1).unwrap();
let signature = &signature[..signature.len() - 2];

let pub_key = data["vin"][0]["scriptsig_asm"].as_str().unwrap().split_whitespace().nth(3).unwrap();

let data1 = Vec::from_hex(raw_transaction).unwrap();
let sha256_hash1 = Sha256::digest(&data1).to_vec();

let data2 = sha256_hash1;
let hash_hex1 = Sha256::digest(&data2).to_vec();

let hex = hex::encode(hash_hex1);
let hash_hex: &str = hex.as_str();
hex
}

fn main() {
let mut f = File::open("../mempool/0ac528562a1626863c0cb912eb725530c54e786e6485380c16633e4b9bce1720.json").unwrap();
let mut data = String::new();
f.read_to_string(&mut data).unwrap();
let data: serde_json::Value = serde_json::from_str(&data).unwrap();

// println!("sha256_hash: {}", (hash_hex));
let hex= create_transaction(data.clone());
let hash_hex: &str = hex.as_str();

let secp = Secp256k1::new();

// Decode the signature, public key, and hash
// let signature = "30440220200b9a61529151f9f264a04e9aa17bb6e1d53fb345747c44885b1e185a82c17502200e41059f8ab4d3b3709dcb91b050c344b06c5086f05598d62bc06a8b746db429";
let signature = data["vin"][0]["scriptsig_asm"].as_str().unwrap().split_whitespace().nth(1).unwrap();
let signature = &signature[..signature.len() - 2];
let signature_bytes = decode(signature).expect("Failed to decode signature hex");

// let pub_key = "025f0ba0cdc8aa97ec1fffd01fac34d3a7f700baf07658048263a2c925825e8d33";
let pub_key = data["vin"][0]["scriptsig_asm"].as_str().unwrap().split_whitespace().nth(3).unwrap();
let pubkey_bytes = decode(pub_key).expect("Failed to decode pubkey hex");
let pubkey = PublicKey::from_slice(&pubkey_bytes).expect("Invalid public key");

Expand Down
2 changes: 1 addition & 1 deletion foo/target/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"rustc_fingerprint":13052377172341671592,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/aarav/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.75.0 (82e1608df 2023-12-21)\nbinary: rustc\ncommit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112\ncommit-date: 2023-12-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.75.0\nLLVM version: 17.0.6\n","stderr":""}},"successes":{}}
{"rustc_fingerprint":3873439692611108760,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/aarav/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.75.0 (82e1608df 2023-12-21)\nbinary: rustc\ncommit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112\ncommit-date: 2023-12-21\nhost: x86_64-unknown-linux-gnu\nrelease: 1.75.0\nLLVM version: 17.0.6\n","stderr":""}},"successes":{}}
Binary file modified foo/target/debug/deps/foo-16b23fee036e51ee
Binary file not shown.
Binary file modified foo/target/debug/foo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 50b0a71

Please sign in to comment.