-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: node-dusk-http-wss + English version
- Loading branch information
Showing
9 changed files
with
718 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ mypy==1.14.1 | |
pymarkdownlnt==0.9.26 | ||
ruff==0.9.3 | ||
sphinx-autobuild==2024.10.3 | ||
types-requests | ||
yamllint==1.35.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
# Communiquer avec votre nœud Dusk | ||
|
||
```{figure} images/dusk-logo.svg | ||
:width: 96 | ||
:height: 96 | ||
:alt: Dusk Logo | ||
:align: center | ||
|
||
Site web : [dusk.network](https://dusk.network) | ||
``` | ||
|
||
Voici différentes manières de questionner votre nœud Dusk : [GraphQL](#graphql), [RPC](#rpc) et [RUES](#rues). | ||
|
||
````{tip} | ||
🇬🇧 Version anglaise : [How to query your Dusk node?](../en/blockchain/node-dusk-http-wss.md). | ||
```{code-block} | ||
:caption: 🫶 Adresse Dusk pour les pourboires | ||
VKZpBrNtEeTobMgYkkdcGiZn8fK2Ve2yez429yRXrH4nUUDTuvr7Tv74xFA2DKNVegtF6jaom2uacZMm8Z2Lg2J | ||
``` | ||
```` | ||
|
||
## 🔗 Liens Utiles | ||
|
||
- [Comment déployer un nœud Dusk ?](./node-dusk.md) | ||
- [RUES](https://docs.dusk.network/developer/integrations/rues/) | ||
|
||
## 1️⃣ GraphQL | ||
|
||
```{hint} | ||
Les requêtes GraphQL utilisent des données définies dans le code de [rusk](https://github.com/dusk-network/rusk/blob/master/explorer/src/lib/services/gql-queries.js), et il y a d'autres possibilités qu'il reste à découvrir. | ||
``` | ||
|
||
### Récupérer le dernier numéro de bloc | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 4-5 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 7-13 | ||
:language: json | ||
``` | ||
|
||
### Récupérer les N derniers blocs | ||
|
||
Plutôt que de récupérer trop d'informations, ici, nous ne voulons que le numéro du bloc (`height`) et l'adresse du nœud (`generatorBlsPubkey`) qui l'a validé. | ||
|
||
Vous pouvez modifier le nombre de blocs à la ligne `last: 100` (pour les 100 derniers blocs, par exemple). | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 18-20 | ||
:emphasize-lines: 3 | ||
:language: shell | ||
``` | ||
|
||
Le même type de requête peut être effectué en spécifiant le nombre de blocs dans un entête HTTP spécial `rusk-gqlvar-XXX` (où `XXX` est le nom de la variable) : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 22-26 | ||
:emphasize-lines: 2,5 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 28-44 | ||
:language: json | ||
``` | ||
|
||
### Récupérer les N derniers blocs avec les détails des transactions | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 48-51 | ||
:emphasize-lines: 4 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 53-76 | ||
:language: json | ||
``` | ||
|
||
### Récupérer les N derniers blocs avec les détails des transactions au format JSON | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 81-84 | ||
:emphasize-lines: 4 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 86-104 | ||
:language: json | ||
``` | ||
|
||
Et en parsant les données JSON, on obtient ceci : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 107-126 | ||
:language: json | ||
``` | ||
|
||
### Récupérer un ensemble de blocs | ||
|
||
Exemple avec la récupération des blocs 10, 11 et 12 : la syntaxe est `[10, 12]`. | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 149-151 | ||
:emphasize-lines: 3 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 153-174 | ||
:language: json | ||
``` | ||
|
||
### Récupérer les données JSON des transactions pour un bloc donné | ||
|
||
Le bloc en question est le numéro 189314. | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 130-133 | ||
:emphasize-lines: 4 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 135-145 | ||
:language: json | ||
``` | ||
|
||
### Récupérer toutes les données d'un bloc, détails des transactions inclus, pour un bloc donné | ||
|
||
Le bloc en question est le numéro 189314. | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 198-201 | ||
:emphasize-lines: 4 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 203-244 | ||
:language: json | ||
``` | ||
|
||
## 2️⃣ RPC | ||
|
||
### Récupérer la liste des nœuds validateurs | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 178 | ||
:language: shell | ||
``` | ||
|
||
Exemple de réponse : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.sh | ||
:lines: 180-194 | ||
:language: json | ||
``` | ||
|
||
## 3️⃣ RUES | ||
|
||
[RUES](https://docs.dusk.network/developer/integrations/rues/) pour *Rusk Universal Event System* est un système permettant d'écouter la *blockchain* pour récupérer les évènements en temps réel. | ||
|
||
Voici un code écrit en Python qui s'intéresse aux blocs validés par un certain nœud : | ||
|
||
```{literalinclude} snippets/node-dusk-http-wss.py | ||
:caption: Fichier : listen.py | ||
:emphasize-lines: 12 | ||
:language: python | ||
``` | ||
|
||
Afin de pouvoir exécuter le script, il est nécessaire d'installer les modules [requests](https://pypi.org/project/requests/) et [websockets](https://pypi.org/project/websockets/). | ||
|
||
Enfin, une fois le script en fonctionnement, les numéros de blocs générés par le nœud apparaitrons en temps réel. | ||
|
||
## 📜 Historique | ||
|
||
2025-01-29 | ||
: Premier jet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
This was part of Dusk Node Monitoring until commit 832e35ef5b30bc953ea41cf57f279993cedda6a4. | ||
Source: https://github.com/BoboTiG/dusk-monitor | ||
""" | ||
|
||
import json | ||
|
||
import requests | ||
import websockets | ||
|
||
# Provisioner public key | ||
PROVISIONER = "0123456789abcdef..." | ||
|
||
|
||
async def listen_to_accepted_blocks() -> None: | ||
url = "wss://nodes.dusk.network/on" | ||
|
||
async with websockets.connect(url) as wss: | ||
# Get a session ID | ||
session_id = await wss.recv() | ||
|
||
# Subscribe to the accepted blocks topic | ||
with requests.get( # noqa: ASYNC210 | ||
"https://nodes.dusk.network/on/blocks/accepted", | ||
headers={"Rusk-Session-Id": session_id}, | ||
timeout=10, | ||
) as req: | ||
req.raise_for_status() | ||
|
||
while "listening": | ||
raw_block = await wss.recv() | ||
raw_block = raw_block[raw_block.find(b'{"header"') :] | ||
block = json.loads(raw_block) | ||
if block["header"]["generator_bls_pubkey"] == PROVISIONER: | ||
print(block["header"]["height"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
asyncio.run(listen_to_accepted_blocks()) |
Oops, something went wrong.