From 75851044027143a58df1e1b10f601a6ad58b4465 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Wed, 1 Jun 2022 13:24:38 -0300 Subject: [PATCH] fix: Fix config point parsing regression (#17) --- src/crosscut/args.rs | 35 +++++++++++++++++++++++++--- src/sources/utils.rs | 10 ++++---- testdrive/custom/data/dump.rdb | Bin 0 -> 171 bytes testdrive/custom/docker-compose.yml | 9 +++++++ testdrive/custom/start.sh | 1 + 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 testdrive/custom/data/dump.rdb create mode 100644 testdrive/custom/docker-compose.yml create mode 100755 testdrive/custom/start.sh diff --git a/src/crosscut/args.rs b/src/crosscut/args.rs index 170033f0..9fdba8c8 100644 --- a/src/crosscut/args.rs +++ b/src/crosscut/args.rs @@ -1,6 +1,6 @@ use pallas::network::miniprotocols::{Point, MAINNET_MAGIC, TESTNET_MAGIC}; use serde::{Deserialize, Serialize}; -use std::{fmt::Display, ops::Deref, str::FromStr}; +use std::{ops::Deref, str::FromStr}; use crate::Error; @@ -106,8 +106,37 @@ impl Default for MagicArg { pub enum IntersectConfig { Tip, Origin, - Point(PointArg), - Fallbacks(Vec), + Point(u64, String), + Fallbacks(Vec<(u64, String)>), +} + +impl IntersectConfig { + pub fn get_point(&self) -> Option { + match self { + IntersectConfig::Point(slot, hash) => { + let hash = hex::decode(hash).expect("valid hex hash"); + Some(Point::Specific(*slot, hash)) + } + _ => None, + } + } + + pub fn get_fallbacks(&self) -> Option> { + match self { + IntersectConfig::Fallbacks(all) => { + let mapped = all + .iter() + .map(|(slot, hash)| { + let hash = hex::decode(hash).expect("valid hex hash"); + Point::Specific(*slot, hash) + }) + .collect(); + + Some(mapped) + } + _ => None, + } + } } /// Well-known information about the blockhain network diff --git a/src/sources/utils.rs b/src/sources/utils.rs index 27d3ca5b..f0c64b48 100644 --- a/src/sources/utils.rs +++ b/src/sources/utils.rs @@ -73,13 +73,13 @@ pub fn define_known_points( let tip = find_end_of_chain(chain, channel)?; Ok(Some(vec![tip])) } - crosscut::IntersectConfig::Point(x) => { - let point = x.clone().try_into()?; + crosscut::IntersectConfig::Point(_, _) => { + let point = intersect.get_point().expect("point value"); Ok(Some(vec![point])) } - crosscut::IntersectConfig::Fallbacks(x) => { - let points: Result, _> = x.iter().cloned().map(|x| x.try_into()).collect(); - Ok(Some(points?)) + crosscut::IntersectConfig::Fallbacks(_) => { + let points = intersect.get_fallbacks().expect("fallback values"); + Ok(Some(points)) } } } diff --git a/testdrive/custom/data/dump.rdb b/testdrive/custom/data/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..910b0607114abe52fd3a8ce955a1783d3ff6fce7 GIT binary patch literal 171 zcmXBOJqp4w7y!^Xh*k6yuD0Yyn|3RxgR34u@+DufU@0W6C-4F;;&DpP;Sro1BlrWZ zZ+hGHYO|x1Q9rb33KyQx_GLsP>PLToqIPZO`?@Yl?558P_@HrU!V=5w@R$%Es45RZ zIc&+Byn2KT_PVjIve{CySqdm(fr*lmaTbdO8a)>Y=fY5(N@-Z45;T&d{ykLAl~9-h ROLG8_3_j=Eah%`z^$Tm6J0}1D literal 0 HcmV?d00001 diff --git a/testdrive/custom/docker-compose.yml b/testdrive/custom/docker-compose.yml new file mode 100644 index 00000000..bde396ce --- /dev/null +++ b/testdrive/custom/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3.7" + +services: + redis: + image: redis + volumes: + - ./data:/data + ports: + - "6379:6379" diff --git a/testdrive/custom/start.sh b/testdrive/custom/start.sh new file mode 100755 index 00000000..77031dc5 --- /dev/null +++ b/testdrive/custom/start.sh @@ -0,0 +1 @@ +RUST_LOG=info cargo run --all-features --bin scrolls -- daemon --config ./daemon.toml