Skip to content

Commit

Permalink
fix: Fix config point parsing regression (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jun 1, 2022
1 parent 86408bb commit 7585104
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
35 changes: 32 additions & 3 deletions src/crosscut/args.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -106,8 +106,37 @@ impl Default for MagicArg {
pub enum IntersectConfig {
Tip,
Origin,
Point(PointArg),
Fallbacks(Vec<PointArg>),
Point(u64, String),
Fallbacks(Vec<(u64, String)>),
}

impl IntersectConfig {
pub fn get_point(&self) -> Option<Point> {
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<Vec<Point>> {
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
Expand Down
10 changes: 5 additions & 5 deletions src/sources/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<_>, _> = 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))
}
}
}
Binary file added testdrive/custom/data/dump.rdb
Binary file not shown.
9 changes: 9 additions & 0 deletions testdrive/custom/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.7"

services:
redis:
image: redis
volumes:
- ./data:/data
ports:
- "6379:6379"
1 change: 1 addition & 0 deletions testdrive/custom/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUST_LOG=info cargo run --all-features --bin scrolls -- daemon --config ./daemon.toml

0 comments on commit 7585104

Please sign in to comment.