How to use the @polkadot/util.isNull function in @polkadot/util

To help you get started, we’ve selected a few @polkadot/util 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-provider / src / ws / Provider.ts View on Github external
public disconnect (): void {
    if (isNull(this.websocket)) {
      throw new Error('Cannot disconnect on a non-open websocket');
    }

    // switch off autoConnect, we are in manual mode now
    this.autoConnect = false;

    // 1000 - Normal closure; the connection successfully completed
    this.websocket.close(1000);
    this.websocket = null;
  }
github polkadot-js / common / packages / trie-db / src / Impl.ts View on Github external
protected _snapshot (dest: TrieDb, fn: ProgressCb | undefined, root: Uint8Array, keys: number, percent: number, depth: number): number {
    // l.debug(() => ['snapshot', { root }]);

    const [encoded, node] = this._getNodeRaw(root);

    if (isNull(encoded) || isNull(node)) {
      return keys;
    }

    dest.db.put(root, encoded);

    fn && fn({ keys: ++keys, percent });

    node.forEach((u8a): void => {
      if (u8a && u8a.length === 32) {
        keys = this._snapshot(dest, fn, u8a, keys, percent, depth + 1);
      }

      percent += (100 / node.length) / Math.pow(16, depth);
    });

    return keys;
github polkadot-js / apps / packages / react-api / src / with / call.tsx View on Github external
private getParams (props: any): [boolean, any[]] {
        const paramValue = paramPick
          ? paramPick(props)
          : paramName
            ? props[paramName]
            : undefined;

        if (atProp) {
          at = props[atProp];
        }

        // When we are specifying a param and have an invalid, don't use it. For 'params',
        // we default to the original types, i.e. no validation (query app uses this)
        if (!paramValid && paramName && (isUndefined(paramValue) || isNull(paramValue))) {
          return [false, []];
        }

        const values = isUndefined(paramValue)
          ? params
          : params.concat(
            (Array.isArray(paramValue) && !(paramValue as any).toU8a)
              ? paramValue
              : [paramValue]
          );
        return [true, values];
      }
github polkadot-js / apps / packages / ui-api / src / with / call.tsx View on Github external
const [area, section, method, ...others] = endpoint.split('.');

        assert(area.length &amp;&amp; section.length &amp;&amp; method.length &amp;&amp; others.length === 0, `Invalid API format, expected <area>.<section>., found ${endpoint}`);
        assert(['rpc', 'query', 'derive'].includes(area), `Unknown api.${area}, expected rpc, query or derive`);
        assert(!at || area === 'query', 'Only able todo an at query on the api.query interface');

        const apiSection = (api as any)[area][section];

        assert(apiSection &amp;&amp; apiSection[method], `Unable to find api.${area}.${section}.${method}`);

        const meta = apiSection[method].meta;

        if (area === 'query' &amp;&amp; meta &amp;&amp; meta.type.isMap) {
          const arg = newParams[0];

          assert(!isUndefined(arg) &amp;&amp; !isNull(arg), `${meta.name} expects one argument`);
        }

        return [
          apiSection[method],
          newParams,
          area === 'derive' || (area === 'query' &amp;&amp; (!at &amp;&amp; !atProp)) || method.startsWith('subscribe')
        ];
      }
</section>
github polkadot-js / ui / packages / ui-shared / src / beachballIcon / demo.ts View on Github external
function generateIcon (seed: string = encodeAddress(randomAsU8a(32))): void {
  const start = Date.now();

  if (isNull(element)) {
    throw new Error('Unable to find #demo element');
  }

  element.appendChild(
    identicon(seed, 100, 'padded')
  );

  console.log(`Icon generated in ${(Date.now() - start)}ms`);
}
github polkadot-js / common / packages / trie-db / src / util / key.ts View on Github external
export function keyStartsWith (key: Uint8Array | null, partial: Uint8Array | null): boolean {
  if (isNull(key) &amp;&amp; isNull(partial)) {
    return true;
  } else if (isNull(key) || isNull(partial) || (key.length &lt; partial.length)) {
    return false;
  }

  for (let index = 0; index &lt; partial.length; index++) {
    if (key[index] !== partial[index]) {
      return false;
    }
  }

  return true;
}
github polkadot-js / common / packages / trie-db / src / util / is.ts View on Github external
export function isEmptyNode (node: Node): node is NodeEmpty {
  return isNull(node);
}
github polkadot-js / common / packages / trie-db / src / Impl.ts View on Github external
if (!keyStartsWith(trieKey, currentKey)) {
      return node;
    } else if (nodeType === NodeType.LEAF) {
      return keyEquals(trieKey, currentKey)
        ? null
        : node;
    }

    const subKey = trieKey.subarray(currentKey.length);
    const subNode = this._getNode(node[1]);
    const newSub = this._del(subNode, subKey);
    const encodedNewSub = this._persistNode(newSub);

    if (keyEquals(encodedNewSub, node[1])) {
      return node;
    } else if (isNull(newSub)) {
      return null;
    }

    if (isKvNode(newSub)) {
      const subNibbles = decodeNibbles(newSub[0]);
      const newKey = u8aConcat(currentKey, subNibbles);

      return [encodeNibbles(newKey), newSub[1]];
    } else if (isBranchNode(newSub)) {
      return [encodeNibbles(currentKey), encodedNewSub];
    }

    throw new Error('Unreachable');
  }
github polkadot-js / common / packages / trie-db / src / util / key.ts View on Github external
export function keyEquals (key: Uint8Array | null, test: Uint8Array | null): boolean {
  if (isNull(key) && isNull(test)) {
    return true;
  } else if (isNull(key) || isNull(test) || (key.length !== test.length)) {
    return false;
  }

  return keyStartsWith(key, test);
}