feat: we're flat encoding plutus core
This commit is contained in:
parent
344620136f
commit
b345afd12f
|
@ -11,5 +11,9 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
println!("{:#?}", program);
|
||||
|
||||
println!("{:?}", program.flat()?);
|
||||
|
||||
println!("{}", program.flat_hex()?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
(program 1.0.0
|
||||
[[(builtin addInteger) (con integer 4)] (con integer 8)]
|
||||
(con bool False)
|
||||
)
|
|
@ -1,3 +1,4 @@
|
|||
use anyhow::anyhow;
|
||||
use flat::en::{Encode, Encoder};
|
||||
|
||||
use crate::builtins::DefaultFunction;
|
||||
|
@ -5,12 +6,28 @@ use crate::builtins::DefaultFunction;
|
|||
const TERM_TAG_WIDTH: u32 = 4;
|
||||
const CONST_TAG_WIDTH: u32 = 4;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Program {
|
||||
pub version: String,
|
||||
pub term: Term,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn flat(&self) -> anyhow::Result<Vec<u8>> {
|
||||
let bytes = flat::encode(self.clone()).map_err(|err| anyhow!("{}", err))?;
|
||||
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn flat_hex(&self) -> anyhow::Result<String> {
|
||||
let bytes = self.flat()?;
|
||||
|
||||
let hex = hex::encode(&bytes);
|
||||
|
||||
Ok(hex)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Term {
|
||||
// tag: 0
|
||||
|
|
Loading…
Reference in New Issue