use tari_ootle_wallet_crypto::MaskAndValue;
use tari_template_lib::types::{bytes::Bytes, crypto::RistrettoPublicKeyBytes, stealth::SpendCondition};
#[derive(Debug, Clone)]
pub enum OutputAuthSpec {
KeyPathFromMask,
KeyPath(RistrettoPublicKeyBytes),
Conditions(Vec<SpendCondition>),
KeyAndConditions {
spend_key: RistrettoPublicKeyBytes,
conditions: Vec<SpendCondition>,
},
}
impl From<RistrettoPublicKeyBytes> for OutputAuthSpec {
fn from(pk: RistrettoPublicKeyBytes) -> Self {
Self::KeyPath(pk)
}
}
impl From<SpendCondition> for OutputAuthSpec {
fn from(condition: SpendCondition) -> Self {
Self::Conditions(vec![condition])
}
}
impl From<Vec<SpendCondition>> for OutputAuthSpec {
fn from(conditions: Vec<SpendCondition>) -> Self {
Self::Conditions(conditions)
}
}
pub struct OutputSpec {
value: u64,
auth: OutputAuthSpec,
}
impl OutputSpec {
pub fn new(value: u64, auth: OutputAuthSpec) -> Self {
Self { value, auth }
}
pub fn key_path_from_mask(value: u64) -> Self {
Self {
value,
auth: OutputAuthSpec::KeyPathFromMask,
}
}
pub fn value(&self) -> u64 {
self.value
}
pub fn auth(&self) -> &OutputAuthSpec {
&self.auth
}
}
impl From<u64> for OutputSpec {
fn from(amount: u64) -> Self {
Self::key_path_from_mask(amount)
}
}
impl From<(u64, SpendCondition)> for OutputSpec {
fn from((value, condition): (u64, SpendCondition)) -> Self {
Self {
value,
auth: OutputAuthSpec::Conditions(vec![condition]),
}
}
}
impl From<(u64, OutputAuthSpec)> for OutputSpec {
fn from((value, auth): (u64, OutputAuthSpec)) -> Self {
Self { value, auth }
}
}
#[derive(Debug, Clone)]
pub enum InputAuthSpec {
KeyPath,
ScriptPath {
conditions: Vec<SpendCondition>,
leaf: SpendCondition,
data: Bytes,
},
}
impl InputAuthSpec {
pub fn single(condition: SpendCondition) -> Self {
Self::ScriptPath {
conditions: vec![condition.clone()],
leaf: condition,
data: Bytes::default(),
}
}
pub fn script_path(conditions: Vec<SpendCondition>, leaf: SpendCondition, data: Bytes) -> Self {
Self::ScriptPath { conditions, leaf, data }
}
}
pub struct InputSpec {
mask_and_value: MaskAndValue,
auth: InputAuthSpec,
}
impl InputSpec {
pub fn new(mask_and_value: MaskAndValue) -> Self {
Self {
mask_and_value,
auth: InputAuthSpec::KeyPath,
}
}
pub fn with_auth(mask_and_value: MaskAndValue, auth: InputAuthSpec) -> Self {
Self { mask_and_value, auth }
}
pub fn mask_and_value(&self) -> &MaskAndValue {
&self.mask_and_value
}
pub fn auth(&self) -> &InputAuthSpec {
&self.auth
}
}
impl From<MaskAndValue> for InputSpec {
fn from(mask_and_value: MaskAndValue) -> Self {
Self::new(mask_and_value)
}
}
impl From<(MaskAndValue, SpendCondition)> for InputSpec {
fn from((mask_and_value, condition): (MaskAndValue, SpendCondition)) -> Self {
Self::with_auth(mask_and_value, InputAuthSpec::single(condition))
}
}
impl From<(MaskAndValue, InputAuthSpec)> for InputSpec {
fn from((mask_and_value, auth): (MaskAndValue, InputAuthSpec)) -> Self {
Self::with_auth(mask_and_value, auth)
}
}