Skip to content

Commit

Permalink
Merge pull request #3643 from onflow/fxamacker/update-ccf-cddl-in-com…
Browse files Browse the repository at this point in the history
…ments-2

Fix and improve CCF CDDL in comments
  • Loading branch information
fxamacker authored Oct 24, 2024
2 parents af8e417 + e3c3821 commit c4e631e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 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
17 changes: 2 additions & 15 deletions encoding/ccf/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ func (d *Decoder) decodeTypeAndValue(types *cadenceTypeByCCFTypeID) (cadence.Val
// / dict-value
// / composite-value
// / path-value
// / path-capability-value
// / id-capability-value
// / capability-value
// / inclusiverange-value
// / function-value
// / type-value
Expand Down Expand Up @@ -1446,24 +1445,12 @@ func (d *Decoder) decodePath() (cadence.Value, error) {
// decodeCapability decodes encoded capability-value as
// language=CDDL
//
// capability-value =
//
// id-capability-value
// / path-capability-value
//
// id-capability-value = [
// 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
13 changes: 9 additions & 4 deletions encoding/ccf/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ func (e *Encoder) encodeTypeDefs(types []cadence.Type, tids ccfTypeIDByCadenceTy
// / dict-value
// / composite-value
// / path-value
// / path-capability-value
// / id-capability-value
// / capability-value
// / inclusiverange-value
// / function-value
// / type-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 Expand Up @@ -1240,7 +1245,7 @@ func (e *Encoder) encodePath(x cadence.Path) error {

// encodeCapability encodes cadence.Capability as
// language=CDDL
// id-capability-value = [
// capability-value = [
//
// address: address-value,
// id: uint64-value
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 c4e631e

Please sign in to comment.