Skip to content

Commit

Permalink
chore: resolve nil pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Sep 30, 2021
1 parent 1740d97 commit 12f7675
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions dot/rpc/modules/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func newTestStateService(t *testing.T) *state.Service {
stateSrvc.UseMemDB()

gen, genTrie, genesisHeader := genesis.NewTestGenesisWithTrieAndHeader(t)

err = stateSrvc.Initialise(gen, genesisHeader, genTrie)
require.NoError(t, err)

Expand Down
16 changes: 12 additions & 4 deletions dot/rpc/modules/childstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ func NewChildStateModule(s StorageAPI, b BlockAPI) *ChildStateModule {

// GetKeys returns the keys from the specified child storage. The keys can also be filtered based on a prefix.
func (cs *ChildStateModule) GetKeys(_ *http.Request, req *GetKeysRequest, res *[]string) error {
var hash common.Hash

if req.Hash == nil {
*req.Hash = cs.blockAPI.BestBlockHash()
hash = cs.blockAPI.BestBlockHash()
} else {
hash = *req.Hash
}

stateRoot, err := cs.storageAPI.GetStateRootFromBlock(req.Hash)
stateRoot, err := cs.storageAPI.GetStateRootFromBlock(&hash)
if err != nil {
return err
}
Expand All @@ -78,11 +82,15 @@ func (cs *ChildStateModule) GetKeys(_ *http.Request, req *GetKeysRequest, res *[

// GetStorageHash returns the hash of a child storage entry
func (cs *ChildStateModule) GetStorageHash(_ *http.Request, req *GetStorageHash, res *string) error {
var hash common.Hash

if req.Hash == nil {
*req.Hash = cs.blockAPI.BestBlockHash()
hash = cs.blockAPI.BestBlockHash()
} else {
hash = *req.Hash
}

stateRoot, err := cs.storageAPI.GetStateRootFromBlock(req.Hash)
stateRoot, err := cs.storageAPI.GetStateRootFromBlock(&hash)
if err != nil {
return err
}
Expand Down

0 comments on commit 12f7675

Please sign in to comment.