Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file_options_changed #762

Merged
merged 4 commits into from Feb 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions zboxcore/sdk/sdk.go
Expand Up @@ -941,7 +941,7 @@ func CreateAllocationForOwner(
allocationRequest["owner_id"] = owner
allocationRequest["owner_public_key"] = ownerpublickey
allocationRequest["third_party_extendable"] = thirdPartyExtendable
allocationRequest["file_options"] = calculateAllocationFileOptions(63 /*0011 1111*/, fileOptionsParams)
allocationRequest["file_options_changed"], allocationRequest["file_options"] = calculateAllocationFileOptions(63 /*0011 1111*/, fileOptionsParams)

var sn = transaction.SmartContractTxnData{
Name: transaction.NEW_ALLOCATION_REQUEST,
Expand Down Expand Up @@ -1143,7 +1143,7 @@ func UpdateAllocation(
updateAllocationRequest["add_blobber_id"] = addBlobberId
updateAllocationRequest["remove_blobber_id"] = removeBlobberId
updateAllocationRequest["set_third_party_extendable"] = setThirdPartyExtendable
updateAllocationRequest["file_options"] = calculateAllocationFileOptions(alloc.FileOptions, fileOptionsParams)
updateAllocationRequest["file_options_changed"], updateAllocationRequest["file_options"] = calculateAllocationFileOptions(alloc.FileOptions, fileOptionsParams)

sn := transaction.SmartContractTxnData{
Name: transaction.STORAGESC_UPDATE_ALLOCATION,
Expand Down Expand Up @@ -1475,38 +1475,45 @@ func GetAllocationMinLock(
}

// calculateAllocationFileOptions calculates the FileOptions 16-bit mask given the user input
func calculateAllocationFileOptions(initial uint16, fop *FileOptionsParameters) uint16 {
func calculateAllocationFileOptions(initial uint16, fop *FileOptionsParameters) (bool, uint16) {
if fop == nil {
return initial
return false, initial
}

mask := initial
changed := false

if fop.ForbidUpload.Changed {
changed = true
mask = updateMaskBit(mask, 0, !fop.ForbidUpload.Value)
}

if fop.ForbidDelete.Changed {
changed = true
mask = updateMaskBit(mask, 1, !fop.ForbidDelete.Value)
}

if fop.ForbidUpdate.Changed {
changed = true
mask = updateMaskBit(mask, 2, !fop.ForbidUpdate.Value)
}

if fop.ForbidMove.Changed {
changed = true
mask = updateMaskBit(mask, 3, !fop.ForbidMove.Value)
}

if fop.ForbidCopy.Changed {
changed = true
mask = updateMaskBit(mask, 4, !fop.ForbidCopy.Value)
}

if fop.ForbidRename.Changed {
changed = true
mask = updateMaskBit(mask, 5, !fop.ForbidRename.Value)
}

return mask
return changed, mask
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is changed the same as initial == mask?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got your point, I'll use initial == mask instead, nice one btw 👌

}

// updateMaskBit Set/Clear (based on `value`) bit value of the bit of `mask` at `index` (starting with LSB as 0) and return the updated mask
Expand Down