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

Fix and improve CCF CDDL in comments #3643

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading