diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index 15c40a04..f487d4d9 100644 --- a/crates/trp/src/compiler.rs +++ b/crates/trp/src/compiler.rs @@ -1,7 +1,7 @@ use pallas::ledger::primitives::conway::CostModels; use std::collections::HashMap; -use dolos_core::{Domain, Genesis}; +use dolos_core::{Domain, Genesis, StateStore}; use crate::{Config, Error}; @@ -47,18 +47,33 @@ fn build_pparams(domain: &D) -> Result { Ok(out) } - pub fn load_compiler( domain: &D, config: &Config, ) -> Result { let pparams = build_pparams::(domain)?; + let state = domain.state(); + let cursor = state.read_cursor()?.ok_or(Error::TipNotResolved)?; + let slot = cursor.slot(); + let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default(); + + let chain_summary = + dolos_cardano::eras::load_era_summary::(&state).map_err(|_| Error::TipNotResolved)?; + let timestamp = chain_summary.slot_time(slot) as u128 * 1000; + + let tip = tx3_cardano::ChainPoint { + slot, + hash, + timestamp, + }; + let compiler = tx3_cardano::Compiler::new( pparams, tx3_cardano::Config { extra_fees: config.extra_fees, }, + tip, ); Ok(compiler) diff --git a/crates/trp/src/error.rs b/crates/trp/src/error.rs index b7cfb7e2..7121bec4 100644 --- a/crates/trp/src/error.rs +++ b/crates/trp/src/error.rs @@ -52,6 +52,9 @@ pub enum Error { #[error("tx script returned failure")] TxScriptFailure(Vec), + + #[error("failed to resolve tip slot/hash")] + TipNotResolved, } trait IntoErrorData { @@ -128,6 +131,7 @@ impl Error { pub const CODE_MISSING_TX_ARG: i32 = -32001; pub const CODE_INPUT_NOT_RESOLVED: i32 = -32002; pub const CODE_TX_SCRIPT_FAILURE: i32 = -32003; + pub const CODE_TIP_NOT_RESOLVED: i32 = -32004; pub fn code(&self) -> i32 { match self { @@ -149,6 +153,7 @@ impl Error { Error::MissingTxArg { .. } => Self::CODE_MISSING_TX_ARG, Error::InputNotResolved(_, _, _) => Self::CODE_INPUT_NOT_RESOLVED, Error::TxScriptFailure(_) => Self::CODE_TX_SCRIPT_FAILURE, + Error::TipNotResolved => Self::CODE_TIP_NOT_RESOLVED, } } diff --git a/crates/trp/src/methods.rs b/crates/trp/src/methods.rs index 0fbac8f1..7c2737f5 100644 --- a/crates/trp/src/methods.rs +++ b/crates/trp/src/methods.rs @@ -191,7 +191,7 @@ mod tests { const SUBJECT_PROTOCOL: &str = r#" party Sender; party Receiver; - + tx swap(quantity: Int) { input source { from: Sender,