Skip to content

Commit

Permalink
remove the Encode method
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Sep 27, 2022
1 parent ca3c2a6 commit 6b40054
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 38 deletions.
2 changes: 1 addition & 1 deletion dot/sync/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func BuildBlock(t *testing.T, instance runtime.Instance, parent *types.Header, e
err = idata.SetInherent(types.Babeslot, uint64(1))
require.NoError(t, err)

ienc, err := idata.Encode()
ienc, err := scale.Marshal(*idata)
require.NoError(t, err)

// Call BlockBuilder_inherent_extrinsics which returns the inherents as encoded extrinsics
Expand Down
35 changes: 0 additions & 35 deletions dot/types/inherents.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
package types

import (
"bytes"
"fmt"
"math/big"

"github.com/ChainSafe/gossamer/pkg/scale"
)
Expand Down Expand Up @@ -81,36 +79,3 @@ func (d *InherentsData) SetInherent(inherentIdentifier InherentIdentifier, value

return nil
}

// Encode will encode a given []byte using scale.Encode
func (d *InherentsData) Encode() ([]byte, error) {
length := big.NewInt(int64(len(d.Data)))
buffer := bytes.Buffer{}

l, err := scale.Marshal(length)
if err != nil {
return nil, err
}

_, err = buffer.Write(l)
if err != nil {
return nil, err
}

for k, v := range d.Data {
_, err = buffer.Write(k[:])
if err != nil {
return nil, err
}

venc, err := scale.Marshal(v)
if err != nil {
return nil, fmt.Errorf("scale encoding encoded value: %w", err)
}
_, err = buffer.Write(venc)
if err != nil {
return nil, err
}
}
return buffer.Bytes(), nil
}
2 changes: 1 addition & 1 deletion lib/babe/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func buildBlockInherents(slot Slot, rt runtime.Instance, parent *types.Header) (
return nil, fmt.Errorf("setting struct inherent %q: %w", types.Newheads, err)
}

ienc, err := idata.Encode()
ienc, err := scale.Marshal(*idata)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func InitializeRuntimeToTest(t *testing.T, instance Instance, parentHash common.
err = idata.SetInherent(types.Babeslot, uint64(1))
require.NoError(t, err)

ienc, err := idata.Encode()
ienc, err := scale.Marshal(*idata)
require.NoError(t, err)

// Call BlockBuilder_inherent_extrinsics which returns the inherents as extrinsics
Expand Down

0 comments on commit 6b40054

Please sign in to comment.