Changed reqwest for ureq
Seemed much smaller and more what I needed
This commit is contained in:
892
Cargo.lock
generated
892
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -8,5 +8,5 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.38"
|
chrono = "0.4.38"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
reqwest = { version = "0.12.5", features = ["json", "blocking"] }
|
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.120"
|
||||||
|
ureq = { version = "2.10.0", features = ["json"] }
|
||||||
|
|||||||
30
src/lib.rs
30
src/lib.rs
@@ -1,10 +1,9 @@
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::convert::Into;
|
|
||||||
use std::sync::RwLock;
|
|
||||||
use reqwest;
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::convert::Into;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
// TODO review whether a genesis block has a block height of 1 or 0
|
// TODO review whether a genesis block has a block height of 1 or 0
|
||||||
|
|
||||||
@@ -12,10 +11,9 @@ pub enum BlockchainSupported {
|
|||||||
BTC,
|
BTC,
|
||||||
BSV,
|
BSV,
|
||||||
XMR,
|
XMR,
|
||||||
ETH
|
ETH,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type BlockHeight = i64;
|
type BlockHeight = i64;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
@@ -75,11 +73,9 @@ pub fn time_to_blockheight(time: DateTime<Utc>, bi: BlockchainInfo) -> BlockHeig
|
|||||||
|
|
||||||
pub fn update_bsv_blockheight() {
|
pub fn update_bsv_blockheight() {
|
||||||
let whatsonchain_url = "https://api.whatsonchain.com/v1/bsv/main/block/headers";
|
let whatsonchain_url = "https://api.whatsonchain.com/v1/bsv/main/block/headers";
|
||||||
match reqwest::blocking::get(whatsonchain_url) {
|
match ureq::get(whatsonchain_url).call() {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let json = resp.json::<Vec<HashMap<String, serde_json::Value>>>();
|
let json: serde_json::Value = resp.into_json().unwrap();
|
||||||
match json {
|
|
||||||
Ok(json) => {
|
|
||||||
let height = json[0].get("height").unwrap().as_i64().unwrap();
|
let height = json[0].get("height").unwrap().as_i64().unwrap();
|
||||||
|
|
||||||
// I am presuming that "time" is when WhatsOnChain saw the block rather than the
|
// I am presuming that "time" is when WhatsOnChain saw the block rather than the
|
||||||
@@ -98,20 +94,13 @@ pub fn update_bsv_blockheight() {
|
|||||||
println!("Err: {}", err);
|
println!("Err: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("Err: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_btc_blockheight() {
|
pub fn update_btc_blockheight() {
|
||||||
let blockcypher_url = "https://api.blockcypher.com/v1/btc/main";
|
let blockcypher_url = "https://api.blockcypher.com/v1/btc/main";
|
||||||
match reqwest::blocking::get(blockcypher_url) {
|
match ureq::get(blockcypher_url).call() {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let json = resp.json::<HashMap<String, serde_json::Value>>();
|
let json: serde_json::Value = resp.into_json().unwrap();
|
||||||
match json {
|
|
||||||
Ok(json) => {
|
|
||||||
let height = json.get("height").unwrap().as_i64().unwrap();
|
let height = json.get("height").unwrap().as_i64().unwrap();
|
||||||
let time = json.get("time").unwrap().as_str().unwrap();
|
let time = json.get("time").unwrap().as_str().unwrap();
|
||||||
let datetime = time.parse::<DateTime<Utc>>().unwrap();
|
let datetime = time.parse::<DateTime<Utc>>().unwrap();
|
||||||
@@ -125,11 +114,6 @@ pub fn update_btc_blockheight() {
|
|||||||
println!("Err: {}", err);
|
println!("Err: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("Err: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user