feat: we're flat encoding plutus core

This commit is contained in:
rvcas 2022-05-23 12:45:13 -04:00
parent 344620136f
commit b345afd12f
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
3 changed files with 23 additions and 2 deletions

View File

@ -11,5 +11,9 @@ fn main() -> anyhow::Result<()> {
println!("{:#?}", program);
println!("{:?}", program.flat()?);
println!("{}", program.flat_hex()?);
Ok(())
}

View File

@ -1,3 +1,3 @@
(program 1.0.0
[[(builtin addInteger) (con integer 4)] (con integer 8)]
(con bool False)
)

View File

@ -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