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

chore (pkg/scale) integrate scale pkg into dot/rpc #1678

Merged
merged 10 commits into from
Jul 8, 2021
7 changes: 4 additions & 3 deletions dot/rpc/modules/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// StateCallRequest holds json fields
Expand Down Expand Up @@ -272,8 +272,9 @@ func (sm *StateModule) GetMetadata(r *http.Request, req *StateRuntimeMetadataQue
return err
}

decoded, err := scale.Decode(metadata, []byte{})
*res = StateMetadataResponse(common.BytesToHex(decoded.([]byte)))
var decoded []byte
err = scale.Unmarshal(metadata, &decoded)
*res = StateMetadataResponse(common.BytesToHex(decoded))
return err
}

Expand Down
7 changes: 4 additions & 3 deletions dot/rpc/modules/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/pkg/scale"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

Expand Down Expand Up @@ -196,12 +196,13 @@ func (sm *SystemModule) AccountNextIndex(r *http.Request, req *StringRequest, re
if err != nil {
return err
}
sdMeta, err := scale.Decode(rawMeta, []byte{})
var sdMeta []byte
err = scale.Unmarshal(rawMeta, &sdMeta)
if err != nil {
return err
}
var metadata ctypes.Metadata
err = ctypes.DecodeFromBytes(sdMeta.([]byte), &metadata)
err = ctypes.DecodeFromBytes(sdMeta, &metadata)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/pkg/scale"
log "github.com/ChainSafe/log15"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -308,7 +308,7 @@ func setupSystemModule(t *testing.T) *SystemModule {
FreeFrozen common.Uint128
}{},
}
aliceAcctEncoded, err := scale.Encode(aliceAcctInfo)
aliceAcctEncoded, err := scale.Marshal(aliceAcctInfo)
require.NoError(t, err)
ts.Set(aliceAcctStoKey, aliceAcctEncoded)

Expand Down