Skip to content

Commit

Permalink
docs(logic): generate documentation for block_header/1
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Nov 23, 2024
1 parent 5ad5bf2 commit 26d1c62
Show file tree
Hide file tree
Showing 26 changed files with 225 additions and 178 deletions.
10 changes: 5 additions & 5 deletions docs/predicate/asserta_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ answer:
results:
- substitutions:
- variable: X
expression: "john"
- variable: Y
expression: "pete"
expression: john
- variable: 'Y'
expression: pete
```
### Only dynamic predicates can be asserted
Expand Down Expand Up @@ -127,10 +127,10 @@ answer:
results:
- substitutions:
- variable: X
expression: "john"
expression: john
- substitutions:
- variable: X
expression: "jane"
expression: jane
```
### Shows a simple counter example
Expand Down
10 changes: 5 additions & 5 deletions docs/predicate/assertz_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ answer:
results:
- substitutions:
- variable: X
expression: "john"
- variable: Y
expression: "pete"
expression: john
- variable: 'Y'
expression: pete
```
### Only dynamic predicates can be asserted
Expand Down Expand Up @@ -127,10 +127,10 @@ answer:
results:
- substitutions:
- variable: X
expression: "jane"
expression: jane
- substitutions:
- variable: X
expression: "john"
expression: john
```
### Add and remove items in an inventory
Expand Down
189 changes: 189 additions & 0 deletions docs/predicate/block_header_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
---
sidebar_position: 10
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

# block_header/1

## Description

`block_header/1` is a predicate which unifies the given term with the current block header.

## Signature

```text
block_header(?Header) is det
```

where:

- Header is a Dict representing the current chain header at the time of the query.

## Examples

### Retrieve the header of the current block

This scenario demonstrates how to retrieve the header of the current block and obtain some of its properties.

The header of a block carries important information about the state of the blockchain, such as basic information (chain id, the height,
time, and height), the information about the last block, hashes, and the consensus info.

The header is represented as a Prolog Dict, which is a collection of key-value pairs.

Here are the steps of the scenario:

- **Given** a block with the following header:

``` yaml
app_hash: Q0P6b2hoSUbmpCE6o6Dme4H4FBWqdcpqo89DrpBYSHQ=
chain_id: axone-localnet
height: 33
next_validators_hash: EIQFMnCDepfXD2e3OeL1QoEfmu6BZQbKR500Wkl4gK0=
proposer_address: yz7PSKMWniQlQWMd7LskBABgDKQ=
time: "2024-11-22T21:22:04.676789Z"
```
- **Given** the query:
``` prolog
block_header(Header).
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
height: 33
gas_used: 3975
answer:
has_more: false
variables: ["Header"]
results:
- substitutions:
- variable: Header
expression: >-
header{app_hash:[67,67,250,111,104,104,73,70,230,164,33,58,163,160,230,123,129,248,20,21,170,117,202,106,163,207,67,174,144,88,72,116],chain_id:'axone-localnet',consensus_hash:[],data_hash:[],evidence_hash:[],height:33,last_block_id:block_id{hash:[],part_set_header:part_set_header{hash:[],total:0}},last_commit_hash:[],last_results_hash:[],next_validators_hash:[16,132,5,50,112,131,122,151,215,15,103,183,57,226,245,66,129,31,154,238,129,101,6,202,71,157,52,90,73,120,128,173],proposer_address:[203,62,207,72,163,22,158,36,37,65,99,29,236,187,36,4,0,96,12,164],time:1732310524,validators_hash:[],version:consensus{app:0,block:0}}
```
### Retrieve the block height of the current block
This scenario demonstrates how to retrieve the block height of the current block.
Here are the steps of the scenario:
- **Given** a block with the following header:
``` yaml
height: 100
```
- **Given** the program:
``` prolog
height(Height) :-
block_header(Header),
Height = Header.height.
```

- **Given** the query:

``` prolog
height(Height).
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
height: 100
gas_used: 3978
answer:
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "100"
```
### Retrieve the block time of the current block
This scenario demonstrates how to retrieve the block time of the current block.
Here are the steps of the scenario:
- **Given** a block with the following header:
``` yaml
time: 2024-03-04T11:03:36.000Z
```
- **Given** the program:
``` prolog
time(Time) :-
block_header(Header),
Time = Header.time.
```

- **Given** the query:

``` prolog
time(Time).
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
height: 42
gas_used: 3978
answer:
has_more: false
variables: ["Time"]
results:
- substitutions:
- variable: Time
expression: "1709550216"
```
### Evaluate a condition based on block time and height
This scenario demonstrates how to evaluate a condition that depends on both the block time and block height.
Specifically, it checks whether the block time is greater than 1709550216 seconds (Monday 4 March 2024 11:03:36 GMT)
or the block height is greater than 42.
Here are the steps of the scenario:
- **Given** a block with the following header:
``` yaml
time: 2024-03-04T11:03:37.000Z
```
- **Given** the program:
``` prolog
evaluate :-
block_header(Header),
(Header.time > 1709550216; Header.height > 42),
!.
```

- **Given** the query:

``` prolog
evaluate.
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
height: 42
gas_used: 3981
answer:
has_more: false
results:
- substitutions:
```
72 changes: 2 additions & 70 deletions docs/predicate/block_height_1.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 10
sidebar_position: 11
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand All @@ -19,72 +19,4 @@ where:

- Height represents the current chain height at the time of the query.

## Examples

### Retrieve the block height of the current block

This scenario demonstrates how to retrieve the block height of the current block.

Here are the steps of the scenario:

- **Given** a block with the following header:

| key | value |
| --- | ----- |
| Height | 100 |

- **Given** the query:

``` prolog
block_height(Height).
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
height: 100
gas_used: 3975
answer:
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "100"
```
### Check that the block height is greater than a certain value
This scenario demonstrates how to check that the block height is greater than 100. This predicate is useful for
governance which requires a certain block height to be reached before a certain action is taken.
Here are the steps of the scenario:
- **Given** a block with the following header:
| key | value |
| --- | ----- |
| Height | 101 |
- **Given** the query:
``` prolog
block_height(Height),
Height > 100.
```

- **When** the query is run
- **Then** the answer we get is:

``` yaml
height: 101
gas_used: 3976
answer:
has_more: false
variables: ["Height"]
results:
- substitutions:
- variable: Height
expression: "101"
```
Deprecated: Use the \`block\_header/1\` predicate instead.
Loading

0 comments on commit 26d1c62

Please sign in to comment.