Skip to content

Commit

Permalink
Merge pull request #3301 from onflow/bastian/update-atree-register-in…
Browse files Browse the repository at this point in the history
…lining-v1.0-2
  • Loading branch information
turbolent authored May 1, 2024
2 parents e29e0f3 + 88681ed commit 09bb39a
Show file tree
Hide file tree
Showing 30 changed files with 1,652 additions and 1,238 deletions.
8 changes: 3 additions & 5 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11698,11 +11698,9 @@ func TestExportRecursiveType(t *testing.T) {

testEncode(
t,
cadence.Resource{
Fields: []cadence.Value{
cadence.Optional{},
},
}.WithType(ty),
cadence.NewResource([]cadence.Value{
cadence.Optional{},
}).WithType(ty),
[]byte{
// language=json, format=json-cdc
// {"type":"Resource","value":{"id":"S.test.Foo","fields":[{"name":"foo","value":{"type": "Optional","value":null}}]}}
Expand Down
40 changes: 34 additions & 6 deletions encoding/ccf/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
goRuntime "runtime"
"sort"
"sync"
_ "unsafe"

"github.com/fxamacker/cbor/v2"

Expand Down Expand Up @@ -1021,46 +1022,73 @@ func (e *Encoder) encodeInclusiveRange(v *cadence.InclusiveRange, tids ccfTypeID
return e.encodeValue(v.Step, staticElementType, tids)
}

//go:linkname getFieldValues github.com/onflow/cadence.getFieldValues
func getFieldValues(cadence.Composite) []cadence.Value

// encodeStruct encodes cadence.Struct as
// language=CDDL
// composite-value = [* (field: value)]
func (e *Encoder) encodeStruct(v cadence.Struct, tids ccfTypeIDByCadenceType) error {
return e.encodeComposite(v.StructType, v.Fields, tids)
return e.encodeComposite(
v.StructType,
getFieldValues(v),
tids,
)
}

// encodeResource encodes cadence.Resource as
// language=CDDL
// composite-value = [* (field: value)]
func (e *Encoder) encodeResource(v cadence.Resource, tids ccfTypeIDByCadenceType) error {
return e.encodeComposite(v.ResourceType, v.Fields, tids)
return e.encodeComposite(
v.ResourceType,
getFieldValues(v),
tids,
)
}

// encodeEvent encodes cadence.Event as
// language=CDDL
// composite-value = [* (field: value)]
func (e *Encoder) encodeEvent(v cadence.Event, tids ccfTypeIDByCadenceType) error {
return e.encodeComposite(v.EventType, v.Fields, tids)
return e.encodeComposite(
v.EventType,
getFieldValues(v),
tids,
)
}

// encodeContract encodes cadence.Contract as
// language=CDDL
// composite-value = [* (field: value)]
func (e *Encoder) encodeContract(v cadence.Contract, tids ccfTypeIDByCadenceType) error {
return e.encodeComposite(v.ContractType, v.Fields, tids)
return e.encodeComposite(
v.ContractType,
getFieldValues(v),
tids,
)
}

// encodeEnum encodes cadence.Enum as
// language=CDDL
// composite-value = [* (field: value)]
func (e *Encoder) encodeEnum(v cadence.Enum, tids ccfTypeIDByCadenceType) error {
return e.encodeComposite(v.EnumType, v.Fields, tids)
return e.encodeComposite(
v.EnumType,
getFieldValues(v),
tids,
)
}

// encodeAttachment encodes cadence.Attachment as
// language=CDDL
// composite-value = [* (field: value)]
func (e *Encoder) encodeAttachment(v cadence.Attachment, tids ccfTypeIDByCadenceType) error {
return e.encodeComposite(v.AttachmentType, v.Fields, tids)
return e.encodeComposite(
v.AttachmentType,
getFieldValues(v),
tids,
)
}

// encodeComposite encodes composite types as
Expand Down
Loading

0 comments on commit 09bb39a

Please sign in to comment.