Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MichelsonMap<K, T>

description

Michelson Map is an abstraction over the michelson native map. It supports complex Pair as key

Type parameters

  • K: MichelsonMapKey

  • T

Hierarchy

  • MichelsonMap

Index

Constructors

constructor

  • new MichelsonMap<K, T>(mapType?: MichelsonV1ExpressionBase | MichelsonV1ExpressionExtended | MichelsonV1Expression[]): MichelsonMap<K, T>
  • example

    new MichelsonMap({ prim: "map", args: [{prim: "string"}, {prim: "int"}]})

    Type parameters

    • K: MichelsonMapKey

    • T

    Parameters

    • Optional mapType: MichelsonV1ExpressionBase | MichelsonV1ExpressionExtended | MichelsonV1Expression[]

      If specified key and value will be type-checked before being added to the map

    Returns MichelsonMap<K, T>

Properties

[michelsonMapTypeSymbol]

[michelsonMapTypeSymbol]: boolean

Accessors

size

  • get size(): number
  • Returns number

Methods

clear

  • clear(): void
  • Returns void

delete

  • delete(key: K): void
  • Parameters

    • key: K

    Returns void

entries

  • entries(): Generator<[K, T], any, unknown>
  • Returns Generator<[K, T], any, unknown>

forEach

  • forEach(cb: (value: T, key: K, map: MichelsonMap<K, T>) => void): void
  • Parameters

    Returns void

get

  • get(key: K): undefined | T
  • Parameters

    • key: K

    Returns undefined | T

has

  • has(key: K): boolean
  • Parameters

    • key: K

    Returns boolean

keys

  • keys(): Generator<K, any, unknown>
  • Returns Generator<K, any, unknown>

removeType

  • removeType(): void
  • Returns void

set

  • set(key: K, value: T): void
  • description

    Set a key and a value in the MichelsonMap. If the key already exists, override the current value.

    example

    map.set("myKey", "myValue") // Using a string as key

    example

    map.set({0: "test", 1: "test1"}, "myValue") // Using a pair as key

    warn

    The same key can be represented in multiple ways, depending on the type of the key. This duplicate key situation will cause a runtime error (duplicate key) when sending the map data to the Tezos RPC node.

    For example, consider a contract with a map whose key is of type boolean. If you set the following values in MichelsonMap: map.set(false, "myValue") and map.set(null, "myValue").

    You will get two unique entries in the MichelsonMap. These values will both be evaluated as falsy by the MichelsonEncoder and ultimately rejected by the Tezos RPC.

    Parameters

    • key: K
    • value: T

    Returns void

setType

  • setType(mapType: MichelsonV1Expression): void
  • Parameters

    • mapType: MichelsonV1Expression

    Returns void

values

  • values(): Generator<T, any, unknown>
  • Returns Generator<T, any, unknown>

Static fromLiteral

  • fromLiteral(obj: {}, mapType?: MichelsonV1ExpressionBase | MichelsonV1ExpressionExtended | MichelsonV1Expression[]): MichelsonMap<MichelsonMapKey, unknown>
  • Parameters

    • obj: {}
      • [key: string]: any
    • Optional mapType: MichelsonV1ExpressionBase | MichelsonV1ExpressionExtended | MichelsonV1Expression[]

    Returns MichelsonMap<MichelsonMapKey, unknown>

Static isMichelsonMap

  • Parameters

    • obj: any

    Returns obj is MichelsonMap<any, any>

Generated using TypeDoc