diff --git a/packages/api-observable/src/Base.ts b/packages/api-observable/src/Base.ts index fcb87225b3..70b0ca7972 100644 --- a/packages/api-observable/src/Base.ts +++ b/packages/api-observable/src/Base.ts @@ -15,7 +15,7 @@ import { Vector } from '@polkadot/types/codec'; import { Hash, Method } from '@polkadot/types/index'; import Event from '@polkadot/types/Event'; import { StorageFunction } from '@polkadot/types/StorageKey'; -import { assert, isUndefined } from '@polkadot/util'; +import { assert, isUndefined, isU8a } from '@polkadot/util'; type MapFn = (combined: R) => T; @@ -104,9 +104,13 @@ export default class ApiBase { } // FIXME Remove when extending from api-rx - rawStorage = (key: StorageFunction, ...params: Array): Observable => { + rawStorage = (key: Uint8Array | StorageFunction, ...params: Array): Observable => { return this - .rawStorageMulti([key, ...params] as [StorageFunction, any]) + .rawStorageMulti( + isU8a(key) + ? key + : [key, ...params] as [StorageFunction, any] + ) .pipe( map((result: Array): T | undefined => result @@ -117,7 +121,7 @@ export default class ApiBase { } // FIXME Remove when extending from api-rx - rawStorageMulti = (...keys: Array<[StorageFunction] | [StorageFunction, any]>): Observable => { + rawStorageMulti = (...keys: Array): Observable => { let observable; try { diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 68766c4d6f..9c1ed456ac 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -179,12 +179,10 @@ export default class Rpc implements RpcInterface { if (method.type === 'StorageData') { // single return value (via state.getStorage), decode the value based on the - // outputType that we have specified - const type = (params[0] as StorageKey).outputType; + // outputType that we have specified. Fallback to Data on nothing + const type = (params[0] as StorageKey).outputType || 'Data'; - if (type) { - return createType(type, base.raw); - } + return createType(type, base.raw); } else if (method.type === 'StorageChangeSet') { // multiple return values (via state.storage subscription), decode the values // one at a time, all based on the query types. Three values can be returned - @@ -192,11 +190,8 @@ export default class Rpc implements RpcInterface { // - null - The storage key is empty (but in the resultset) // - undefined - The storage value is not in the resultset return (params[0] as Vector).reduce((result, _key: StorageKey) => { - const type = _key.outputType; - - if (!type) { - throw new Error('Cannot format StorageChangeSet, output type missing for key'); - } + // Fallback to Data (i.e. just the encoding) if we don't have a specific type + const type = _key.outputType || 'Data'; // see if we have a result value for this specific key const key = _key.toHex(); diff --git a/packages/types/src/StorageKey.ts b/packages/types/src/StorageKey.ts index 1515d66898..f53ce1fd74 100644 --- a/packages/types/src/StorageKey.ts +++ b/packages/types/src/StorageKey.ts @@ -38,6 +38,7 @@ export default class StorageKey extends Bytes { return fn(arg); } } + return value as Uint8Array; }