Skip to content

Commit 6a5c4c3

Browse files
committed
Add explicit() method for confidential::Value
1 parent 0194fb0 commit 6a5c4c3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/confidential.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ impl Value {
190190
_ => false,
191191
}
192192
}
193+
194+
/// Returns the explicit value.
195+
/// Returns [None] if [is_explicit] returns false.
196+
pub fn explicit(&self) -> Option<u64> {
197+
match *self {
198+
Value::Explicit(v) => Some(v),
199+
_ => None,
200+
}
201+
}
193202
}
194203

195204
/// A CT commitment to an asset
@@ -221,6 +230,15 @@ impl Asset {
221230
_ => false,
222231
}
223232
}
233+
234+
/// Unwrap the explicit value of this type.
235+
/// Panics if [is_explicit] returns false.
236+
pub fn unwrap_explicit(&self) -> sha256d::Hash {
237+
match *self {
238+
Asset::Explicit(v) => v,
239+
_ => panic!("Called unwrap_explicit on non-explicit asset: {:?}", self),
240+
}
241+
}
224242
}
225243

226244

@@ -255,6 +273,15 @@ impl Nonce {
255273
_ => false,
256274
}
257275
}
276+
277+
/// Unwrap the explicit value of this type.
278+
/// Panics if [is_explicit] returns false.
279+
pub fn unwrap_explicit(&self) -> sha256d::Hash {
280+
match *self {
281+
Nonce::Explicit(v) => v,
282+
_ => panic!("Called unwrap_explicit on non-explicit nonce: {:?}", self),
283+
}
284+
}
258285
}
259286

260287
#[cfg(test)]

0 commit comments

Comments
 (0)