2020-02-05 11:08:47 +04:00
|
|
|
---
|
|
|
|
id: big-map-reference
|
2020-03-09 21:20:21 +04:00
|
|
|
title: Big_map
|
|
|
|
description: A lazily deserialized map that's intended to store large amounts of data.
|
|
|
|
hide_table_of_contents: true
|
2020-02-05 11:08:47 +04:00
|
|
|
---
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
import Syntax from '@theme/Syntax';
|
2020-03-09 21:20:21 +04:00
|
|
|
import SyntaxTitle from '@theme/SyntaxTitle';
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
A lazily deserialized map that's intended to store large amounts of data.
|
2020-02-26 21:31:58 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
The gast costs of deserialized maps are higher than standard maps as data is lazily deserialized.
|
2020-02-11 13:03:46 +04:00
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
type big_map (key, value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
|
|
|
|
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
type ('key, 'value) big_map
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
type big_map ('key, 'value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
<Syntax syntax="pascaligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
The type of a big map from values of type `key` to
|
|
|
|
values of type `value` is `big_map (key, value)`.
|
|
|
|
|
|
|
|
```pascaligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
type move is int * int
|
|
|
|
type register is big_map (address, move)
|
2020-02-11 13:03:46 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
The type of a big map from values of type `key` to values
|
|
|
|
of type `value` is `(key, value) big_map`.
|
|
|
|
|
|
|
|
```cameligo group=big_map
|
2020-02-11 13:03:46 +04:00
|
|
|
type move = int * int
|
2020-02-25 21:07:53 +04:00
|
|
|
type register = (address, move) big_map
|
2020-02-11 13:03:46 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
2020-03-09 21:20:21 +04:00
|
|
|
The type of a big map from values of type `key` to
|
|
|
|
values of type `value` is `big_map (key, value)`.
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```reasonligo group=big_map
|
2020-02-11 13:03:46 +04:00
|
|
|
type move = (int, int);
|
2020-02-25 21:07:53 +04:00
|
|
|
type register = big_map (address, move);
|
2020-02-11 13:03:46 +04:00
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
function empty : big_map (key, value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
val empty : ('key, 'value) big_map
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
let empty: big_map ('key, 'value)
|
|
|
|
</SyntaxTitle>
|
2020-02-11 13:03:46 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
Create an empty big_map.
|
2020-02-25 21:07:53 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<Syntax syntax="pascaligo">
|
2020-02-11 13:03:46 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
|
|
|
const empty : register = Big_map.empty
|
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
Alternatively, you can also create an empty big_map using:
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
const empty_alternative : register = big_map []
|
2020-02-11 13:03:46 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```cameligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
let empty : register = Big_map.empty
|
2020-02-11 13:03:46 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```reasonligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
let empty : register = Big_map.empty
|
2020-02-11 13:03:46 +04:00
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
|
2020-02-11 13:03:46 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
function literal : list (key * value) -> big_map (key, value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
val literal : ('key * 'value) list -> ('key, 'value) big_map
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
let literal: list(('key, 'value)) => big_map('key, 'value)
|
|
|
|
</SyntaxTitle>
|
2020-02-25 21:07:53 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
Create a non-empty big_map.
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
<Syntax syntax="pascaligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
|
|
|
const moves : register =
|
2020-03-10 15:54:18 +04:00
|
|
|
Big_map.literal (list [
|
|
|
|
(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2));
|
|
|
|
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))]);
|
2020-03-09 21:20:21 +04:00
|
|
|
```
|
|
|
|
|
|
|
|
Alternative way of creating an empty big_map:
|
|
|
|
|
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
const moves_alternative : register =
|
2020-02-25 21:07:53 +04:00
|
|
|
big_map [
|
|
|
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2);
|
2020-03-10 15:54:18 +04:00
|
|
|
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)];
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```cameligo group=big_map
|
2020-02-26 21:31:58 +04:00
|
|
|
let moves : register =
|
2020-02-25 21:07:53 +04:00
|
|
|
Big_map.literal [
|
|
|
|
(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2));
|
|
|
|
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))]
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```reasonligo group=big_map
|
2020-02-26 21:31:58 +04:00
|
|
|
let moves : register =
|
2020-02-25 21:07:53 +04:00
|
|
|
Big_map.literal ([
|
|
|
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)),
|
|
|
|
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]);
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
function find_opt : key -> big_map (key, value) -> option value
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
val find_opt : 'key -> ('key, 'value) big_map -> 'value option
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
let find_opt : ('key, big_map ('key, 'value)) => option ('value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
|
|
|
|
Retrieve a value from a big map with the given key.
|
2020-02-05 11:08:47 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
Because the key may be missing in the big map, the result is an
|
|
|
|
*optional value*.
|
2020-02-05 11:08:47 +04:00
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
<Syntax syntax="pascaligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
|
|
|
const my_balance : option (move) =
|
2020-03-10 15:54:18 +04:00
|
|
|
Big_map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves)
|
2020-03-09 21:20:21 +04:00
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively:
|
|
|
|
|
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
const my_balance_alternative : option (move) =
|
|
|
|
moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)];
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```cameligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
let my_balance : move option =
|
|
|
|
Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```reasonligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
let my_balance : option (move) =
|
|
|
|
Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves);
|
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
function update : key -> option value -> big_map (key, value) -> big_map (key, value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
val update: 'key -> 'value option -> ('key, 'value) big_map -> ('key, 'value) big_map
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
let update: ('key, option('value), big_map ('key, 'value)) => big_map ('key, 'value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
|
|
|
|
Note: when `None` is used as a value, the value is removed from the big_map.
|
|
|
|
|
|
|
|
<Syntax syntax="pascaligo">
|
2020-02-05 11:08:47 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
const updated_big_map : register = Big_map.update(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some (4,9), moves);
|
2020-03-09 21:20:21 +04:00
|
|
|
```
|
2020-02-05 11:08:47 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
Alternatively:
|
2020-02-05 11:08:47 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
|
|
|
|
function update (var m : register) : register is
|
|
|
|
block {
|
|
|
|
m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9);
|
|
|
|
} with m
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
If multiple bindings need to be updated, PascaLIGO offers a *patch
|
|
|
|
instruction* for maps, similar to that for records.
|
2020-03-04 17:19:00 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
|
|
|
function assignments (var m : register) : register is
|
2020-02-05 11:08:47 +04:00
|
|
|
block {
|
2020-03-09 21:20:21 +04:00
|
|
|
patch m with map [
|
|
|
|
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (4,9);
|
|
|
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2)
|
|
|
|
]
|
2020-02-05 11:08:47 +04:00
|
|
|
} with m
|
|
|
|
```
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
> Note the use of the keyword `map` instead of `big_map` (which is not
|
|
|
|
> a keyword).
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```cameligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
let updated_map : register =
|
|
|
|
Big_map.update
|
|
|
|
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```reasonligo group=big_map
|
2020-02-25 21:07:53 +04:00
|
|
|
let updated_map : register =
|
|
|
|
Big_map.update
|
|
|
|
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves);
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
function add : key -> value -> big_map (key, value) -> big_map (key, value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
val add : 'key -> 'value -> ('key, 'value) big_map -> ('key, 'value) big_map
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
let add: ('key, 'value, big_map('key, 'value)) => big_map('key, 'value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
<Syntax syntax="pascaligo">
|
2020-02-05 11:08:47 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
const added_item : register = Big_map.add (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4, 9), moves)
|
2020-03-09 21:20:21 +04:00
|
|
|
```
|
2020-02-11 13:03:46 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
2020-02-11 13:03:46 +04:00
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```cameligo group=big_map
|
|
|
|
let add (m : register) : register =
|
|
|
|
Big_map.add
|
|
|
|
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m
|
|
|
|
```
|
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
|
|
|
|
|
|
|
```reasonligo group=big_map
|
|
|
|
let add = (m: register): register =>
|
|
|
|
Big_map.add
|
|
|
|
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m);
|
|
|
|
```
|
|
|
|
|
|
|
|
</Syntax>
|
|
|
|
|
|
|
|
|
|
|
|
<SyntaxTitle syntax="pascaligo">
|
|
|
|
function remove: key -> big_map (key, value) -> big_map (key, value)
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="cameligo">
|
|
|
|
val remove: 'key -> ('key, 'value) big_map -> ('key, 'value) big_map
|
|
|
|
</SyntaxTitle>
|
|
|
|
<SyntaxTitle syntax="reasonligo">
|
|
|
|
let remove: (key, big_map ('key, 'value)) => big_map ('key, 'value)
|
|
|
|
</SyntaxTitle>
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
<Syntax syntax="pascaligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```pascaligo group=big_map
|
2020-03-10 15:54:18 +04:00
|
|
|
const updated_map : register =
|
2020-03-09 21:20:21 +04:00
|
|
|
Big_map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves)
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively, the instruction `remove key from map m` removes the key
|
|
|
|
`key` from the big map `m` (note that the keyword is `map`, not
|
|
|
|
`big_map`).
|
|
|
|
|
|
|
|
```pascaligo group=big_map
|
2020-02-26 21:31:58 +04:00
|
|
|
function rem (var m : register) : register is
|
2020-02-25 21:07:53 +04:00
|
|
|
block {
|
2020-02-26 21:31:58 +04:00
|
|
|
remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) from map moves
|
2020-02-25 21:07:53 +04:00
|
|
|
} with m
|
|
|
|
|
2020-02-26 21:31:58 +04:00
|
|
|
const updated_map : register = rem (moves)
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="cameligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```cameligo group=big_map
|
2020-02-26 21:31:58 +04:00
|
|
|
let updated_map : register =
|
2020-03-09 21:20:21 +04:00
|
|
|
Big_map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
<Syntax syntax="reasonligo">
|
|
|
|
|
2020-03-09 21:20:21 +04:00
|
|
|
```reasonligo group=big_map
|
2020-02-26 21:31:58 +04:00
|
|
|
let updated_map : register =
|
2020-03-09 21:20:21 +04:00
|
|
|
Big_map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves)
|
2020-02-05 11:08:47 +04:00
|
|
|
```
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
</Syntax>
|
|
|
|
|