From 5358696d79dea5fcbb8ce8a255f6b4ae7888fcda Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 29 May 2023 23:44:25 -0700 Subject: [PATCH] add remainder of routes to use --- src/main.rs | 7 ++++-- src/routes/address.rs | 4 ++++ src/routes/block.rs | 21 ++++++++++++----- src/routes/mod.rs | 4 +++- src/routes/search.rs | 5 +++++ src/routes/transaction.rs | 47 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/routes/address.rs create mode 100644 src/routes/search.rs create mode 100644 src/routes/transaction.rs diff --git a/src/main.rs b/src/main.rs index d89e0b3..4c33b00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #[macro_use] extern crate rocket; mod routes; -use routes::block::get_height; +use routes::{block, transaction, address, search}; #[get("/")] fn index() -> &'static str { @@ -11,5 +11,8 @@ fn index() -> &'static str { fn rocket() -> _ { rocket::build() .mount("/", routes![index]) - .mount("/block", routes![get_height]) + .mount("/block", routes![block::height, block::hash]) + .mount("/transaction", routes![transaction::hash, transaction::receipt]) + .mount("/address", routes![address::show]) + .mount("/search", routes![search::show]) } \ No newline at end of file diff --git a/src/routes/address.rs b/src/routes/address.rs new file mode 100644 index 0000000..b493764 --- /dev/null +++ b/src/routes/address.rs @@ -0,0 +1,4 @@ +#[get("/")] +pub fn show() -> &'static str { + "address details and qr" +} \ No newline at end of file diff --git a/src/routes/block.rs b/src/routes/block.rs index f20a867..87f4edd 100644 --- a/src/routes/block.rs +++ b/src/routes/block.rs @@ -1,12 +1,23 @@ -use rocket::serde::json; +use rocket::serde::json::{Value, json}; -#[get("/height/")] -pub fn get_height(block_height: i32) -> json::Value { - return json::json!({ +#[get("/height/")] +pub fn height(height: i32) -> Value { + let payload: Value = json!({ "method": "get_block", "params": { - "height": block_height + "height": height } }); + return payload; +} +#[get("/hash/")] +pub fn hash(hash: String) -> Value { + let payload: Value = json!({ + "method": "get_block", + "params": { + "hash": hash + } + }); + return payload; } \ No newline at end of file diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 4b576ec..3ee19fa 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,2 +1,4 @@ pub mod block; -// pub mod block::get_height; \ No newline at end of file +pub mod transaction; +pub mod address; +pub mod search; \ No newline at end of file diff --git a/src/routes/search.rs b/src/routes/search.rs new file mode 100644 index 0000000..a362224 --- /dev/null +++ b/src/routes/search.rs @@ -0,0 +1,5 @@ +#[get("/")] +pub fn show(value: String) -> &'static str { + println!("found args: {}", value); + "search options/args" +} \ No newline at end of file diff --git a/src/routes/transaction.rs b/src/routes/transaction.rs new file mode 100644 index 0000000..a1bb205 --- /dev/null +++ b/src/routes/transaction.rs @@ -0,0 +1,47 @@ +use rocket::serde::json::{Value, json}; + +#[get("/")] +pub fn hash(hash: String) -> Value { + let params: Value = json!({ + "txs_hashes": [&hash], + "decode_as_json": true + }); + // let mut res: GetTransactions = build_rpc( + // &"get_transactions", Some(params), true + // ).send().unwrap().json().unwrap(); + // if res.txs.len() > 0 { + // for f in &mut res.txs { + // f.process(); + // }; + // }; + // let context = json!({ + // "tx_info": res.txs, + // "hash": hash, + // "debug": res.clone() + // }); + return params; +} + +#[get("/receipt?
&&")] +pub fn receipt(address: String, hash: String, key: String) -> Value { + let payload: Value = json!({ + "method": "check_tx_key", + "params": { + "address": address, + "txid": hash, + "tx_key": key + } + }); + // let http_client = Client::new(); + // let wallet_uri = env::var("WALLET_URI").unwrap(); + // let uri = format!("{}/json_rpc", &wallet_uri); + // let res: CheckTxKeyResponse = http_client.post(&uri).json(&payload) + // .send().unwrap().json().unwrap(); + // let context = json!({ + // "res": &res.result, + // "hash": hash, + // "address": address + // }); + // Template::render("receipt", context) + return payload; +} \ No newline at end of file