Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Map<TKey, TValue>

Type Parameters

  • TKey

  • TValue

Hierarchy

  • Map

Index

Constructors

  • new Map<TKey, TValue>(contractId: Uint8Array, spaceId: number, valueDecoder: ((reader: Reader, length: number) => TValue), valueEncoder: ((message: TValue, writer: Writer) => void), defaultValue?: null | (() => null | TValue), system?: bool): Map<TKey, TValue>
  • Initialize a Space object with TKey the type of the keys and TValue the type of the values

    example
    const contractId = Base58.decode('1DQzuCcTKacbs9GGScFTU1Hc8BsyARTPqe');
    const BALANCES_SPACE_ID = 1;
    const balances = new Storage.Map(
    this.contractId,
    BALANCES_SPACE_ID,
    token.uint64.decode,
    token.uint64.encode,
    () => new token.uint64(0)
    );

    Type Parameters

    • TKey

    • TValue

    Parameters

    • contractId: Uint8Array

      the id of the contract

    • spaceId: number

      the id of the space

    • valueDecoder: ((reader: Reader, length: number) => TValue)

      the protobuf decoder for the values

        • (reader: Reader, length: number): TValue
        • Parameters

          • reader: Reader
          • length: number

          Returns TValue

    • valueEncoder: ((message: TValue, writer: Writer) => void)

      the protobuf encoder for the values

        • (message: TValue, writer: Writer): void
        • Parameters

          • message: TValue
          • writer: Writer

          Returns void

    • defaultValue: null | (() => null | TValue) = null

      arrow function that returns the default value

    • system: bool = false

      is system space

    Returns Map<TKey, TValue>

Properties

defaultValue: null | (() => null | TValue)
valueDecoder: ((reader: Reader, length: number) => TValue)

Type declaration

    • (reader: Reader, length: number): TValue
    • Parameters

      • reader: Reader
      • length: number

      Returns TValue

valueEncoder: ((message: TValue, writer: Writer) => void)

Type declaration

    • (message: TValue, writer: Writer): void
    • Parameters

      • message: TValue
      • writer: Writer

      Returns void

Methods

  • get(key: TKey): null | TValue
  • Get an object from the space

    example
    const obj = Objects.get('key1');

    if (obj != null) {
    ...
    }

    Parameters

    • key: TKey

      key to get

    Returns null | TValue

    the object if exists, null otherwise

  • Get many objects from the space

    example
    const objs = Objects.getMany('key1', 10, Space.Direction.Descending);

    for (let index = 0; index < objs.length; index++) {
    const obj = objs[index];
    }

    Parameters

    • offsetKey: TKey

      key used as the offset

    • limit: number = i32.MAX_VALUE

      number of objects to return

    • direction: Direction = Direction.Ascending

      direction of the get, Ascending or Descending

    Returns ProtoDatabaseObject<TValue>[]

    an array with the objects retrieved

  • getManyKeys(offsetKey: TKey, limit?: number, direction?: Direction): TKey[]
  • Get many keys from the space

    example
    const keys = Objects.getManyKeys('key1', 10, Space.Direction.Descending);

    for (let index = 0; index < keys.length; index++) {
    const key = keys[index];
    }

    Parameters

    • offsetKey: TKey

      key used as the offset

    • limit: number = i32.MAX_VALUE

      number of keys to return

    • direction: Direction = Direction.Ascending

      direction of the get, Ascending or Descending

    Returns TKey[]

    an array with the keys retrieved

  • getManyValues(offsetKey: TKey, limit?: number, direction?: Direction): TValue[]
  • Get many values from the space

    example
    const values = Objects.getManyValues('key1', 10, Space.Direction.Descending);

    for (let index = 0; index < values.length; index++) {
    const values = values[index];
    }

    Parameters

    • offsetKey: TKey

      key used as the offset

    • limit: number = i32.MAX_VALUE

      number of values to return

    • direction: Direction = Direction.Ascending

      direction of the get, Ascending or Descending

    Returns TValue[]

    an array with the values retrieved

  • Get the next object from the space

    example
    const obj = Objects.getNext('key1');

    if (obj != null) {
    const key = obj.key;
    const val = obj.value;
    }

    Parameters

    • key: TKey

      key to get next

    Returns null | ProtoDatabaseObject<TValue>

    a System.ProtoDatabaseObject if exists, null otherwise

  • Get the previous object from the space

    example
    const obj = Objects.getPrev('key1');

    if (obj != null) {
    const key = obj.key;
    const val = obj.value;
    }

    Parameters

    • key: TKey

      key to get previous

    Returns null | ProtoDatabaseObject<TValue>

    a System.ProtoDatabaseObject if exists, null otherwise

  • has(key: TKey): boolean
  • Check if key exists in the space

    example
    const exists = Objects.has('key1');

    if (exists) {
    ...
    }

    Parameters

    • key: TKey

      key to check

    Returns boolean

  • put(key: TKey, object: TValue): void
  • Put an object in the space

    example
    const nbBytesWritten = Objects.put('key1', new test_object(42));

    System.log(nbBytesWritten.toString());

    Parameters

    • key: TKey

      key of the object

    • object: TValue

    Returns void

    number of bytes that were written in the space

  • remove(key: TKey): void
  • Remove an object from the space

    example
    Objects.remove('key1');
    

    Parameters

    • key: TKey

      key of the object

    Returns void

Generated using TypeDoc