Conversation
Co-authored-by: Dmitry Demin <dmidem@users.noreply.github.com>
…e type of the value was changed from ValueSum to NoteValue
…ntu package to be installed
…nfig Ubuntu package to be installed" This reverts commit c30e108.
…ich is required by the yeslogic-fontconfig-sys crate (a transitive dev dependency). The CI error started occurring after GitHub updated ubuntu-latest from Ubuntu 22.04 to 24.04.
…s field from SupplyInfo, add and use get_reference_note method to IssueAction
…t_reference_note, fix the tests accordingly
src/bundle/burn_validation.rs
Outdated
| if !asset_set.insert(asset) { | ||
| return Err(BurnError::DuplicateAsset); | ||
| } | ||
| for (asset, value) in burn.into_iter().cloned() { |
There was a problem hiding this comment.
Is it necessary to clone the iterator?
There was a problem hiding this comment.
The .cloned() method clones the iterating value, not the iterator itself. However, since we changed burn to be a slice, we don't need it now, so I removed it.
…tion in burn_validation, supply_info, and issuance
PaulLaux
left a comment
There was a problem hiding this comment.
added comments, one is significant.
| pub fn get_reference_note(&self) -> Option<&Note> { | ||
| self.notes.iter().find(|note| { | ||
| (note.recipient() == ReferenceKeys::recipient()) && (note.value() == NoteValue::zero()) | ||
| }) | ||
| } |
There was a problem hiding this comment.
So according to the finalized spec, the reference note must be the first note.
The logic should be:
- get first note
- check if it is the ref note
- if yes, return.
with .find() we might get a non deterministic behavior.
There was a problem hiding this comment.
use the existing verify_reference_note()
There was a problem hiding this comment.
So, if the first note doesn't match the reference note condition, it should return None even if, for example, there's the second note that does match the condition?
Now I changed it this way:
/// Returns the reference note.
pub fn get_reference_note(&self) -> Option<&Note> {
self.notes.first().filter(|note| {
(note.recipient() == ReferenceKeys::recipient()) && (note.value() == NoteValue::zero())
})
}It considers the first note only, and Option::filter additionally checks the referenence note condition for the first note.
There was a problem hiding this comment.
filter is fine
but the logic to verify a referance note repeat itself many times: see verify_reference_note() x2 in tests.
please extract and use the extracted fn ->bool here and in both tests.
Also update doc for this function.
There was a problem hiding this comment.
Now I added new function:
fn is_reference_note(note: &Note) -> bool {
note.value() == NoteValue::zero() && note.recipient() == ReferenceKeys::recipient()
}and used it in get_reference_note and verify_reference_note, but verify_reference_note still has an additional check for asset matching, which does make sense for the tests, but looks duplicated for get_reference_note as we already checked this in IssueAction::verify_supply. So, I kept verify_reference_note as a separate function that calls is_reference_note and performs an additional check for the asset matching.
| } | ||
|
|
||
| fn sum<'a, T: IntoIterator<Item = &'a AssetSupply>>(supplies: T) -> Option<ValueSum> { | ||
| fn sum<'a, T: IntoIterator<Item = &'a AssetSupply>>(supplies: T) -> Option<NoteValue> { |
There was a problem hiding this comment.
'a is not required:
fn sum<T: IntoIterator<Item = AssetSupply>>(supplies: T) -> Option<NoteValue> {
There was a problem hiding this comment.
It seems that it is needed :/
src/bundle/burn_validation.rs
Outdated
| /// * Any asset in the `burn` vector has a zero value (`BurnError::ZeroAmount`). | ||
| /// * Any asset in the `burn` vector is not unique (`BurnError::DuplicateAsset`). | ||
| pub fn validate_bundle_burn(burn: &[(AssetBase, NoteValue)]) -> Result<(), BurnError> { | ||
| let mut burn_set = HashMap::new(); |
There was a problem hiding this comment.
HashMap could be replaced by a HashSet with only the AssetBase inside it
PaulLaux
left a comment
There was a problem hiding this comment.
Very nice,
Please consider #133 (comment) and merge
This PR is an updated copy of #128:
The code was updated,
get_reference_notemethod ofIssueActionwas added and used,get_reference_noteswas removed. Also, instead of a separate newreference_notesHashMapinSupplyInfoa new fieldreference_notewas added toAssetSupplystruct. Unit tests were fixed accordingly.