chore: minimal pallas dependencies

This commit is contained in:
hade 2024-05-30 10:51:14 +07:00
parent c9a15194a0
commit ad3c9f24b7
No known key found for this signature in database
GPG Key ID: 706945D35C5E919B
23 changed files with 91 additions and 93 deletions

5
Cargo.lock generated vendored
View File

@ -3535,8 +3535,11 @@ dependencies = [
"num-integer", "num-integer",
"num-traits", "num-traits",
"once_cell", "once_cell",
"pallas", "pallas-addresses",
"pallas-codec", "pallas-codec",
"pallas-crypto",
"pallas-primitives",
"pallas-traverse",
"peg", "peg",
"pretty", "pretty",
"pretty_assertions", "pretty_assertions",

View File

@ -19,8 +19,11 @@ miette = "5.5.0"
num-bigint = "0.4.3" num-bigint = "0.4.3"
num-integer = "0.1.45" num-integer = "0.1.45"
num-traits = "0.2.15" num-traits = "0.2.15"
pallas.workspace = true pallas-crypto = "0.22.0"
pallas-primitives = "0.22.0"
pallas-addresses = "0.22.0"
pallas-codec = { version = "0.22.0", features = ["num-bigint"] } pallas-codec = { version = "0.22.0", features = ["num-bigint"] }
pallas-traverse = "0.22.0"
peg = "0.8.1" peg = "0.8.1"
pretty = "0.11.3" pretty = "0.11.3"
serde = { version = "1.0.152", features = ["derive"] } serde = { version = "1.0.152", features = ["derive"] }

View File

@ -11,14 +11,12 @@ use crate::{
}; };
use num_bigint::BigInt; use num_bigint::BigInt;
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
use pallas::ledger::{ use pallas_addresses::{Network, ShelleyAddress, ShelleyDelegationPart, ShelleyPaymentPart};
addresses::{Network, ShelleyAddress, ShelleyDelegationPart, ShelleyPaymentPart}, use pallas_primitives::{
primitives::{ alonzo::{self, Constr, PlutusData},
alonzo::{self, Constr, PlutusData}, conway::{self, Language},
conway::{self, Language},
},
traverse::ComputeHash,
}; };
use pallas_traverse::ComputeHash;
use serde::{ use serde::{
self, self,
de::{self, Deserialize, Deserializer, MapAccess, Visitor}, de::{self, Deserialize, Deserializer, MapAccess, Visitor},
@ -304,7 +302,7 @@ pub struct Data;
impl Data { impl Data {
pub fn to_hex(data: PlutusData) -> String { pub fn to_hex(data: PlutusData) -> String {
let mut bytes = Vec::new(); let mut bytes = Vec::new();
pallas::codec::minicbor::Encoder::new(&mut bytes) pallas_codec::minicbor::Encoder::new(&mut bytes)
.encode(data) .encode(data)
.expect("failed to encode Plutus Data as cbor?"); .expect("failed to encode Plutus Data as cbor?");
hex::encode(bytes) hex::encode(bytes)

View File

@ -2,7 +2,7 @@ use crate::{
ast::{Constant, Name, Term, Type}, ast::{Constant, Name, Term, Type},
builtins::DefaultFunction, builtins::DefaultFunction,
}; };
use pallas::ledger::primitives::alonzo::PlutusData; use pallas_primitives::alonzo::PlutusData;
pub const CONSTR_FIELDS_EXPOSER: &str = "__constr_fields_exposer"; pub const CONSTR_FIELDS_EXPOSER: &str = "__constr_fields_exposer";
pub const CONSTR_INDEX_EXPOSER: &str = "__constr_index_exposer"; pub const CONSTR_INDEX_EXPOSER: &str = "__constr_index_exposer";

View File

@ -1,6 +1,6 @@
use std::{fmt::Display, rc::Rc, str::FromStr}; use std::{fmt::Display, rc::Rc, str::FromStr};
use pallas::codec::flat::de; use pallas_codec::flat::de;
use strum_macros::EnumIter; use strum_macros::EnumIter;
use crate::ast::Term; use crate::ast::Term;

View File

@ -1,12 +1,10 @@
use num_bigint::BigInt; use num_bigint::BigInt;
use pallas::{ use pallas_codec::flat::{
codec::flat::{ de::{self, Decode, Decoder},
de::{self, Decode, Decoder}, en::{self, Encode, Encoder},
en::{self, Encode, Encoder}, Flat,
Flat,
},
ledger::primitives::{babbage::PlutusData, Fragment},
}; };
use pallas_primitives::{babbage::PlutusData, Fragment};
use std::{collections::VecDeque, fmt::Debug, rc::Rc}; use std::{collections::VecDeque, fmt::Debug, rc::Rc};
@ -35,7 +33,7 @@ where
T: Binder<'b> + Debug, T: Binder<'b> + Debug,
{ {
pub fn from_cbor(bytes: &'b [u8], buffer: &'b mut Vec<u8>) -> Result<Self, de::Error> { pub fn from_cbor(bytes: &'b [u8], buffer: &'b mut Vec<u8>) -> Result<Self, de::Error> {
let mut cbor_decoder = pallas::codec::minicbor::Decoder::new(bytes); let mut cbor_decoder = pallas_codec::minicbor::Decoder::new(bytes);
let flat_bytes = cbor_decoder let flat_bytes = cbor_decoder
.bytes() .bytes()
@ -88,7 +86,7 @@ where
let mut bytes = Vec::new(); let mut bytes = Vec::new();
let mut cbor_encoder = pallas::codec::minicbor::Encoder::new(&mut bytes); let mut cbor_encoder = pallas_codec::minicbor::Encoder::new(&mut bytes);
cbor_encoder cbor_encoder
.bytes(&flat_bytes) .bytes(&flat_bytes)
@ -1006,7 +1004,7 @@ mod tests {
parser, parser,
}; };
use indoc::indoc; use indoc::indoc;
use pallas::codec::flat::Flat; use pallas_codec::flat::Flat;
#[test] #[test]
fn flat_encode_integer() { fn flat_encode_integer() {

View File

@ -9,9 +9,9 @@ pub mod parser;
mod pretty; mod pretty;
pub mod tx; pub mod tx;
pub use pallas::codec::utils::KeyValuePairs; pub use pallas_codec::utils::KeyValuePairs;
pub use pallas::crypto::hash::Hash; pub use pallas_crypto::hash::Hash;
pub use pallas::ledger::primitives::{ pub use pallas_primitives::{
alonzo::{BigInt, Constr, PlutusData}, alonzo::{BigInt, Constr, PlutusData},
babbage::{PostAlonzoTransactionOutput, TransactionInput, TransactionOutput, Value}, babbage::{PostAlonzoTransactionOutput, TransactionInput, TransactionOutput, Value},
Error, Fragment, Error, Fragment,

View File

@ -11,7 +11,7 @@ pub mod value;
use cost_model::{ExBudget, StepKind}; use cost_model::{ExBudget, StepKind};
pub use error::Error; pub use error::Error;
use pallas::ledger::primitives::conway::Language; use pallas_primitives::conway::Language;
use self::{ use self::{
cost_model::CostModel, cost_model::CostModel,

View File

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use pallas::ledger::primitives::conway::Language; use pallas_primitives::conway::Language;
use crate::builtins::DefaultFunction; use crate::builtins::DefaultFunction;

View File

@ -72,6 +72,16 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
Secp256k1(#[from] secp256k1::Error), Secp256k1(#[from] secp256k1::Error),
#[cfg(target_family = "wasm")] #[cfg(target_family = "wasm")]
#[error(transparent)] #[error("{0}")]
Secp256k1(#[from] k256::ecdsa::Error), K256Error(String),
// #[cfg(target_family = "wasm")]
// #[error("k256 error")]
// Secp256k1(#[from] k256::ecdsa::Error),
}
#[cfg(target_family = "wasm")]
impl From<k256::ecdsa::Error> for Error {
fn from(error: k256::ecdsa::Error) -> Error {
Error::K256Error(format!("k256 error: {}", error))
}
} }

View File

@ -4,7 +4,7 @@ use num_bigint::BigInt;
use num_integer::Integer; use num_integer::Integer;
use num_traits::{Signed, Zero}; use num_traits::{Signed, Zero};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use pallas::ledger::primitives::conway::{Language, PlutusData}; use pallas_primitives::conway::{Language, PlutusData};
use crate::{ use crate::{
ast::{Constant, Data, Type}, ast::{Constant, Data, Type},

View File

@ -6,7 +6,7 @@ use crate::{
}; };
use num_bigint::BigInt; use num_bigint::BigInt;
use num_traits::{Signed, ToPrimitive, Zero}; use num_traits::{Signed, ToPrimitive, Zero};
use pallas::ledger::primitives::babbage::{self, PlutusData}; use pallas_primitives::babbage::{self, PlutusData};
use super::{runtime::BuiltinRuntime, Error}; use super::{runtime::BuiltinRuntime, Error};
@ -411,7 +411,7 @@ pub fn from_pallas_bigint(n: &babbage::BigInt) -> BigInt {
pub fn to_pallas_bigint(n: &BigInt) -> babbage::BigInt { pub fn to_pallas_bigint(n: &BigInt) -> babbage::BigInt {
if let Some(i) = n.to_i128() { if let Some(i) = n.to_i128() {
if let Ok(i) = i.try_into() { if let Ok(i) = i.try_into() {
let pallas_int: pallas::codec::utils::Int = i; let pallas_int: pallas_codec::utils::Int = i;
return babbage::BigInt::Int(pallas_int); return babbage::BigInt::Int(pallas_int);
} }
} }

View File

@ -3,7 +3,7 @@ use std::{cmp::Ordering, iter, ops::Neg, rc::Rc, vec};
use indexmap::IndexMap; use indexmap::IndexMap;
use itertools::Itertools; use itertools::Itertools;
use pallas::ledger::primitives::babbage::{BigInt, PlutusData}; use pallas_primitives::babbage::{BigInt, PlutusData};
use crate::{ use crate::{
ast::{Constant, Data, Name, NamedDeBruijn, Program, Term, Type}, ast::{Constant, Data, Name, NamedDeBruijn, Program, Term, Type},
@ -1907,7 +1907,7 @@ fn pop_lambdas_and_get_names(term: &Term<Name>) -> (Vec<Rc<Name>>, &Term<Name>)
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use pallas::ledger::primitives::babbage::{BigInt, PlutusData}; use pallas_primitives::babbage::{BigInt, PlutusData};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use crate::{ use crate::{

View File

@ -9,7 +9,7 @@ use crate::{
use interner::Interner; use interner::Interner;
use num_bigint::BigInt; use num_bigint::BigInt;
use pallas::ledger::primitives::alonzo::PlutusData; use pallas_primitives::alonzo::PlutusData;
use peg::{error::ParseError, str::LineCol}; use peg::{error::ParseError, str::LineCol};
pub mod interner; pub mod interner;
@ -248,7 +248,7 @@ peg::parser! {
)) ))
} }
/ _* "Map" _+ kvps:plutus_key_value_pairs() { / _* "Map" _+ kvps:plutus_key_value_pairs() {
PlutusData::Map(pallas::codec::utils::KeyValuePairs::Def(kvps)) PlutusData::Map(pallas_codec::utils::KeyValuePairs::Def(kvps))
} }
/ _* "List" _+ ls:plutus_list() { PlutusData::Array(ls) } / _* "List" _+ ls:plutus_list() { PlutusData::Array(ls) }
/ _* "I" _+ n:big_number() { PlutusData::BigInt(to_pallas_bigint(&n)) } / _* "I" _+ n:big_number() { PlutusData::BigInt(to_pallas_bigint(&n)) }

View File

@ -4,7 +4,7 @@ use crate::{
machine::runtime::{convert_tag_to_constr, Compressable}, machine::runtime::{convert_tag_to_constr, Compressable},
machine::value::from_pallas_bigint, machine::value::from_pallas_bigint,
}; };
use pallas::ledger::primitives::babbage::{Constr, PlutusData}; use pallas_primitives::babbage::{Constr, PlutusData};
use pretty::RcDoc; use pretty::RcDoc;
use std::ascii::escape_default; use std::ascii::escape_default;

View File

@ -1,8 +1,8 @@
use pallas::ledger::primitives::{ use pallas_primitives::{
babbage::{CostMdls, MintedTx, Redeemer, TransactionInput, TransactionOutput}, babbage::{CostMdls, MintedTx, Redeemer, TransactionInput, TransactionOutput},
Fragment, Fragment,
}; };
use pallas::ledger::traverse::{Era, MultiEraTx}; use pallas_traverse::{Era, MultiEraTx};
use error::Error; use error::Error;
pub use phase_one::eval_phase_one; pub use phase_one::eval_phase_one;

View File

@ -3,13 +3,13 @@ use crate::machine::{self, cost_model::ExBudget};
#[derive(thiserror::Error, Debug, miette::Diagnostic)] #[derive(thiserror::Error, Debug, miette::Diagnostic)]
pub enum Error { pub enum Error {
#[error("{0}")] #[error("{0}")]
Address(#[from] pallas::ledger::addresses::Error), Address(#[from] pallas_addresses::Error),
#[error("Only shelley reward addresses can be a part of withdrawals")] #[error("Only shelley reward addresses can be a part of withdrawals")]
BadWithdrawalAddress, BadWithdrawalAddress,
#[error("{0}")] #[error("{0}")]
FlatDecode(#[from] pallas::codec::flat::de::Error), FlatDecode(#[from] pallas_codec::flat::de::Error),
#[error("{0}")] #[error("{0}")]
FragmentDecode(#[from] pallas::ledger::primitives::Error), FragmentDecode(#[from] pallas_primitives::Error),
#[error("{}\n\n{:#?}\n\n{}", .0, .1, .2.join("\n"))] #[error("{}\n\n{:#?}\n\n{}", .0, .1, .2.join("\n"))]
Machine(machine::Error, ExBudget, Vec<String>), Machine(machine::Error, ExBudget, Vec<String>),
#[error("Native script can't be executed in phase-two")] #[error("Native script can't be executed in phase-two")]
@ -32,7 +32,7 @@ pub enum Error {
#[error("PlutusV2 cost model not found.")] #[error("PlutusV2 cost model not found.")]
V2CostModelNotFound, V2CostModelNotFound,
#[error("Wrong era, Please use Babbage or Alonzo: {0}")] #[error("Wrong era, Please use Babbage or Alonzo: {0}")]
WrongEra(#[from] pallas::codec::minicbor::decode::Error), WrongEra(#[from] pallas_codec::minicbor::decode::Error),
#[error("Byron address not allowed in Plutus.")] #[error("Byron address not allowed in Plutus.")]
ByronAddressNotAllowed, ByronAddressNotAllowed,
#[error("Inline datum not allowed in PlutusV1.")] #[error("Inline datum not allowed in PlutusV1.")]

View File

@ -3,22 +3,17 @@ use crate::{
machine::cost_model::ExBudget, machine::cost_model::ExBudget,
PlutusData, PlutusData,
}; };
use pallas::{ use pallas_addresses::{Address, ScriptHash, StakePayload};
codec::utils::{KeyValuePairs, MaybeIndefArray}, use pallas_codec::utils::{KeyValuePairs, MaybeIndefArray};
crypto::hash::Hash, use pallas_crypto::hash::Hash;
ledger::{ use pallas_primitives::babbage::{
addresses::{Address, ScriptHash, StakePayload}, Certificate, CostMdls, DatumHash, DatumOption, ExUnits, Mint, MintedTx, NativeScript,
primitives::babbage::{ PlutusV1Script, PlutusV2Script, PolicyId, PseudoScript, Redeemer, RedeemerTag, RewardAccount,
Certificate, CostMdls, DatumHash, DatumOption, ExUnits, Mint, MintedTx, NativeScript, StakeCredential, TransactionInput, TransactionOutput, Value, Withdrawals,
PlutusV1Script, PlutusV2Script, PolicyId, PseudoScript, Redeemer, RedeemerTag,
RewardAccount, StakeCredential, TransactionInput, TransactionOutput, Value,
Withdrawals,
},
traverse::{ComputeHash, OriginalHash},
},
}; };
use pallas_traverse::{ComputeHash, OriginalHash};
use pallas::ledger::primitives::conway::Language; use pallas_primitives::conway::Language;
use std::{cmp::Ordering, collections::HashMap, convert::TryInto, ops::Deref, vec}; use std::{cmp::Ordering, collections::HashMap, convert::TryInto, ops::Deref, vec};

View File

@ -1,14 +1,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use pallas::{ use pallas_addresses::{Address, ScriptHash, ShelleyPaymentPart, StakePayload};
codec::utils::{KeyValuePairs, MaybeIndefArray}, use pallas_codec::utils::{KeyValuePairs, MaybeIndefArray};
ledger::{ use pallas_primitives::babbage::{
addresses::{Address, ScriptHash, ShelleyPaymentPart, StakePayload}, Certificate, MintedTx, PolicyId, RedeemerTag, RewardAccount, StakeCredential, TransactionOutput,
primitives::babbage::{
Certificate, MintedTx, PolicyId, RedeemerTag, RewardAccount, StakeCredential,
TransactionOutput,
},
},
}; };
use super::{ use super::{

View File

@ -1,13 +1,9 @@
use pallas::{ use pallas_addresses::Address;
codec::utils::KeyValuePairs, use pallas_codec::utils::KeyValuePairs;
crypto::hash::Hash, use pallas_crypto::hash::Hash;
ledger::{ use pallas_primitives::babbage::{
addresses::Address, AddrKeyhash, Certificate, Coin, DatumHash, PlutusData, PolicyId, Redeemer, StakeCredential,
primitives::babbage::{ TransactionInput, TransactionOutput, Value,
AddrKeyhash, Certificate, Coin, DatumHash, PlutusData, PolicyId, Redeemer,
StakeCredential, TransactionInput, TransactionOutput, Value,
},
},
}; };
use super::to_plutus_data::MintValue; use super::to_plutus_data::MintValue;

View File

@ -1,9 +1,9 @@
use pallas::codec::utils::MaybeIndefArray; use pallas_codec::utils::MaybeIndefArray;
use pallas::ledger::primitives::{ use pallas_primitives::{
babbage::{CostMdls, TransactionInput, TransactionOutput}, babbage::{CostMdls, TransactionInput, TransactionOutput},
Fragment, Fragment,
}; };
use pallas::ledger::traverse::{Era, MultiEraTx}; use pallas_traverse::{Era, MultiEraTx};
use crate::machine::cost_model::ExBudget; use crate::machine::cost_model::ExBudget;

View File

@ -1,12 +1,12 @@
use pallas::codec::utils::{AnyUInt, Bytes, Int, KeyValuePairs}; use pallas_addresses::{Address, ShelleyDelegationPart, ShelleyPaymentPart, StakePayload};
use pallas::crypto::hash::Hash; use pallas_codec::utils::{AnyUInt, Bytes, Int, KeyValuePairs};
use pallas::ledger::addresses::{Address, ShelleyDelegationPart, ShelleyPaymentPart, StakePayload}; use pallas_crypto::hash::Hash;
use pallas::ledger::primitives::babbage::{AssetName, BigInt, Constr, Mint, PlutusData, ScriptRef}; use pallas_primitives::babbage::{AssetName, BigInt, Constr, Mint, PlutusData, ScriptRef};
use pallas::ledger::primitives::babbage::{ use pallas_primitives::babbage::{
Certificate, DatumOption, PseudoScript, Redeemer, StakeCredential, TransactionInput, Certificate, DatumOption, PseudoScript, Redeemer, StakeCredential, TransactionInput,
TransactionOutput, Value, TransactionOutput, Value,
}; };
use pallas::ledger::traverse::ComputeHash; use pallas_traverse::ComputeHash;
use crate::machine::runtime::{convert_constr_to_tag, ANY_TAG}; use crate::machine::runtime::{convert_constr_to_tag, ANY_TAG};

View File

@ -112,7 +112,7 @@ fn constant_data_constr() {
tag: 122, tag: 122,
any_constructor: None, any_constructor: None,
fields: vec![PlutusData::BigInt( fields: vec![PlutusData::BigInt(
pallas::ledger::primitives::alonzo::BigInt::Int(2.into()), pallas_primitives::alonzo::BigInt::Int(2.into()),
)], )],
})) }))
.into(), .into(),
@ -127,11 +127,11 @@ fn constant_data_map() {
Term::<Name>::Constant( Term::<Name>::Constant(
Constant::Data(PlutusData::Map(uplc::KeyValuePairs::Def(vec![ Constant::Data(PlutusData::Map(uplc::KeyValuePairs::Def(vec![
( (
PlutusData::BigInt(pallas::ledger::primitives::alonzo::BigInt::Int(0.into())), PlutusData::BigInt(pallas_primitives::alonzo::BigInt::Int(0.into())),
PlutusData::BoundedBytes(vec![0x00].into()), PlutusData::BoundedBytes(vec![0x00].into()),
), ),
( (
PlutusData::BigInt(pallas::ledger::primitives::alonzo::BigInt::Int(1.into())), PlutusData::BigInt(pallas_primitives::alonzo::BigInt::Int(1.into())),
PlutusData::BoundedBytes(vec![0x0f].into()), PlutusData::BoundedBytes(vec![0x0f].into()),
), ),
]))) ])))
@ -146,8 +146,8 @@ fn constant_data_list() {
round_trip( round_trip(
Term::<Name>::Constant( Term::<Name>::Constant(
Constant::Data(PlutusData::Array(vec![ Constant::Data(PlutusData::Array(vec![
PlutusData::BigInt(pallas::ledger::primitives::alonzo::BigInt::Int(0.into())), PlutusData::BigInt(pallas_primitives::alonzo::BigInt::Int(0.into())),
PlutusData::BigInt(pallas::ledger::primitives::alonzo::BigInt::Int(1.into())), PlutusData::BigInt(pallas_primitives::alonzo::BigInt::Int(1.into())),
])) ]))
.into(), .into(),
), ),
@ -160,7 +160,7 @@ fn constant_data_int() {
round_trip( round_trip(
Term::<Name>::Constant( Term::<Name>::Constant(
Constant::Data(PlutusData::BigInt( Constant::Data(PlutusData::BigInt(
pallas::ledger::primitives::alonzo::BigInt::Int(2.into()), pallas_primitives::alonzo::BigInt::Int(2.into()),
)) ))
.into(), .into(),
), ),
@ -169,14 +169,14 @@ fn constant_data_int() {
let term = Term::<Name>::Constant( let term = Term::<Name>::Constant(
Constant::Data(PlutusData::BigInt( Constant::Data(PlutusData::BigInt(
pallas::ledger::primitives::alonzo::BigInt::BigUInt(vec![2, 3, 4].into()), pallas_primitives::alonzo::BigInt::BigUInt(vec![2, 3, 4].into()),
)) ))
.into(), .into(),
); );
assert_eq!(term.to_pretty(), "(con data (I 131844))"); assert_eq!(term.to_pretty(), "(con data (I 131844))");
let term = Term::<Name>::Constant( let term = Term::<Name>::Constant(
Constant::Data(PlutusData::BigInt( Constant::Data(PlutusData::BigInt(
pallas::ledger::primitives::alonzo::BigInt::BigNInt(vec![2, 3, 3].into()), pallas_primitives::alonzo::BigInt::BigNInt(vec![2, 3, 3].into()),
)) ))
.into(), .into(),
); );