@@ -144,6 +144,30 @@ type StateRuntimeVersionResponse struct {
144
144
Apis []interface {} `json:"apis"`
145
145
}
146
146
147
+ // NewStateRuntimeVersionResponse converts a runtime.Version to a
148
+ // StateRuntimeVersionResponse struct.
149
+ func NewStateRuntimeVersionResponse (runtimeVersion runtime.Version ) (
150
+ response StateRuntimeVersionResponse ) {
151
+ apisResponse := make ([]interface {}, len (runtimeVersion .APIItems ))
152
+ for i , apiItem := range runtimeVersion .APIItems {
153
+ hexItemName := hex .EncodeToString (apiItem .Name [:])
154
+ apisResponse [i ] = []interface {}{
155
+ "0x" + hexItemName ,
156
+ apiItem .Ver ,
157
+ }
158
+ }
159
+
160
+ return StateRuntimeVersionResponse {
161
+ SpecName : string (runtimeVersion .SpecName ),
162
+ ImplName : string (runtimeVersion .ImplName ),
163
+ AuthoringVersion : runtimeVersion .AuthoringVersion ,
164
+ SpecVersion : runtimeVersion .SpecVersion ,
165
+ ImplVersion : runtimeVersion .ImplVersion ,
166
+ TransactionVersion : runtimeVersion .TransactionVersion ,
167
+ Apis : apisResponse ,
168
+ }
169
+ }
170
+
147
171
// StateModule is an RPC module providing access to storage API points.
148
172
type StateModule struct {
149
173
networkAPI NetworkAPI
@@ -296,22 +320,15 @@ func (sm *StateModule) GetReadProof(
296
320
}
297
321
298
322
// GetRuntimeVersion Get the runtime version at a given block.
299
- // If no block hash is provided, the latest version gets returned.
323
+ // If no block hash is provided, the latest version gets returned.
300
324
func (sm * StateModule ) GetRuntimeVersion (
301
325
_ * http.Request , req * StateRuntimeVersionRequest , res * StateRuntimeVersionResponse ) error {
302
326
rtVersion , err := sm .coreAPI .GetRuntimeVersion (req .Bhash )
303
327
if err != nil {
304
328
return err
305
329
}
306
330
307
- res .SpecName = string (rtVersion .SpecName )
308
- res .ImplName = string (rtVersion .ImplName )
309
- res .AuthoringVersion = rtVersion .AuthoringVersion
310
- res .SpecVersion = rtVersion .SpecVersion
311
- res .ImplVersion = rtVersion .ImplVersion
312
- res .TransactionVersion = rtVersion .TransactionVersion
313
- res .Apis = ConvertAPIs (rtVersion .APIItems )
314
-
331
+ * res = NewStateRuntimeVersionResponse (rtVersion )
315
332
return nil
316
333
}
317
334
@@ -489,13 +506,3 @@ func (*StateModule) SubscribeStorage(
489
506
_ * http.Request , _ * StateStorageQueryRangeRequest , _ * StorageChangeSetResponse ) error {
490
507
return nil
491
508
}
492
-
493
- // ConvertAPIs runtime.APIItems to []interface
494
- func ConvertAPIs (in []runtime.APIItem ) []interface {} {
495
- ret := make ([]interface {}, 0 )
496
- for _ , item := range in {
497
- encStr := hex .EncodeToString (item .Name [:])
498
- ret = append (ret , []interface {}{"0x" + encStr , item .Ver })
499
- }
500
- return ret
501
- }
0 commit comments