Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick and dirty test of wasm compilation #33

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pallas-alonzo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ authors = [
]

[dependencies]
minicbor = { version = "0.12", features = ["std"] }
minicbor = { version = "0.12", features = ["derive"] }
minicbor-derive = "0.8.0"

[dev-dependencies]
hex = "0.4.3"
log = "0.4.14"
pallas-crypto = { version = "0.3", path = "../pallas-crypto" }
50 changes: 0 additions & 50 deletions pallas-alonzo/src/crypto.rs

This file was deleted.

13 changes: 11 additions & 2 deletions pallas-alonzo/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ where
T: minicbor::Encode + minicbor::Decode<'a> + Sized,
{
fn encode_fragment(&self) -> Result<Vec<u8>, Error> {
minicbor::to_vec(self).map_err(|e| e.into())
let mut buf = Vec::new();
{
let mut encoder = minicbor::Encoder::new(&mut buf);
encoder.encode(self).expect("error encoding");
}

Ok(buf)
}

fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error> {
minicbor::decode(bytes).map_err(|e| e.into())
let mut decoder = minicbor::Decoder::new(bytes);
let out = decoder.decode().expect("error decoding");

Ok(out)
}
}
4 changes: 1 addition & 3 deletions pallas-alonzo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ mod framework;
mod model;
mod utils;

pub use framework::*;
pub use model::*;

pub mod crypto;
pub use framework::*;
26 changes: 13 additions & 13 deletions pallas-alonzo/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
//!
//! Handcrafted, idiomatic rust artifacts based on based on the [Alonzo CDDL](https://github.com/input-output-hk/cardano-ledger/blob/master/eras/alonzo/test-suite/cddl-files/alonzo.cddl) file in IOHK repo.

use log::warn;
use minicbor::{bytes::ByteVec, data::Tag};
use minicbor_derive::{Decode, Encode};
use pallas_crypto::hash::Hash;
use std::{collections::BTreeMap, ops::Deref};

use crate::utils::{KeyValuePairs, MaybeIndefArray};

pub type Hash32 = ByteVec;
pub type Hash28 = ByteVec;

#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
pub struct SkipCbor<const N: usize> {}

impl<'b, const N: usize> minicbor::Decode<'b> for SkipCbor<N> {
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
{
let probe = d.probe();
warn!("skipped cbor value {}: {:?}", N, probe.datatype()?);
println!("skipped cbor value {}: {:?}", N, probe.datatype()?);
}

Expand Down Expand Up @@ -47,7 +47,7 @@ pub struct HeaderBody {
pub slot: u64,

#[n(2)]
pub prev_hash: Hash<32>,
pub prev_hash: Hash32,

#[n(3)]
pub issuer_vkey: ByteVec,
Expand All @@ -65,7 +65,7 @@ pub struct HeaderBody {
pub block_body_size: u64,

#[n(8)]
pub block_body_hash: Hash<32>,
pub block_body_hash: Hash32,

#[n(9)]
pub operational_cert: ByteVec,
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct Header {
#[derive(Encode, Decode, Debug, PartialEq)]
pub struct TransactionInput {
#[n(0)]
pub transaction_id: Hash<32>,
pub transaction_id: Hash32,

#[n(1)]
pub index: u64,
Expand All @@ -125,7 +125,7 @@ pub struct Nonce {
pub variant: NonceVariant,

#[n(1)]
pub hash: Hash<32>,
pub hash: Hash32,
}

pub type ScriptHash = ByteVec;
Expand Down Expand Up @@ -197,11 +197,11 @@ pub struct TransactionOutput {
pub datum_hash: Option<ByteVec>,
}

pub type PoolKeyhash = Hash<28>;
pub type PoolKeyhash = Hash28;
pub type Epoch = u64;
pub type Genesishash = ByteVec;
pub type GenesisDelegateHash = ByteVec;
pub type VrfKeyhash = Hash<32>;
pub type VrfKeyhash = Hash32;

/* move_instantaneous_reward = [ 0 / 1, { * stake_credential => delta_coin } / coin ]
; The first field determines where the funds are drawn from.
Expand Down Expand Up @@ -359,7 +359,7 @@ impl minicbor::encode::Encode for Relay {
}
}

pub type PoolMetadataHash = Hash<32>;
pub type PoolMetadataHash = Hash32;

#[derive(Encode, Decode, Debug, PartialEq)]
pub struct PoolMetadata {
Expand All @@ -370,8 +370,8 @@ pub struct PoolMetadata {
pub hash: PoolMetadataHash,
}

pub type AddrKeyhash = Hash<28>;
pub type Scripthash = Hash<28>;
pub type AddrKeyhash = Hash28;
pub type Scripthash = Hash28;

#[derive(Debug, PartialEq)]
pub struct RationalNumber {
Expand Down Expand Up @@ -718,7 +718,7 @@ pub enum TransactionBodyComponent {
AuxiliaryDataHash(ByteVec),
ValidityIntervalStart(u64),
Mint(Multiasset<i64>),
ScriptDataHash(Hash<32>),
ScriptDataHash(Hash32),
Collateral(MaybeIndefArray<TransactionInput>),
RequiredSigners(MaybeIndefArray<AddrKeyhash>),
NetworkId(NetworkId),
Expand Down