How to use the @polkadot/types.withTypeString function in @polkadot/types

To help you get started, we’ve selected a few @polkadot/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / api / packages / api-contract / src / MetaRegistry.ts View on Github external
public typeDefFromMetaType (metaType: MetaType, typeIndex?: TypeIndex): TypeDef {
    return withTypeString({
      info: TypeDefInfo.Null,
      type: '',
      ...this.typeDefDefFields(metaType, typeIndex),
      ...this.typeDefIdFields(metaType)
    }) as TypeDef;
  }
github polkadot-js / api / packages / api-contract / src / MetaRegistry.ts View on Github external
private typeDefForTupleStruct (def: MetaTypeDefTupleStruct | MetaTypeDefEnumVariantTupleStruct): Pick {
    const tupleStructTypes = (def as MetaTypeDefTupleStruct)['tuple_struct.types'] || (def as MetaTypeDefEnumVariantTupleStruct)['tuple_struct_variant.types'];
    const tupleStructNameIndex = (def as MetaTypeDefEnumVariantTupleStruct)['tuple_struct_variant.name'];

    return withTypeString({
      info: TypeDefInfo.Tuple,
      ...(tupleStructNameIndex
        ? { name: this.stringAt(tupleStructNameIndex) }
        : {}
      ),
      sub: tupleStructTypes.map((fieldIndex: number, index: number): TypeDef => ({
        ...this.typeDefFromMetaTypeAt(fieldIndex),
        index
      }))
    });
  }
}
github polkadot-js / api / packages / api-contract / src / MetaRegistry.ts View on Github external
public typeDefForStruct (def: MetaTypeDefStruct | MetaTypeDefEnumVariantStruct): Pick {
    const structFields = (def as MetaTypeDefStruct)['struct.fields'] || (def as MetaTypeDefEnumVariantStruct)['struct_variant.fields'];
    const structNameIndex = (def as MetaTypeDefEnumVariantStruct)['struct_variant.name'];

    return withTypeString({
      info: TypeDefInfo.Struct,
      ...(structNameIndex
        ? { name: this.stringAt(structNameIndex) }
        : {}
      ),
      sub: structFields.map((field: MetaTypeDefStructField): TypeDef => ({
        ...this.typeDefFromMetaTypeAt(field.type),
        name: this.stringAt(field.name)
      }))
    });
  }