Skip to content
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
41 changes: 40 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions codec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pub mod address;
pub mod block;
pub mod certs;
pub mod parameter;
pub mod tx;
pub mod utils;
pub mod utxo;
mod address;
mod block;
mod certs;
mod parameter;
mod tx;
mod utils;
mod utxo;
mod witness;

pub use address::*;
pub use block::*;
Expand All @@ -13,3 +14,4 @@ pub use parameter::*;
pub use tx::*;
pub use utils::*;
pub use utxo::*;
pub use witness::*;
4 changes: 2 additions & 2 deletions codec/src/utxo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::address::map_address;
use crate::{address::map_address, witness::map_native_script};
use acropolis_common::{validation::TransactionValidationError, *};
use pallas_primitives::conway;
use pallas_traverse::{MultiEraInput, MultiEraPolicyAssets, MultiEraTx, MultiEraValue};
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn map_datum(datum: &Option<conway::MintedDatumOption>) -> Option<Datum> {
pub fn map_reference_script(script: &Option<conway::MintedScriptRef>) -> Option<ReferenceScript> {
match script {
Some(conway::PseudoScript::NativeScript(script)) => {
Some(ReferenceScript::Native(script.raw_cbor().to_vec()))
Some(ReferenceScript::Native(map_native_script(script)))
}
Some(conway::PseudoScript::PlutusV1Script(script)) => {
Some(ReferenceScript::PlutusV1(script.as_ref().to_vec()))
Expand Down
35 changes: 35 additions & 0 deletions codec/src/witness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use acropolis_common::{AddrKeyhash, NativeScript, VKeyWitness};
use pallas_primitives::{KeepRaw, alonzo};

pub fn map_vkey_witness(vkey_witness: &alonzo::VKeyWitness) -> VKeyWitness {
VKeyWitness::new(vkey_witness.vkey.to_vec(), vkey_witness.signature.to_vec())
}

pub fn map_vkey_witnesses(vkey_witnesses: &[alonzo::VKeyWitness]) -> Vec<VKeyWitness> {
vkey_witnesses.iter().map(map_vkey_witness).collect()
}

pub fn map_native_script(script: &alonzo::NativeScript) -> NativeScript {
match script {
alonzo::NativeScript::ScriptPubkey(addr_key_hash) => {
NativeScript::ScriptPubkey(AddrKeyhash::from(**addr_key_hash))
}
alonzo::NativeScript::ScriptAll(scripts) => {
NativeScript::ScriptAll(scripts.iter().map(map_native_script).collect())
}
alonzo::NativeScript::ScriptAny(scripts) => {
NativeScript::ScriptAny(scripts.iter().map(map_native_script).collect())
}
alonzo::NativeScript::ScriptNOfK(n, scripts) => {
NativeScript::ScriptNOfK(*n, scripts.iter().map(map_native_script).collect())
}
alonzo::NativeScript::InvalidBefore(slot_no) => NativeScript::InvalidBefore(*slot_no),
alonzo::NativeScript::InvalidHereafter(slot_no) => NativeScript::InvalidHereafter(*slot_no),
}
}

pub fn map_native_scripts<'b>(
native_scripts: &[KeepRaw<'b, alonzo::NativeScript>],
) -> Vec<NativeScript> {
native_scripts.iter().map(|script| map_native_script(script)).collect()
}
8 changes: 8 additions & 0 deletions common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ impl Address {
None
}

/// Get payment part
pub fn get_payment_part(&self) -> Option<ShelleyAddressPaymentPart> {
if let Address::Shelley(shelley) = self {
return Some(shelley.payment.clone());
}
None
}

/// Read from string format ("addr1...")
pub fn from_string(text: &str) -> Result<Self> {
if text.starts_with("addr1") || text.starts_with("addr_test1") {
Expand Down
8 changes: 8 additions & 0 deletions common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ pub struct GenesisUTxOsMessage {
pub utxos: Vec<(UTxOIdentifier, TxIdentifier)>,
}

/// Message encapsulating multiple unpacked transactions, in order
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UnpackedTransactionsMessage {
/// Ordered array of unpacked transactions
pub transactions: Vec<Transaction>,
}

/// Message encapsulating multiple UTXO deltas, in order
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UTXODeltasMessage {
Expand Down Expand Up @@ -314,6 +321,7 @@ pub enum CardanoMessage {
ReceivedTxs(RawTxsMessage), // Transaction available
GenesisComplete(GenesisCompleteMessage), // Genesis UTXOs done + genesis params
GenesisUTxOs(GenesisUTxOsMessage), // Genesis UTxOs with their UTxOIdentifiers
UnpackedTransactions(UnpackedTransactionsMessage), // Unpacked transactions received
UTXODeltas(UTXODeltasMessage), // UTXO deltas received
AssetDeltas(AssetDeltasMessage), // Asset mint and burn deltas
TxCertificates(TxCertificatesMessage), // Transaction certificates received
Expand Down
Loading