Skip to content

Commit

Permalink
Add integer primitive data type
Browse files Browse the repository at this point in the history
  • Loading branch information
bandreghetti committed Oct 5, 2020
1 parent a69cfd1 commit 7d17eff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/assetProp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AssetProp struct {
ReadOnly bool `json:"readOnly"`

/* DataType can assume the following values:
Primary types: "string", "number", "boolean", "datetime"
Primary types: "string", "number", "integer", "boolean", "datetime"
Special types:
<assetType>: the specific asset type key (reference) as defined by <assetType> in the assets packages
[]<type>: an array of elements specified by <type> as any of the above valid types
Expand Down
26 changes: 26 additions & 0 deletions assets/dataType.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ var dataTypeMap = map[string]DataType{
return strconv.FormatUint(math.Float64bits(dataVal), 16), dataVal, nil
},
},
"integer": {
AcceptedFormats: []string{"number"},
Parse: func(data interface{}) (string, interface{}, error) {
dataVal, ok := data.(float64)
if !ok {
propValStr, okStr := data.(string)
if !okStr {
return "", nil, errors.NewCCError("asset property should be an integer", 400)
}
var err error
dataVal, err = strconv.ParseFloat(propValStr, 64)
if err != nil {
return "", nil, errors.WrapErrorWithStatus(err, fmt.Sprintf("asset property should be an integer"), 400)
}
}

retVal := math.Trunc(dataVal)

if dataVal != retVal {
return "", nil, errors.NewCCError("asset property should be an integer", 400)
}

// Float IEEE 754 hexadecimal representation
return fmt.Sprintf("%d", int64(retVal)), int64(retVal), nil
},
},
"boolean": {
AcceptedFormats: []string{"boolean"},
Parse: func(data interface{}) (string, interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion transactions/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Argument struct {
Description string `json:"description"`

/* DataType can assume the following values:
Primary types: "string", "number", "boolean", "datetime"
Primary types: "string", "number", "integer", "boolean", "datetime"
Special types:
@asset: any asset type defined in the assets package
@key: key properties for any asset type defined in the assets package
Expand Down

0 comments on commit 7d17eff

Please sign in to comment.