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
3 changed files with 23 additions and 2 deletions

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