Skip to content

Commit

Permalink
✨ Improve validations for prop deletion on update
Browse files Browse the repository at this point in the history
  • Loading branch information
andremacedopv committed Jan 16, 2023
1 parent 3dff021 commit 9766b1e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions transactions/updateAssetType.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
sw "github.com/goledgerdev/cc-tools/stubwrapper"
)

// TODO: Update tag name?
// ? Update tag name?
// TODO: Handle not required -> required

// CreateAssetType is the transaction which creates a dynamic Asset Type
Expand Down Expand Up @@ -126,14 +126,18 @@ func handleProps(assetType assets.AssetType, propMap []interface{}) (assets.Asse
if deleteVal && !hasProp {
return assetType, errors.WrapError(err, "attempt to delete inexistent prop")
} else if deleteVal && hasProp {
// TODO: Handle required/isKey
// ? Should you be able to delete a required prop?
for i, prop := range propObj {
if prop.Tag == v["tag"].(string) {
if prop.IsKey {
return assetType, errors.NewCCError("cannot delete key prop", http.StatusBadRequest)
}
propObj = append(propObj[:i], propObj[i+1:]...)
}
}
} else if !hasProp && !deleteVal {
// TODO: Handle required/isKey prop
// ? Should you be able to create a isKey prop?
// TODO: Handle required prop
newProp, err := BuildAssetProp(v)
if err != nil {
return assetType, errors.WrapError(err, "failed to build prop")
Expand All @@ -158,7 +162,7 @@ func handleProps(assetType assets.AssetType, propMap []interface{}) (assets.Asse
}

func handlePropUpdate(assetProps assets.AssetProp, propMap map[string]interface{}) (assets.AssetProp, errors.ICCError) {
// TODO: Update tag?
// ? Update tag?
handleDefaultValue := false
for k, v := range propMap {
switch k {
Expand Down

0 comments on commit 9766b1e

Please sign in to comment.