How to use the @polkadot/extrinsics/codec/decode/length function in @polkadot/extrinsics

To help you get started, we’ve selected a few @polkadot/extrinsics 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 / common / packages / type-primitives / src / codec / block / decodeRaw.ts View on Github external
export default function decodeRaw (u8a: Uint8Array): RawData {
  // tslint:disable-next-line:variable-name
  const { body, header, number } = decodeHeader(u8a);
  const length = u8aToBn(body.subarray(0, 4), true).toNumber();
  const extrinsics = [];
  let offset = 4;

  for (let index = 0; index < length; index++) {
    const extrinsic = decodeExtrinsic(
      body.subarray(offset)
    );

    offset += extrinsic.length + 4;
    extrinsics.push(extrinsic);
  }

  return {
    body,
    extrinsics,
    header,
    number
  };
}