Skip to content

Commit

Permalink
Merge pull request #2882 from onflow/fxamacker/integrate-with-atree
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Jan 24, 2024
2 parents fd29ad8 + ea8fd35 commit deffd50
Show file tree
Hide file tree
Showing 40 changed files with 2,376 additions and 567 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/kr/pretty v0.3.1
github.com/leanovate/gopter v0.2.9
github.com/logrusorgru/aurora/v4 v4.0.0
github.com/onflow/atree v0.6.1-0.20230706233410-78f997992600
github.com/onflow/atree v0.6.1-0.20231024210403-cb829958cc5f
github.com/rivo/uniseg v0.4.4
github.com/schollz/progressbar/v3 v3.13.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3px
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/onflow/atree v0.6.1-0.20230706233410-78f997992600 h1:OOnC8buJso6dSZ6W+RGQDnJW9UTh7HfEGyS/ivXJ7NI=
github.com/onflow/atree v0.6.1-0.20230706233410-78f997992600/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A=
github.com/onflow/atree v0.6.1-0.20231024210403-cb829958cc5f h1:mmc7WjCGwiEkt1GlANRRoxxJRz469gBG0ik755gJJpg=
github.com/onflow/atree v0.6.1-0.20231024210403-cb829958cc5f/go.mod h1:7YNAyCd5JENq+NzH+fR1ABUZVzbSq9dkt0+5fZH3L2A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw=
github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
Expand Down
16 changes: 13 additions & 3 deletions runtime/cmd/decode-state-values/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/schollz/progressbar/v3"

"github.com/onflow/cadence/runtime/common"
runtimeErr "github.com/onflow/cadence/runtime/errors"
"github.com/onflow/cadence/runtime/interpreter"
)

Expand Down Expand Up @@ -91,8 +92,12 @@ func storageKeyToSlabID(address atree.Address, key string) atree.SlabID {
return atree.NewSlabID(address, index)
}

func decodeStorable(decoder *cbor.StreamDecoder, storableSlabStorageID atree.SlabID) (atree.Storable, error) {
return interpreter.DecodeStorable(decoder, storableSlabStorageID, nil)
func decodeStorable(
decoder *cbor.StreamDecoder,
storableSlabStorageID atree.SlabID,
inlinedExtraData []atree.ExtraData,
) (atree.Storable, error) {
return interpreter.DecodeStorable(decoder, storableSlabStorageID, inlinedExtraData, nil)
}

func decodeTypeInfo(decoder *cbor.StreamDecoder) (atree.TypeInfo, error) {
Expand Down Expand Up @@ -136,6 +141,11 @@ type slabStorage struct{}

var _ atree.SlabStorage = &slabStorage{}

func (s *slabStorage) RetrieveIfLoaded(atree.SlabID) atree.Slab {
// RetrieveIfLoaded() is used for loaded resource tracking. So it isn't needed here.
panic(runtimeErr.NewUnreachableError())
}

func (s *slabStorage) Retrieve(id atree.SlabID) (atree.Slab, bool, error) {
data, ok := storage[slabIDToStorageKey(id)]
if !ok {
Expand Down Expand Up @@ -350,7 +360,7 @@ func loadStorageKey(

reader := bytes.NewReader(data)
decoder := interpreter.CBORDecMode.NewStreamDecoder(reader)
storable, err := interpreter.DecodeStorable(decoder, atree.SlabIDUndefined, nil)
storable, err := interpreter.DecodeStorable(decoder, atree.SlabIDUndefined, nil, nil)
if err != nil {
log.Printf(
"Failed to decode storable @ 0x%x %s: %s (data: %x)\n",
Expand Down
66 changes: 35 additions & 31 deletions runtime/convertValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,40 +562,44 @@ func exportDictionaryValue(
var err error
pairs := make([]cadence.KeyValuePair, 0, v.Count())

v.Iterate(inter, func(key, value interpreter.Value) (resume bool) {

var convertedKey cadence.Value
convertedKey, err = exportValueWithInterpreter(
key,
inter,
locationRange,
seenReferences,
)
if err != nil {
return false
}
v.Iterate(
inter,
locationRange,
func(key, value interpreter.Value) (resume bool) {

var convertedKey cadence.Value
convertedKey, err = exportValueWithInterpreter(
key,
inter,
locationRange,
seenReferences,
)
if err != nil {
return false
}

var convertedValue cadence.Value
convertedValue, err = exportValueWithInterpreter(
value,
inter,
locationRange,
seenReferences,
)
if err != nil {
return false
}
var convertedValue cadence.Value
convertedValue, err = exportValueWithInterpreter(
value,
inter,
locationRange,
seenReferences,
)
if err != nil {
return false
}

pairs = append(
pairs,
cadence.KeyValuePair{
Key: convertedKey,
Value: convertedValue,
},
)
pairs = append(
pairs,
cadence.KeyValuePair{
Key: convertedKey,
Value: convertedValue,
},
)

return true
})
return true
},
)

if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit deffd50

Please sign in to comment.