refactor: Re-organize and clean-up pallas-primitives (#523)
* Re-organize and clean-up pallas-primitives
Namely:
- Move _common_ (i.e. era-independent) types and structures up to the
`lib` module; to be shared across all eras. If any of those deviate
in a subsequent era, it is easy to bring them down and define new
types from the point of divergence onward. This simplifies the scope
of each era-specific module and make them slightly easier to
navigate.
Note that, each era module still re-export all of the common types
that's relevant to that particular era. So technically, this
reorganization doesn't really change anything for callers/users of
the library.
- Rename `Scripthash` to `ScriptHash`. Before this commit, both
actually existed as `ScriptHash` was introduced with the Conway era.
Yet, they refer to the same thing, so the duplication is simply
confusing.
- Rename `One` / `Two` constructors for `NetworkId` to `Testnet` and
`Mainnet` respectively. Also defined idiomatic `From` & `TryFrom`
implementation for conversion to and from `u8`. This is a lot let
confusing!
- Generalize `PlutusScript` with a constant generic, to avoid
repetition for each plutus script generated for specific version.
Note that a distinction is still _necessary_ if we want to provie
out-of-the-box serialisers for Plutus scripts, which are serialised
with a tag prefix depending on the language. All else apart, they
are strictly similar types.
- Rename `CostMdls` to `CostModels`. Because, common.
- Rename `plutus_script` to `plutus_v1_script` in the Alonzo's witness
set, for consistency with other eras.
* Fix ordering of ScriptHash variants.
This is an odd one. See the note.
* Bump minicbor to v0.25.1
* Add aliases with deprecation warnings to various fields and types.
* revert renaming plutus_script to plutus_v1_script in Alonzo witness
See https://github.com/txpipe/pallas/pull/523#discussion_r1807329742
This commit is contained in:
parent
7d79407163
commit
6b667c78a3
26 changed files with 972 additions and 1071 deletions
|
|
@ -4,10 +4,10 @@ use pallas_codec::utils::{CborWrap, KeyValuePairs};
|
|||
use pallas_crypto::hash::Hash;
|
||||
use pallas_primitives::{
|
||||
babbage::{
|
||||
DatumOption, ExUnits as PallasExUnits, NativeScript, NetworkId, PlutusData, PlutusV1Script,
|
||||
PlutusV2Script, PostAlonzoTransactionOutput, PseudoScript as PallasScript,
|
||||
PseudoTransactionOutput, Redeemer, RedeemerTag, TransactionBody, TransactionInput,
|
||||
Tx as BabbageTx, Value, WitnessSet,
|
||||
DatumOption, ExUnits as PallasExUnits, NativeScript, NetworkId, PlutusData, PlutusScript,
|
||||
PostAlonzoTransactionOutput, PseudoScript as PallasScript, PseudoTransactionOutput,
|
||||
Redeemer, RedeemerTag, TransactionBody, TransactionInput, Tx as BabbageTx, Value,
|
||||
WitnessSet,
|
||||
},
|
||||
Fragment,
|
||||
};
|
||||
|
|
@ -88,10 +88,9 @@ impl BuildBabbage for StagingTransaction {
|
|||
.collect();
|
||||
|
||||
let network_id = if let Some(nid) = self.network_id {
|
||||
match nid {
|
||||
0 => Some(NetworkId::One),
|
||||
1 => Some(NetworkId::Two),
|
||||
_ => return Err(TxBuilderError::InvalidNetworkId),
|
||||
match NetworkId::try_from(nid) {
|
||||
Err(()) => return Err(TxBuilderError::InvalidNetworkId),
|
||||
Ok(network_id) => Some(network_id),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
|
@ -125,12 +124,12 @@ impl BuildBabbage for StagingTransaction {
|
|||
native_script.push(script)
|
||||
}
|
||||
ScriptKind::PlutusV1 => {
|
||||
let script = PlutusV1Script(script.bytes.into());
|
||||
let script = PlutusScript::<1>(script.bytes.into());
|
||||
|
||||
plutus_v1_script.push(script)
|
||||
}
|
||||
ScriptKind::PlutusV2 => {
|
||||
let script = PlutusV2Script(script.bytes.into());
|
||||
let script = PlutusScript::<2>(script.bytes.into());
|
||||
|
||||
plutus_v2_script.push(script)
|
||||
}
|
||||
|
|
@ -313,12 +312,12 @@ impl Output {
|
|||
NativeScript::decode_fragment(s.bytes.as_ref())
|
||||
.map_err(|_| TxBuilderError::MalformedScript)?,
|
||||
),
|
||||
ScriptKind::PlutusV1 => {
|
||||
PallasScript::PlutusV1Script(PlutusV1Script(s.bytes.as_ref().to_vec().into()))
|
||||
}
|
||||
ScriptKind::PlutusV2 => {
|
||||
PallasScript::PlutusV2Script(PlutusV2Script(s.bytes.as_ref().to_vec().into()))
|
||||
}
|
||||
ScriptKind::PlutusV1 => PallasScript::PlutusV1Script(PlutusScript::<1>(
|
||||
s.bytes.as_ref().to_vec().into(),
|
||||
)),
|
||||
ScriptKind::PlutusV2 => PallasScript::PlutusV2Script(PlutusScript::<2>(
|
||||
s.bytes.as_ref().to_vec().into(),
|
||||
)),
|
||||
};
|
||||
|
||||
Some(CborWrap(script))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue