import type { HexString } from 'https://deno.land/x/polkadot@0.2.40/util/types.ts';import type { AnyJson, Codec, Inspect, IU8a, IVec, Registry } from '../types/index.ts';
import { compactToU8a, u8aConcatStrict, u8aToHex } from 'https://deno.land/x/polkadot@0.2.40/util/mod.ts';
import { compareArray } from '../utils/compareArray.ts';
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> { readonly registry: Registry;
public createdAtHash?: IU8a; public initialU8aLength?: number; public isStorageFallback?: boolean;
static get [Symbol.species] (): typeof Array { return Array; }
protected constructor (registry: Registry, length: number) { super(length);
this.registry = registry; }
public get encodedLength (): number { const count = this.length; let total = compactToU8a(count).length;
for (let i = 0; i < count; i++) { total += this[i].encodedLength; }
return total; }
public get hash (): IU8a { return this.registry.hash(this.toU8a()); }
public get isEmpty (): boolean { return this.length === 0; }
public override get length (): number { return super.length; }
public eq (other?: unknown): boolean { return compareArray(this, other); }
public inspect (): Inspect { return { inner: this.inspectInner(), outer: [compactToU8a(this.length)] }; }
public inspectInner (): Inspect[] { const count = this.length; const inner = new Array<Inspect>(count);
for (let i = 0; i < count; i++) { inner[i] = this[i].inspect(); }
return inner; }
public toArray (): T[] { return Array.from(this); }
public toHex (): HexString { return u8aToHex(this.toU8a()); }
public toHuman (isExtended?: boolean): AnyJson { const count = this.length; const result = new Array<AnyJson>(count);
for (let i = 0; i < count; i++) { result[i] = this[i] && this[i].toHuman(isExtended); }
return result; }
public toJSON (): AnyJson { const count = this.length; const result = new Array<AnyJson>(count);
for (let i = 0; i < count; i++) { result[i] = this[i] && this[i].toJSON(); }
return result; }
public toPrimitive (): AnyJson { const count = this.length; const result = new Array<AnyJson>(count);
for (let i = 0; i < count; i++) { result[i] = this[i] && this[i].toPrimitive(); }
return result; }
abstract toRawType (): string;
public override toString (): string { const count = this.length; const result = new Array<string>(count);
for (let i = 0; i < count; i++) { result[i] = this[i].toString(); }
return `[${result.join(', ')}]`; }
public toU8a (isBare?: boolean): Uint8Array { const encoded = this.toU8aInner();
return isBare ? u8aConcatStrict(encoded) : u8aConcatStrict([compactToU8a(this.length), ...encoded]); }
public toU8aInner (isBare?: boolean): Uint8Array[] { const count = this.length; const encoded = new Array<Uint8Array>(count);
for (let i = 0; i < count; i++) { encoded[i] = this[i].toU8a(isBare); }
return encoded; }}