Skip to content

Commit fa6f161

Browse files
authored
Merge pull request #322 from Alesfatalis/develop
add scan start block height config parameter
2 parents 87d1bee + 4ba5447 commit fa6f161

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed

core/src/cli_commands/prepare_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ rescan_height: 141887
628628
node_url: http://10.94.77.47:9052
629629
node_api_key: hello
630630
base_fee: 1100000
631+
scan_start_height: 0
631632
log_level: ~
632633
core_api_port: 9010
633634
oracle_address: 3Wy3BaCjGDWE3bjjZkNo3aWaMz3cYrePMFhchcKovY9uG9vhpAuW

core/src/datapoint_source/bitpanda.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::DataPointSourceError;
77
#[derive(Debug, Clone)]
88
pub struct BitPanda {}
99

10+
#[cfg(not(test))]
1011
pub async fn get_kgau_usd() -> Result<AssetsExchangeRate<KgAu, Usd>, DataPointSourceError> {
1112
let url = "https://api.bitpanda.com/v1/ticker";
1213
let resp = reqwest::get(url).await?;
@@ -34,6 +35,20 @@ pub async fn get_kgau_usd() -> Result<AssetsExchangeRate<KgAu, Usd>, DataPointSo
3435
}
3536
}
3637

38+
#[cfg(test)]
39+
pub async fn get_kgau_usd() -> Result<AssetsExchangeRate<KgAu, Usd>, DataPointSourceError> {
40+
// USD price of 1 gram of gold
41+
let p_float = 66.10;
42+
let usd_per_kgau = KgAu::from_gram(p_float);
43+
let rate = AssetsExchangeRate {
44+
per1: KgAu {},
45+
get: Usd {},
46+
rate: usd_per_kgau,
47+
};
48+
Ok(rate)
49+
}
50+
51+
#[cfg(not(test))]
3752
// Get USD/BTC. Can be used as a redundant source for ERG/BTC through ERG/USD and USD/BTC
3853
pub(crate) async fn get_btc_usd() -> Result<AssetsExchangeRate<Btc, Usd>, DataPointSourceError> {
3954
let url = "https://api.bitpanda.com/v1/ticker";
@@ -61,6 +76,18 @@ pub(crate) async fn get_btc_usd() -> Result<AssetsExchangeRate<Btc, Usd>, DataPo
6176
}
6277
}
6378

79+
#[cfg(test)]
80+
pub(crate) async fn get_btc_usd() -> Result<AssetsExchangeRate<Btc, Usd>, DataPointSourceError> {
81+
// USD price of BTC
82+
let usd_per_btc = 43827.02;
83+
let rate = AssetsExchangeRate {
84+
per1: Btc {},
85+
get: Usd {},
86+
rate: usd_per_btc,
87+
};
88+
Ok(rate)
89+
}
90+
6491
#[cfg(test)]
6592
mod tests {
6693
use super::*;

core/src/datapoint_source/coincap.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::DataPointSourceError;
77
#[derive(Debug, Clone)]
88
pub struct CoinCap;
99

10+
#[cfg(not(test))]
1011
pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataPointSourceError> {
1112
// see https://coincap.io/assets/ergo
1213
let url = "https://api.coincap.io/v2/assets/ergo";
@@ -34,6 +35,19 @@ pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataP
3435
}
3536
}
3637

38+
#[cfg(test)]
39+
pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataPointSourceError> {
40+
let p_float = 1.661_923_469_67;
41+
let nanoerg_per_usd = NanoErg::from_erg(1.0 / p_float);
42+
let rate = AssetsExchangeRate {
43+
per1: Usd {},
44+
get: NanoErg {},
45+
rate: nanoerg_per_usd,
46+
};
47+
Ok(rate)
48+
}
49+
50+
#[cfg(not(test))]
3751
// Get USD/BTC. Can be used as a redundant source for ERG/BTC through ERG/USD and USD/BTC
3852
pub async fn get_btc_usd() -> Result<AssetsExchangeRate<Btc, Usd>, DataPointSourceError> {
3953
// see https://coincap.io/assets/ergo
@@ -61,6 +75,17 @@ pub async fn get_btc_usd() -> Result<AssetsExchangeRate<Btc, Usd>, DataPointSour
6175
}
6276
}
6377

78+
#[cfg(test)]
79+
pub async fn get_btc_usd() -> Result<AssetsExchangeRate<Btc, Usd>, DataPointSourceError> {
80+
let usd_per_btc = 43_712.768_005_075_37;
81+
let rate = AssetsExchangeRate {
82+
per1: Btc {},
83+
get: Usd {},
84+
rate: usd_per_btc,
85+
};
86+
Ok(rate)
87+
}
88+
6489
#[cfg(test)]
6590
mod tests {
6691
use super::super::bitpanda;

core/src/datapoint_source/coingecko.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub async fn get_kgau_nanoerg() -> Result<AssetsExchangeRate<KgAu, NanoErg>, Dat
2929
}
3030
}
3131

32+
#[cfg(not(test))]
3233
pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataPointSourceError> {
3334
let url = "https://api.coingecko.com/api/v3/simple/price?ids=ergo&vs_currencies=USD";
3435
let resp = reqwest::get(url).await?;
@@ -50,6 +51,19 @@ pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataP
5051
}
5152
}
5253

54+
#[cfg(test)]
55+
pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataPointSourceError> {
56+
// Convert from price Erg/USD to nanoErgs per 1 USD
57+
let nanoerg_per_usd = NanoErg::from_erg(1.0 / 1.67);
58+
let rate = AssetsExchangeRate {
59+
per1: Usd {},
60+
get: NanoErg {},
61+
rate: nanoerg_per_usd,
62+
};
63+
Ok(rate)
64+
}
65+
66+
#[cfg(not(test))]
5367
pub async fn get_usd_lovelace() -> Result<AssetsExchangeRate<Usd, Lovelace>, DataPointSourceError> {
5468
let url = "https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=USD";
5569
let resp = reqwest::get(url).await?;
@@ -71,6 +85,19 @@ pub async fn get_usd_lovelace() -> Result<AssetsExchangeRate<Usd, Lovelace>, Dat
7185
}
7286
}
7387

88+
#[cfg(test)]
89+
pub async fn get_usd_lovelace() -> Result<AssetsExchangeRate<Usd, Lovelace>, DataPointSourceError> {
90+
// Convert from price Erg/USD to nanoErgs per 1 USD
91+
let lovelace_price = Lovelace::from_ada(1.0 / 0.606545);
92+
let rate = AssetsExchangeRate {
93+
per1: Usd {},
94+
get: Lovelace {},
95+
rate: lovelace_price,
96+
};
97+
Ok(rate)
98+
}
99+
100+
#[cfg(not(test))]
74101
pub async fn get_btc_nanoerg() -> Result<AssetsExchangeRate<Btc, NanoErg>, DataPointSourceError> {
75102
let url = "https://api.coingecko.com/api/v3/simple/price?ids=ergo&vs_currencies=BTC";
76103
let resp = reqwest::get(url).await?;
@@ -92,6 +119,18 @@ pub async fn get_btc_nanoerg() -> Result<AssetsExchangeRate<Btc, NanoErg>, DataP
92119
}
93120
}
94121

122+
#[cfg(test)]
123+
pub async fn get_btc_nanoerg() -> Result<AssetsExchangeRate<Btc, NanoErg>, DataPointSourceError> {
124+
// Convert from price BTC/ERG to nanoERG/BTC
125+
let erg_per_usd = NanoErg::from_erg(1.0 / 0.00003791);
126+
let rate = AssetsExchangeRate {
127+
per1: Btc {},
128+
get: NanoErg {},
129+
rate: erg_per_usd,
130+
};
131+
Ok(rate)
132+
}
133+
95134
#[cfg(test)]
96135
mod tests {
97136
use super::*;

core/src/oracle_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub const DEFAULT_ORACLE_CONFIG_FILE_NAME: &str = "oracle_config.yaml";
3030
pub struct OracleConfig {
3131
pub node_url: Url,
3232
pub base_fee: u64,
33+
pub scan_start_height: u32,
3334
pub log_level: Option<LevelFilter>,
3435
pub core_api_port: u16,
3536
pub oracle_address: NetworkAddress,
@@ -117,6 +118,7 @@ impl Default for OracleConfig {
117118
Self {
118119
oracle_address: address.clone(),
119120
core_api_port: 9010,
121+
scan_start_height: 0,
120122
data_point_source_custom_script: None,
121123
base_fee: *tx_builder::SUGGESTED_TX_FEE().as_u64(),
122124
log_level: LevelFilter::Info.into(),

core/src/scans/registry.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::spec_token::PoolTokenId;
1010
use crate::spec_token::RefreshTokenId;
1111
use crate::spec_token::UpdateTokenId;
1212

13+
use crate::oracle_config::ORACLE_CONFIG;
1314
use ::serde::Deserialize;
1415
use ::serde::Serialize;
1516
use once_cell::sync;
@@ -87,7 +88,7 @@ impl NodeScanRegistry {
8788
buyback_token_scan,
8889
};
8990
registry.save_to_json_file(&get_scans_file_path())?;
90-
node_api.rescan_from_height(0)?;
91+
node_api.rescan_from_height(ORACLE_CONFIG.scan_start_height)?;
9192
Ok(registry)
9293
}
9394

@@ -116,7 +117,7 @@ impl NodeScanRegistry {
116117
} else {
117118
let buyback_token_scan =
118119
GenericTokenScan::register(node_api, &pool_config_buyback_token_id)?;
119-
node_api.rescan_from_height(0)?;
120+
node_api.rescan_from_height(ORACLE_CONFIG.scan_start_height)?;
120121
let new_registry = Self {
121122
buyback_token_scan: Some(buyback_token_scan),
122123
..loaded_registry

0 commit comments

Comments
 (0)