use ergotree_ir::chain::address::Address;
use ergotree_ir::ergo_tree::ErgoTree;
use ergotree_ir::serialization::SigmaParsingError;
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Contract {
ergo_tree: ErgoTree,
}
impl Contract {
pub fn new(ergo_tree: ErgoTree) -> Contract {
Contract { ergo_tree }
}
pub fn pay_to_address(address: &Address) -> Result<Contract, SigmaParsingError> {
Ok(Contract::new(address.script()?))
}
pub fn ergo_tree(&self) -> ErgoTree {
self.ergo_tree.clone()
}
#[cfg(feature = "compiler")]
pub fn compile(
source: &str,
env: ergoscript_compiler::script_env::ScriptEnv,
) -> Result<Contract, ergoscript_compiler::compiler::CompileError> {
let ergo_tree = ergoscript_compiler::compiler::compile(source, env)?;
Ok(Contract { ergo_tree })
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
#[cfg(feature = "compiler")]
#[test]
fn compile() {
let contract =
Contract::compile("HEIGHT", ergoscript_compiler::script_env::ScriptEnv::new()).unwrap();
dbg!(&contract);
}
}