Skip to content

Commit f0d2b13

Browse files
committed
Added Advanced chapter.
1 parent e2a2e82 commit f0d2b13

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

docs/core/advanced/_category_.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Advanced",
3+
"position": 6,
4+
"link": {
5+
"type": "doc",
6+
"id": "advanced"
7+
}
8+
}

docs/core/advanced/advanced.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Advanced
3+
---
4+
5+
# Advanced topics
6+
7+
In this part of the documentation, we go over some more "advanced" things you can do with the
8+
functionality CosmWasm core offers.
9+
10+
:::tip
11+
12+
While the name of this section is "advanced", this doesn't mean that we want to imply that you
13+
only need these functions in advanced contexts. The wording "advanced" more so refers to the fact
14+
that you should be familiar with endpoints, the structs that are passed to the endpoints, etc.
15+
16+
:::
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Measuring time
6+
7+
Accessing the current time is useful in a lot of different contexts but time is hard.
8+
It is hard to coordinate, hard to keep in sync, and this gets worse in distributed settings such as blockchains.
9+
10+
In CosmWasm, we solve this by passing you some information about the blockchain you are running on
11+
whenever an entrypoint is invoked.
12+
13+
In each of the entrypoints, you get a parameter of the type `Env` and this struct contains the field `block`.
14+
The struct contained in this field has a bunch of different information about the current state of the blockchain
15+
you are running on.
16+
17+
:::tip
18+
19+
The documentation for the `BlockInfo` struct can be [found here].
20+
21+
:::
22+
23+
The timestamp contained in this struct can be safely used in your program as the source of the current time.
24+
Well, kinda. It won't be 100% matching the current time, as it is the timestamp of the block we are currently
25+
operating on.
26+
27+
But you can rely on this timestamp to have the following properties:
28+
29+
- Consistent across the chain (every validator on the chain has the same info)
30+
- Monotonic (it will only ever increase or stay the same; never decrease)
31+
32+
Read more about [BFT Time] and [Proposer-Based Timestamps (PBTS)][PBTS] if you want to better understand
33+
where the time value comes from.
34+
35+
[found here]: https://docs.rs/cosmwasm-std/latest/cosmwasm_std/struct.BlockInfo.html
36+
[BFT Time]: https://docs.cometbft.com/main/spec/consensus/bft-time
37+
[PBTS]: https://informal.systems/blog/introducing-proposer-based-timestamps-pbts-in-cometbft

0 commit comments

Comments
 (0)