From eec7713463dfcaf4b7c4c7a02d30b82bad60e5ea Mon Sep 17 00:00:00 2001
From: Santiago Carmuega <santiago@carmuega.me>
Date: Sun, 3 Jul 2022 21:01:28 -0300
Subject: [PATCH] fix: Fix n2n babbage header parsing

---
 Cargo.lock                 |  4 ++--
 src/sources/n2n/headers.rs | 16 ++++++++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 19182541..b530daba 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1707,9 +1707,9 @@ dependencies = [
 
 [[package]]
 name = "pallas-traverse"
-version = "0.11.0"
+version = "0.11.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2e8818ff5279ef4dbce4d3e83187cbbb85c810eeceb9308081757a3cc4fe1a0"
+checksum = "0f84c669596744b97384bfbaed7e222ff76f4ba2fe8939abc3a9335a8080b00b"
 dependencies = [
  "hex",
  "pallas-codec",
diff --git a/src/sources/n2n/headers.rs b/src/sources/n2n/headers.rs
index af2fd8a2..28239218 100644
--- a/src/sources/n2n/headers.rs
+++ b/src/sources/n2n/headers.rs
@@ -1,6 +1,6 @@
 use pallas::{
     codec::minicbor::decode,
-    ledger::primitives::{alonzo, byron, ToHash},
+    ledger::primitives::{alonzo, babbage, byron, ToHash},
     network::miniprotocols::{chainsync::HeaderContent, Point},
 };
 
@@ -11,6 +11,7 @@ pub enum MultiEraHeader {
     ByronBoundary(byron::EbbHead),
     Byron(byron::BlockHead),
     AlonzoCompatible(alonzo::Header),
+    Babbage(babbage::Header),
 }
 
 impl TryFrom<HeaderContent> for MultiEraHeader {
@@ -28,10 +29,17 @@ impl TryFrom<HeaderContent> for MultiEraHeader {
                     Ok(MultiEraHeader::Byron(header))
                 }
             },
-            _ => {
+            1 | 2 | 3 | 4 => {
                 let header = decode(&value.cbor)?;
                 Ok(MultiEraHeader::AlonzoCompatible(header))
             }
+            5 => {
+                let header = decode(&value.cbor)?;
+                Ok(MultiEraHeader::Babbage(header))
+            }
+            x => {
+                return Err(format!("This version of Oura can't handle era: {}", x).into());
+            }
         }
     }
 }
@@ -53,6 +61,10 @@ impl MultiEraHeader {
                 let hash = x.to_hash();
                 Ok(Point::Specific(x.header_body.slot, hash.to_vec()))
             }
+            MultiEraHeader::Babbage(x) => {
+                let hash = x.to_hash();
+                Ok(Point::Specific(x.header_body.slot, hash.to_vec()))
+            }
         }
     }
 }