Skip to content

Commit

Permalink
Fix and improve CCF CDDL in comments
Browse files Browse the repository at this point in the history
Changes to CDDL notation and other comments include:
- Fix entitlement CCF CDDL
- Remove deprecated path-capability CCF CDDL
- Update inclusiverange-value CCF CDDL
- and other minor improvements
  • Loading branch information
fxamacker committed Oct 24, 2024
1 parent 3815ec4 commit ccf50a0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion encoding/ccf/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const (
CBORTagIntersectionTypeValue
CBORTagCapabilityTypeValue
CBORTagFunctionTypeValue
CBORTagInclusiveRangeTypeValue // InclusiveRange is stored as a composite value.
CBORTagInclusiveRangeTypeValue
CBORTagEntitlementSetAuthorizationAccessTypeValue
CBORTagEntitlementMapAuthorizationAccessTypeValue
_
Expand Down
15 changes: 1 addition & 14 deletions encoding/ccf/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ func (d *Decoder) decodeTypeAndValue(types *cadenceTypeByCCFTypeID) (cadence.Val
// / dict-value
// / composite-value
// / path-value
// / path-capability-value
// / id-capability-value
// / inclusiverange-value
// / function-value
Expand Down Expand Up @@ -1443,27 +1442,15 @@ func (d *Decoder) decodePath() (cadence.Value, error) {
return cadence.NewMeteredPath(d.gauge, common.PathDomain(pathDomain), identifier)
}

// decodeCapability decodes encoded capability-value as
// decodeCapability decodes encoded id-capability-value as
// language=CDDL
//
// capability-value =
//
// id-capability-value
// / path-capability-value
//
// id-capability-value = [
//
// address: address-value,
// id: uint64-value
//
// ]
//
// path-capability-value = [
//
// address: address-value,
// path: path-value
//
// ]
func (d *Decoder) decodeCapability(typ *cadence.CapabilityType, types *cadenceTypeByCCFTypeID) (cadence.Value, error) {
// typ can be different from runtime CapabilityType because borrow type can be nil.
// In this case, runtime type is encoded with the value (as tag content for tag CBORTagTypeAndValue).
Expand Down
18 changes: 9 additions & 9 deletions encoding/ccf/decode_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ func (d *Decoder) decodeCapabilityType(
//
// ; cbor-tag-entitlement-set-authorization-type
// #6.146([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
//
// entitlement-map-authorization-type =
//
// ; cbor-tag-entitlement-map-authorization-type
// #6.147(entitlement: string)
// #6.147(tstr)
//
// authorization-type-value =
//
Expand All @@ -382,14 +382,14 @@ func (d *Decoder) decodeCapabilityType(
//
// ; cbor-tag-entitlement-set-authorization-type-value
// #6.195([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
//
// entitlement-map-authorization-type-value =
//
// ; cbor-tag-entitlement-map-authorization-type-value
// #6.196(entitlement: string)
// #6.196(tstr)
func (d *Decoder) decodeAuthorization(isType bool) (cadence.Authorization, error) {
nt, err := d.dec.NextType()
if err != nil {
Expand Down Expand Up @@ -454,8 +454,8 @@ const entitlementSetAuthorizationArraySize = 2
//
// ; cbor-tag-entitlement-set-authorization-type
// #6.146([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
func (d *Decoder) decodeEntitlementSetAuthorization() (cadence.Authorization, error) {

Expand Down Expand Up @@ -569,7 +569,7 @@ func (d *Decoder) decodeEntitlementMapAuthorization() (cadence.Authorization, er
//
// ; cbor-tag-reference-type-value
// #6.190([
// authorized: authorization-type,
// authorized: authorization-type-value,
// type: type-value,
// ])
//
Expand Down
2 changes: 1 addition & 1 deletion encoding/ccf/decode_typedef.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (d *Decoder) decodeTypeDef(
// fields: [
// * [
// field-name: tstr,
// field-type: inline-type
// field-type: inline-type,
// ]
// ]
//
Expand Down
9 changes: 7 additions & 2 deletions encoding/ccf/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ func (e *Encoder) encodeTypeDefs(types []cadence.Type, tids ccfTypeIDByCadenceTy
// / dict-value
// / composite-value
// / path-value
// / path-capability-value
// / id-capability-value
// / inclusiverange-value
// / function-value
Expand Down Expand Up @@ -1030,7 +1029,13 @@ func encodeAndSortKeyValuePairs(

// encodeInclusiveRange encodes cadence.InclusiveRange as
// language=CDDL
// inclusiverange-value = [3*3 (key: value, value: value)]
// inclusiverange-value = [
//
// start: value,
// stop: value,
// step: value,
//
// ]
func (e *Encoder) encodeInclusiveRange(v *cadence.InclusiveRange, tids ccfTypeIDByCadenceType) error {
staticElementType := v.InclusiveRangeType.ElementType

Expand Down
18 changes: 9 additions & 9 deletions encoding/ccf/encode_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ func (e *Encoder) encodeReferenceType(
//
// ; cbor-tag-entitlement-set-authorization-type
// #6.146([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
//
// entitlement-map-authorization-type =
//
// ; cbor-tag-entitlement-map-authorization-type
// #6.147(entitlement: string)
// #6.147(tstr)
//
// authorization-type-value =
//
Expand All @@ -397,8 +397,8 @@ func (e *Encoder) encodeReferenceType(
//
// ; cbor-tag-entitlement-set-authorization-type-value
// #6.195([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
//
// entitlement-map-authorization-type-value =
Expand Down Expand Up @@ -442,8 +442,8 @@ func (e *Encoder) encodeAuthorization(
//
// ; cbor-tag-entitlement-set-authorization-type
// #6.146([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
//
// or
Expand All @@ -452,8 +452,8 @@ func (e *Encoder) encodeAuthorization(
//
// ; cbor-tag-entitlement-set-authorization-type-value
// #6.195([
// kind: uint8,
// entitlements: +[string]
// kind: uint,
// entitlements: [+ tstr],
// ])
func (e *Encoder) encodeEntitlementSetAuthorizationWithRawTag(
auth *cadence.EntitlementSetAuthorization,
Expand Down

0 comments on commit ccf50a0

Please sign in to comment.