mirror of https://github.com/zcash/orchard.git
Add serialization of finalize flag (#68)
Add a function `flags` to serialize the `finalize` flag of an IssueAction to a byte. This function will be used by the client.
This commit is contained in:
parent
02fa582c80
commit
9965a6d06b
|
@ -61,6 +61,23 @@ impl IssueAction {
|
|||
}
|
||||
}
|
||||
|
||||
/// Constructs a new `IssueAction`.
|
||||
pub fn new_with_finalize(asset_desc: String, note: &Note, flags: u8) -> Option<Self> {
|
||||
let finalize = match flags {
|
||||
0b0000_0000 => false,
|
||||
0b0000_0001 => true,
|
||||
_ => return None,
|
||||
};
|
||||
Some(IssueAction {
|
||||
asset_desc,
|
||||
notes: NonEmpty {
|
||||
head: *note,
|
||||
tail: vec![],
|
||||
},
|
||||
finalize,
|
||||
})
|
||||
}
|
||||
|
||||
/// Constructs an `IssueAction` from its constituent parts.
|
||||
pub fn from_parts(asset_desc: String, notes: NonEmpty<Note>, finalize: bool) -> Self {
|
||||
IssueAction {
|
||||
|
@ -134,6 +151,11 @@ impl IssueAction {
|
|||
.then(|| Ok((asset, AssetSupply::new(value_sum, self.is_finalized()))))
|
||||
.ok_or(IssueBundleIkMismatchAssetBase)?
|
||||
}
|
||||
|
||||
/// Serialize `finalize` flag to a byte
|
||||
pub fn flags(&self) -> u8 {
|
||||
self.finalize.then(|| 0b0000_0001).unwrap_or(0b0000_0000)
|
||||
}
|
||||
}
|
||||
|
||||
/// Defines the authorization type of an Issue bundle.
|
||||
|
@ -1272,6 +1294,23 @@ mod tests {
|
|||
WrongAssetDescSize
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_finalize_flag_serialization() {
|
||||
let mut rng = OsRng;
|
||||
let (_, _, note) = Note::dummy(&mut rng, None, AssetBase::native());
|
||||
|
||||
let action =
|
||||
IssueAction::new_with_finalize(String::from("Asset description"), ¬e, 0u8).unwrap();
|
||||
assert_eq!(action.flags(), 0b0000_0000);
|
||||
|
||||
let action =
|
||||
IssueAction::new_with_finalize(String::from("Asset description"), ¬e, 1u8).unwrap();
|
||||
assert_eq!(action.flags(), 0b0000_0001);
|
||||
|
||||
let action = IssueAction::new_with_finalize(String::from("Asset description"), ¬e, 2u8);
|
||||
assert!(action.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
/// Generators for property testing.
|
||||
|
|
Loading…
Reference in New Issue