@polkadot/types/interfaces#StorageEntryMetadataLatest TypeScript Examples

The following examples show how to use @polkadot/types/interfaces#StorageEntryMetadataLatest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From substrate-api-explorer with Apache License 2.0 5 votes vote down vote up
function mapQueryMethodWithParams(method: StorageEntryMetadataLatest) {
  const methodName = _camelCase(method.name.toString())
  let params: { [key: string]: string | boolean }[] = []
  let type: string | null = null
  const methodMap = method.type.isMap ? method.type.asMap : null
  const methodPlain = method.type.isPlain ? method.type.asPlain : null
  const doubleMap = method.type.isDoubleMap ? method.type.asDoubleMap : null

  if (methodPlain) type = methodPlain.toString()
  if (methodMap) {
    params = [
      {
        isOptional: method.modifier.isOptional,
        name: methodMap.key.toString(),
        type: methodMap.hasher.toString(),
      },
    ]
    type = methodMap.value.toString()
  }
  if (doubleMap) {
    params = [
      {
        isOptional: method.modifier.isOptional,
        name: doubleMap.key1.toString(),
        type: doubleMap.hasher.toString(),
      },
      {
        isOptional: method.modifier.isOptional,
        name: doubleMap.key2.toString(),
        type: doubleMap.key2Hasher.toString(),
      },
    ]
    type = doubleMap.value.toString()
  }

  return {
    name: methodName,
    data: {
      type,
      params,
      description: formatDocs(method.documentation),
    },
  }
}