diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 617f3a4410..1606660e17 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -128,6 +128,7 @@ dependencies = [ "bitflags 2.6.0", "hex", "lazy_static", + "serde", ] [[package]] @@ -3519,6 +3520,8 @@ dependencies = [ "ain-macros", "bitcoin", "hex", + "serde", + "serde_json", ] [[package]] diff --git a/lib/ain-dftx/Cargo.toml b/lib/ain-dftx/Cargo.toml index b0f0d4ee42..1a3cddcb52 100644 --- a/lib/ain-dftx/Cargo.toml +++ b/lib/ain-dftx/Cargo.toml @@ -11,3 +11,4 @@ bitcoin.workspace = true hex.workspace = true bitflags = "2.4.1" lazy_static.workspace = true +serde.workspace = true diff --git a/lib/ain-dftx/src/types/balance.rs b/lib/ain-dftx/src/types/balance.rs index 44f2ca22d0..20bddb5163 100644 --- a/lib/ain-dftx/src/types/balance.rs +++ b/lib/ain-dftx/src/types/balance.rs @@ -1,5 +1,6 @@ use ain_macros::ConsensusEncoding; use bitcoin::{io, ScriptBuf, VarInt}; +use serde::Serialize; use super::common::CompactVec; diff --git a/lib/ain-dftx/src/types/common.rs b/lib/ain-dftx/src/types/common.rs index 154f8835a8..0724ee387c 100644 --- a/lib/ain-dftx/src/types/common.rs +++ b/lib/ain-dftx/src/types/common.rs @@ -4,6 +4,7 @@ use bitcoin::{ consensus::{Decodable, Encodable}, io::{self, ErrorKind}, }; +use serde::Serialize; #[derive(Debug, PartialEq, Eq, Clone)] pub struct CompactVec(Vec); @@ -110,7 +111,7 @@ impl Decodable for RawBytes { /// In the rust-bitcoin library, variable-length integers are implemented as CompactSize. /// See [issue #1016](https://github.com/rust-bitcoin/rust-bitcoin/issues/1016) -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize)] pub struct VarInt(pub u64); impl Encodable for VarInt { diff --git a/lib/ain-dftx/src/types/price.rs b/lib/ain-dftx/src/types/price.rs index bba56a5f8a..b87972dbc4 100644 --- a/lib/ain-dftx/src/types/price.rs +++ b/lib/ain-dftx/src/types/price.rs @@ -1,7 +1,7 @@ +use super::common::CompactVec; use ain_macros::ConsensusEncoding; use bitcoin::io; - -use super::common::CompactVec; +use serde::Serialize; #[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)] pub struct CurrencyPair { @@ -9,7 +9,7 @@ pub struct CurrencyPair { pub currency: String, } -#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)] +#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone, Serialize)] pub struct TokenAmount { pub currency: String, pub amount: i64, diff --git a/lib/parser/Cargo.toml b/lib/parser/Cargo.toml index 3abd2054ad..cf49f40afd 100644 --- a/lib/parser/Cargo.toml +++ b/lib/parser/Cargo.toml @@ -6,5 +6,7 @@ edition = "2021" [dependencies] ain-macros.workspace = true ain-dftx.workspace = true -bitcoin.workspace = true +bitcoin = { workspace = true, features = ["serde"] } hex.workspace = true +serde_json.workspace = true +serde.workspace = true diff --git a/lib/parser/src/main.rs b/lib/parser/src/main.rs index 6e6b2b9572..72cff934c2 100644 --- a/lib/parser/src/main.rs +++ b/lib/parser/src/main.rs @@ -1,6 +1,10 @@ +use ain_dftx::balance::TokenBalanceVarInt; +use ain_dftx::common::VarInt; +use ain_dftx::price::TokenAmount; use ain_macros::ConsensusEncoding; -use bitcoin::io; use bitcoin::{consensus::Decodable, ScriptBuf}; +use bitcoin::{io, Txid}; +use serde::Serialize; use std::io::BufRead; #[derive(Debug)] @@ -26,19 +30,19 @@ impl RawDbEntry { } } -#[derive(ConsensusEncoding, Debug, Clone, PartialEq, Eq)] +#[derive(ConsensusEncoding, Debug, Clone, PartialEq, Eq, Serialize)] pub struct BalanceKey { pub owner: ScriptBuf, - pub token_id: u32, + pub token_id: VarInt, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct PrefixedData { pub key: K, pub value: V, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub enum VMDomainEdge { DVMToEVM, EVMToDVM, @@ -59,12 +63,24 @@ impl Decodable for VMDomainEdge { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +struct UndoKey { + height: u32, + id: Txid, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +struct Undo { + data: Vec, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub enum Prefix { ByBalance(PrefixedData), ByHeight(PrefixedData), VMDomainTxEdge(PrefixedData<(VMDomainEdge, String), String>), VMDomainBlockEdge(PrefixedData<(VMDomainEdge, String), String>), + Undo(PrefixedData), } impl TryFrom for Prefix { @@ -104,7 +120,7 @@ fn process_line(line: &str) -> Result<(), Box> { let raw_entry = RawDbEntry::parse(line)?; match Prefix::try_from(raw_entry) { - Ok(entry) => println!("{entry:?}"), + Ok(entry) => println!("{}", serde_json::to_string(&entry)?), Err(_) => {} }