diff --git a/crates/trp/src/compiler.rs b/crates/trp/src/compiler.rs index 02d6dc15..a108d04d 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::{ChainPoint, Domain, Genesis, StateStore}; use crate::{Config, Error}; @@ -50,18 +50,24 @@ fn build_pparams(domain: &D) -> Result { Ok(out) } - pub fn load_compiler( domain: &D, config: &Config, ) -> Result { let pparams = build_pparams::(domain)?; + let cursor = domain.state().read_cursor()?.ok_or(Error::TipNotResolved)?; + let slot = cursor.slot(); + let hash = cursor.hash().map(|h| h.to_vec()).unwrap_or_default(); + + let tip = tx3_cardano::ChainPoint { slot, hash }; + 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 97a5dc69..d326cb18 100644 --- a/crates/trp/src/methods.rs +++ b/crates/trp/src/methods.rs @@ -192,7 +192,7 @@ mod tests { const SUBJECT_PROTOCOL: &str = r#" party Sender; party Receiver; - + tx swap(quantity: Int) { input source { from: Sender,