Skip to content

Commit

Permalink
cr feedback, fixed storageAppend
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Oct 5, 2021
1 parent af87966 commit 6fa9243
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func TestHandleChainReorg_WithReorg_Transactions(t *testing.T) {
// create extrinsic
enc, err := scale.Marshal([]byte("nootwashere"))
require.NoError(t, err)
// we prefix with []byte{2} here since that's the enum index for the old IncludeDataExt extrinsic
tx := append([]byte{2}, enc...)

bhash := s.blockState.BestBlockHash()
Expand Down
13 changes: 7 additions & 6 deletions lib/runtime/life/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ func (in *Instance) Version() (runtime.Version, error) {
version := &runtime.VersionData{}
err = version.Decode(res)
// error comes from scale now, so do a string check
if strings.Contains(fmt.Sprintf("%s", err), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
} else if err != nil {
if err != nil {
if strings.Contains(err.Error(), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
}
return nil, err
}

Expand Down
9 changes: 7 additions & 2 deletions lib/runtime/life/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,13 @@ func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error {
return nil
}

// append new item, pop off first byte now, since we're not using old scale.Decoder
valueRes = append(valueCurr[1:], valueToAppend...)
lengthBytes, err := scale.Marshal(currLength)
if err != nil {
return err
}
// append new item, pop off number of bytes required for length encoding,
// since we're not using old scale.Decoder
valueRes = append(valueCurr[len(lengthBytes):], valueToAppend...)

// increase length by 1
nextLength = big.NewInt(0).Add(currLength, big.NewInt(1))
Expand Down
13 changes: 7 additions & 6 deletions lib/runtime/wasmer/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ func (in *Instance) Version() (runtime.Version, error) {
version := &runtime.VersionData{}
err = version.Decode(res)
// error comes from scale now, so do a string check
if strings.Contains(fmt.Sprintf("%s", err), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
} else if err != nil {
if err != nil {
if strings.Contains(err.Error(), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
}
return nil, err
}

Expand Down
9 changes: 7 additions & 2 deletions lib/runtime/wasmer/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,13 @@ func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error {
return nil
}

// append new item, pop off first byte now, since we're not using old scale.Decoder
valueRes = append(valueCurr[1:], valueToAppend...)
lengthBytes, err := scale.Marshal(currLength)
if err != nil {
return err
}
// append new item, pop off number of bytes required for length encoding,
// since we're not using old scale.Decoder
valueRes = append(valueCurr[len(lengthBytes):], valueToAppend...)

// increase length by 1
nextLength = big.NewInt(0).Add(currLength, big.NewInt(1))
Expand Down

0 comments on commit 6fa9243

Please sign in to comment.