2019-11-08 03:19:27 +04:00
|
|
|
---
|
|
|
|
id: timestamps-addresses
|
|
|
|
title: Timestamps, Addresses
|
|
|
|
---
|
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
## Timestamps
|
2019-11-08 03:19:27 +04:00
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
LIGO features timestamps, as Michelson does, while bakers baking the
|
|
|
|
block (including the transaction in a block) are responsible for
|
|
|
|
providing the given current timestamp for the contract.
|
2019-11-08 03:19:27 +04:00
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
### Current Time
|
2019-11-08 03:19:27 +04:00
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
You can obtain the current time using the built-in syntax specific
|
|
|
|
expression, please be aware that it is up to the baker to set the
|
|
|
|
current timestamp value.
|
2019-11-08 03:19:27 +04:00
|
|
|
|
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2019-12-26 17:21:17 +04:00
|
|
|
```pascaligo group=a
|
2020-02-25 21:07:53 +04:00
|
|
|
const today : timestamp = Tezos.now
|
2019-11-08 03:19:27 +04:00
|
|
|
```
|
2020-01-18 10:56:54 +04:00
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `now` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=a
|
2020-02-25 21:07:53 +04:00
|
|
|
let today : timestamp = Tezos.now
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=a
|
2020-02-25 21:07:53 +04:00
|
|
|
let today : timestamp = Tezos.now;
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> When running code, the LIGO CLI option `--predecessor-timestamp`
|
|
|
|
> allows you to control what `Tezos.now` returns.
|
2020-01-04 00:38:40 +04:00
|
|
|
|
2020-02-12 01:29:12 +04:00
|
|
|
### Timestamp Arithmetics
|
2019-11-08 03:19:27 +04:00
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
In LIGO, timestamps can be added to integers, allowing you to set time
|
|
|
|
constraints on your smart contracts. Consider the following scenarios.
|
2019-11-08 03:19:27 +04:00
|
|
|
|
|
|
|
#### In 24 hours
|
2020-02-05 19:28:40 +04:00
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2019-12-26 17:21:17 +04:00
|
|
|
```pascaligo group=b
|
2020-02-25 21:07:53 +04:00
|
|
|
const today : timestamp = Tezos.now
|
2020-02-05 19:28:40 +04:00
|
|
|
const one_day : int = 86400
|
|
|
|
const in_24_hrs : timestamp = today + one_day
|
|
|
|
const some_date : timestamp = ("2000-01-01T10:10:10Z" : timestamp)
|
|
|
|
const one_day_later : timestamp = some_date + one_day
|
2019-11-08 03:19:27 +04:00
|
|
|
```
|
2020-01-18 10:56:54 +04:00
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `now` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=b
|
2020-02-25 21:07:53 +04:00
|
|
|
let today : timestamp = Tezos.now
|
2020-02-05 19:28:40 +04:00
|
|
|
let one_day : int = 86400
|
|
|
|
let in_24_hrs : timestamp = today + one_day
|
|
|
|
let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp)
|
|
|
|
let one_day_later : timestamp = some_date + one_day
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=b
|
2020-02-25 21:07:53 +04:00
|
|
|
let today : timestamp = Tezos.now;
|
2020-02-05 19:28:40 +04:00
|
|
|
let one_day : int = 86400;
|
|
|
|
let in_24_hrs : timestamp = today + one_day;
|
|
|
|
let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp);
|
|
|
|
let one_day_later : timestamp = some_date + one_day;
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
#### 24 hours Ago
|
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2019-12-26 17:21:17 +04:00
|
|
|
```pascaligo group=c
|
2020-02-25 21:07:53 +04:00
|
|
|
const today : timestamp = Tezos.now
|
2020-02-05 19:28:40 +04:00
|
|
|
const one_day : int = 86400
|
|
|
|
const in_24_hrs : timestamp = today - one_day
|
2019-11-08 03:19:27 +04:00
|
|
|
```
|
2020-01-18 10:56:54 +04:00
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `now` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=c
|
2020-02-25 21:07:53 +04:00
|
|
|
let today : timestamp = Tezos.now
|
2020-02-05 19:28:40 +04:00
|
|
|
let one_day : int = 86400
|
|
|
|
let in_24_hrs : timestamp = today - one_day
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=c
|
2020-02-25 21:07:53 +04:00
|
|
|
let today : timestamp = Tezos.now;
|
2020-02-05 19:28:40 +04:00
|
|
|
let one_day : int = 86400;
|
|
|
|
let in_24_hrs : timestamp = today - one_day;
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
### Comparing Timestamps
|
2019-11-08 03:19:27 +04:00
|
|
|
|
2020-02-06 14:47:41 +04:00
|
|
|
You can compare timestamps using the same comparison operators
|
|
|
|
applying to numbers.
|
2019-11-08 03:19:27 +04:00
|
|
|
|
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2019-12-26 17:21:17 +04:00
|
|
|
```pascaligo group=c
|
2020-02-25 21:07:53 +04:00
|
|
|
const not_tommorow : bool = (Tezos.now = in_24_hrs)
|
2019-11-08 03:19:27 +04:00
|
|
|
```
|
2020-01-18 10:56:54 +04:00
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `now` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=c
|
2020-02-25 21:07:53 +04:00
|
|
|
let not_tomorrow : bool = (Tezos.now = in_24_hrs)
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=c
|
2020-02-25 21:07:53 +04:00
|
|
|
let not_tomorrow : bool = (Tezos.now == in_24_hrs);
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2020-02-25 21:07:53 +04:00
|
|
|
> Note that `Current.time` is *deprecated*.
|
|
|
|
|
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
|
|
|
|
|
|
|
## Addresses
|
|
|
|
|
2020-02-12 01:29:12 +04:00
|
|
|
The `address` type in LIGO denotes Tezos addresses (tz1, tz2, tz3,
|
2020-02-06 14:47:41 +04:00
|
|
|
KT1, ...). Currently, addresses are created by casting a string to the
|
2020-02-12 01:29:12 +04:00
|
|
|
`address` type. Beware of failures if the address is invalid. Consider
|
2020-02-06 14:47:41 +04:00
|
|
|
the following examples.
|
2019-11-08 03:19:27 +04:00
|
|
|
|
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2019-12-26 17:21:17 +04:00
|
|
|
```pascaligo group=d
|
2020-02-05 19:28:40 +04:00
|
|
|
const my_account : address =
|
|
|
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)
|
2019-11-08 03:19:27 +04:00
|
|
|
```
|
2020-01-18 10:56:54 +04:00
|
|
|
|
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=d
|
2020-02-05 19:28:40 +04:00
|
|
|
let my_account : address =
|
|
|
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=d
|
2020-02-05 19:28:40 +04:00
|
|
|
let my_account : address =
|
|
|
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address);
|
2020-01-18 10:56:54 +04:00
|
|
|
```
|
|
|
|
|
2019-11-08 03:19:27 +04:00
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
|
|
|
|
2020-01-13 14:37:10 +04:00
|
|
|
## Signatures
|
|
|
|
|
2020-02-06 14:47:41 +04:00
|
|
|
The `signature` type in LIGO datatype is used for Tezos signatures
|
2020-02-05 19:28:40 +04:00
|
|
|
(edsig, spsig). Signatures are created by casting a string. Beware of
|
|
|
|
failure if the signature is invalid.
|
2020-01-13 14:37:10 +04:00
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
Here is how you can define a signature:
|
2020-01-13 14:37:10 +04:00
|
|
|
|
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2020-01-13 14:37:10 +04:00
|
|
|
```pascaligo group=e
|
2020-02-05 19:28:40 +04:00
|
|
|
const my_sig : signature =
|
|
|
|
("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" :
|
|
|
|
signature)
|
2020-01-13 14:37:10 +04:00
|
|
|
```
|
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=e
|
2020-02-05 19:28:40 +04:00
|
|
|
let my_sig : signature =
|
|
|
|
("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" :
|
|
|
|
signature)
|
2020-01-13 14:37:10 +04:00
|
|
|
```
|
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=e
|
2020-02-05 19:28:40 +04:00
|
|
|
let my_sig : signature =
|
|
|
|
("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" :
|
|
|
|
signature);
|
2020-01-13 14:37:10 +04:00
|
|
|
```
|
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
## Keys
|
2020-01-13 14:37:10 +04:00
|
|
|
|
2020-02-06 14:47:41 +04:00
|
|
|
The `key` type in LIGO is used for Tezos public keys. Do not confuse
|
2020-02-05 19:28:40 +04:00
|
|
|
them with map keys. Keys are made by casting strings. Beware of
|
|
|
|
failure if the key is invalid.
|
2020-01-13 14:37:10 +04:00
|
|
|
|
2020-02-05 19:28:40 +04:00
|
|
|
Here is how you can define a key.
|
2020-01-13 14:37:10 +04:00
|
|
|
|
|
|
|
<!--DOCUSAURUS_CODE_TABS-->
|
2020-02-10 22:07:20 +04:00
|
|
|
<!--PascaLIGO-->
|
2020-01-13 14:37:10 +04:00
|
|
|
```pascaligo group=f
|
2020-02-05 19:28:40 +04:00
|
|
|
const my_key : key =
|
|
|
|
("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key)
|
2020-01-13 14:37:10 +04:00
|
|
|
```
|
|
|
|
<!--CameLIGO-->
|
|
|
|
```cameligo group=f
|
2020-02-05 19:28:40 +04:00
|
|
|
let my_key : key =
|
|
|
|
("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key)
|
2020-01-13 14:37:10 +04:00
|
|
|
```
|
|
|
|
<!--ReasonLIGO-->
|
|
|
|
```reasonligo group=f
|
2020-02-05 19:28:40 +04:00
|
|
|
let my_key : key =
|
|
|
|
("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key);
|
2020-01-13 14:37:10 +04:00
|
|
|
```
|
2020-01-18 10:56:54 +04:00
|
|
|
<!--END_DOCUSAURUS_CODE_TABS-->
|