File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "label" : " Advanced" ,
3
+ "position" : 6 ,
4
+ "link" : {
5
+ "type" : " doc" ,
6
+ "id" : " advanced"
7
+ }
8
+ }
Original file line number Diff line number Diff line change
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
+ :::
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments