diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index 84856da6c..95a809c66 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -250,8 +250,21 @@ impl Slate { tx } - /// Create a new slate + /// Create a new slate with a plain kernel pub fn blank(num_participants: u8, is_invoice: bool) -> Slate { + Slate::blank_with_kernel_features(num_participants, is_invoice, 0, None) + } + + /// Create a new slate with custom kernel_feature and lock height + /// If a lock_height is set kernel_features will have to be either HeightLocked (2) or NoRecentDuplicate (3) + /// otherwise the value passed as lock_height will be ignored and a plain kernel will be created + /// Invalid arguments for kernel_features (>3) are not allowed and will make the function panic + pub fn blank_with_kernel_features( + num_participants: u8, + is_invoice: bool, + kernel_feat_param: u8, + lock_height_param: Option, + ) -> Slate { let np = match num_participants { 0 => 2, n => n, @@ -260,6 +273,19 @@ impl Slate { true => SlateState::Invoice1, false => SlateState::Standard1, }; + if kernel_feat_param > 3 { + panic!("Invalid value passed as kernel_feat_param to blank_with_kernel_features"); + } + let kernel_features = kernel_feat_param; + let is_height_locked = + lock_height_param.is_some() && (kernel_features == 2 || kernel_features == 3); + let kernel_feat_args = if is_height_locked { + Some(KernelFeaturesArgs { + lock_height: lock_height_param.unwrap(), + }) + } else { + None + }; Slate { num_participants: np, // assume 2 if not present id: Uuid::new_v4(), @@ -268,7 +294,7 @@ impl Slate { amount: 0, fee_fields: FeeFields::zero(), ttl_cutoff_height: 0, - kernel_features: 0, + kernel_features: kernel_features, offset: BlindingFactor::zero(), participant_data: vec![], version_info: VersionCompatInfo { @@ -276,9 +302,10 @@ impl Slate { block_header_version: GRIN_BLOCK_HEADER_VERSION, }, payment_proof: None, - kernel_features_args: None, + kernel_features_args: kernel_feat_args, } } + /// Removes any signature data that isn't mine, for compacting /// slates for a return journey pub fn remove_other_sigdata(