Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,8 @@ func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error {
msg := &network.TransactionMessage{Extrinsics: []types.Extrinsic{ext}}
return s.safeMsgSend(msg)
}

//GetMetadata calls runtime Metadata_metadata function
func (s *Service) GetMetadata() ([]byte, error) {
return s.rt.Exec(runtime.Metadata_metadata, []byte{})
}
1 change: 1 addition & 0 deletions dot/rpc/modules/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type CoreAPI interface {
GetRuntimeVersion() (*runtime.VersionAPI, error)
IsBabeAuthority() bool
HandleSubmittedExtrinsic(types.Extrinsic) error
GetMetadata() ([]byte, error)
}

// RPCAPI is the interface for methods related to RPC service
Expand Down
8 changes: 6 additions & 2 deletions dot/rpc/modules/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ func (sm *StateModule) GetKeys(r *http.Request, req *StateStorageKeyRequest, res
// TODO implement change storage trie so that block hash parameter works (See issue #834)
}

// GetMetadata isn't implemented properly yet.
func (sm *StateModule) GetMetadata(r *http.Request, req *StateRuntimeMetadataQuery, res *StateMetadataResponse) {
// GetMetadata calls runtime Metadata_metadata function
func (sm *StateModule) GetMetadata(r *http.Request, req *StateRuntimeMetadataQuery, res *string) error {
// TODO implement change storage trie so that block hash parameter works (See issue #834)
metadata, err := sm.coreAPI.GetMetadata()
// TODO use common.BytesToHex once PR #848 is merged
*res = "0x" + hex.EncodeToString(metadata)
Comment thread
edwardmack marked this conversation as resolved.
Outdated
return err
}

// GetRuntimeVersion Get the runtime version at a given block.
Expand Down
12 changes: 12 additions & 0 deletions dot/rpc/modules/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ func TestStateModule_GetStorageSize_NotFound(t *testing.T) {
require.Equal(t, nil, res)
}

func TestStateModule_GetMetadata(t *testing.T) {
sm := setupStateModule(t)
var res string
err := sm.GetMetadata(nil, nil, &res)

// currently this is generating an error because runtime has not implemented Metadata_metadata yet
// expect this to change when runtime changes
require.Equal(t, "0x", res)
require.EqualError(t, err, "Failed to call the `Metadata_metadata` exported function.")

}

func setupStateModule(t *testing.T) *StateModule {
// setup service
net := newNetworkService(t)
Expand Down
13 changes: 13 additions & 0 deletions lib/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ func TestConcurrentRuntimeCalls(t *testing.T) {
_, _ = runtime.Exec(CoreVersion, []byte{})
}()
}

func TestRuntime_Exec_Metadata(t *testing.T) {
var expected []byte
runtime := NewTestRuntime(t, POLKADOT_RUNTIME_c768a7e4c70e)

ret, err := runtime.Exec(Metadata_metadata, []byte{})

// currently this is returning an error because runtime has not implemented Metadata_metadata yet
// expect this to change when runtime changes
require.EqualError(t, err, "Failed to call the `Metadata_metadata` exported function.")
require.Equal(t, expected, ret)

}
2 changes: 2 additions & 0 deletions lib/runtime/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ var (
CoreInitializeBlock = "Core_initialize_block"
// CoreExecuteBlock is the runtime API call Core_execute_block
CoreExecuteBlock = "Core_execute_block"
// Metadata_metadata is the runtime API call Metadata_metadata
Metadata_metadata = "Metadata_metadata"
// TaggedTransactionQueueValidateTransaction is the runtime API call TaggedTransactionQueue_validate_transaction
TaggedTransactionQueueValidateTransaction = "TaggedTransactionQueue_validate_transaction"
// AuraAPIAuthorities is the runtime API call AuraApi_authorities
Expand Down