How to use the @polkadot/types.createClass 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 / rpc-core / src / index.ts View on Github external
const type = key.outputType || 'Raw';
    const meta = key.meta || EMPTY_META;
    const isEmpty = isNull(value);

    // we convert to Uint8Array since it maps to the raw encoding, all
    // data will be correctly encoded (incl. numbers, excl. :code)
    const input = isEmpty
      ? null
      : this.treatAsHex(key)
        ? value
        : u8aToU8a(value);

    if (meta.modifier.isOptional) {
      return new Option(
        this.registry,
        createClass(this.registry, type),
        isEmpty
          ? null
          : createTypeUnsafe(this.registry, type, [input], true)
      );
    }

    return createTypeUnsafe(this.registry, type, [isEmpty ? meta.fallback : input], true);
  }
github polkadot-js / api / packages / rpc-core / src / index.ts View on Github external
const isEmpty = isNull(value);
    const input = isEmpty
      ? null
      : this.treatAsHex(key)
        ? value
        : u8aToU8a(value);

    // store the retrieved result - the only issue with this cache is that there is no
    // clearing of it, so very long running processes (not just a couple of hours, longer)
    // will increase memory beyond what is allowed.
    this._storageCache.set(hexKey, value);

    if (meta.modifier.isOptional) {
      return new Option(
        this.registry,
        createClass(this.registry, type),
        isEmpty
          ? null
          : createTypeUnsafe(this.registry, type, [input], true)
      );
    }

    return createTypeUnsafe(this.registry, type, [isEmpty ? meta.fallback : input], true);
  }
}
github polkadot-js / api / packages / api-contract / src / util.ts View on Github external
export function formatData (registry: Registry, data: Raw, { info, type }: TypeDef): Codec {
  if (info === TypeDefInfo.Option) {
    return new Option(
      registry,
      createClass(registry, type),
      createTypeUnsafe(registry, type, [data], true)
    );
  }

  return createTypeUnsafe(registry, type, [data], true);
}
github polkadot-js / api / packages / api-contract / src / ContractRegistry.ts View on Github external
function createArgClass (registry: Registry, args: ContractABIFnArg[], baseDef: Record): Constructor {
  return createClass(
    registry,
    JSON.stringify(
      args.reduce((base: Record, { name, type }): Record => {
        base[name] = type.displayName || encodeType(type);

        return base;
      }, baseDef)
    )
  );
}
github polkadot-js / api / packages / api-contract / src / method.ts View on Github external
export function createArgClass (args: ContractABIFnArg[], baseDef: Record): Constructor {
  return createClass(
    JSON.stringify(
      args.reduce((base: Record, { name, type }): Record => {
        base[name] = encodeType(type);

        return base;
      }, baseDef)
    )
  );
}