iotaledger / iotaledger/notarization
[Task]: Add examples on the usage of Notarization with the gas station
- Dominant language
- Rust
- Stars
- 5
- Forks
- 7
- Avg merge
- 10h 34m
- Merged PRs (30d)
- 11
Description
We need to demonstrate the gas-station usage in an additional example.
Setting up a local Gas-Station service with and without Bearer authentication is a bit tricky at the moment.
## Gas-Station without Bearer authentication
Check out the latest gas-station `dev` branch.
The gas-station without Bearer authentication can be started like this (in the `gas-station/docker` folder):
```bash
> generate-sample-config --config-path config.yaml --docker-compose -n testnet
Unable to find image 'iotaledger/gas-station-tool:latest' locally
latest: Pulling from iotaledger/gas-station-tool
cc41ef31545f: Already exists
607d3ac95693: Pull complete
83ba0c981770: Pull complete
Digest: sha256:c773754bef65bcc5bc3375c1e327f84db477a006dca6f5dafb7c837c2a396493
Status: Downloaded newer image for iotaledger/gas-station-tool:latest
Generated a new IOTA address. If you plan to use it, please make sure it has enough funds: '0x28664b7cc94f2fb82845145acea06c1d7a3277fb1b1d5b764f2b020987654321'
> iota client switch --env testnet
Active environment switched to [testnet]
> iota client faucet --address 0x28664b7cc94f2fb82845145acea06c1d7a3277fb1b1d5b764f2b020987654321
Request successful. It can take up to 1 minute to get the coin. Run iota client gas to check your gas coins.
> docker compose up
[+] Running 3/3
✔ Network docker_default Created 0.0s
✔ Container gas-station-redis Created 0.0s
✔ Container iota-gas-station Created 0.0s
Attaching to gas-station-redis, iota-gas-station
gas-station-redis | Starting ...
...
...
```
On client side, the main difference is to use `executeWithGasStation` instead of `buildAndExecute` like this:
```TS
const { output: notarization } = await notarizationClient
.createLocked()
.withStringState("Undeletable data", "v1")
.withDeleteLock(TimeLock.withUnlockAt(delete_unlock_at))
.withImmutableDescription("This can not be changed any more")
.withUpdatableMetadata("This can be updated")
.finish()
.executeWithGasStation(notarizationClient, "http://localhost:9527/", new DefaultHttpClient());
```
## Using Bearer authentication
Having already performed all the preparation steps described above, you need to add an entry for the `GAS_STATION_AUTH` env variable in the `environment` section of the `docker/docker-compose.yml` file:
```
environment:
- CONFIG_PATH=/app/config.yaml
- RUST_BACKTRACE=1
- GAS_STATION_AUTH=${GAS_STATION_AUTH}
```
After having added this, the gas station needs to be started like this (we are using Bearer token "12345678" for example purposes here):
```bash
GAS_STATION_AUTH="12345678" docker compose up
```
On client side, the Bearer token needs to be provided using the `withAuthToken` function:
```TS
// Create default GasStationParams with AuthToken
const gasStationParams = new GasStationParams().withAuthToken("12345678");
// Print to console for debug purposes
console.log ("gasStationParams.headers:"); // Error: null pointer passed to rust
gasStationParams.headers.forEach((value: boolean, key: string) => {
console.log(key, value);
});
console.log (`gasStationParams.gasReservationDuration: ${gasStationParams.gasReservationDuration}`);
const { output: notarization } = await notarizationClient
.createLocked()
.withStringState("Undeletable data", "v1")
.withDeleteLock(TimeLock.withUnlockAt(delete_unlock_at))
.withImmutableDescription("This can not be changed any more")
.withUpdatableMetadata("This can be updated")
.finish()
.executeWithGasStation(notarizationClient, "http://localhost:9527/", new DefaultHttpClient(), gasStationParams);
```
### Open questions
Ideally we would only have a single source of truth for examples on the usage of IOTA products with gas-station. Not sure how to accomplish this.
Option 1 : Just have verbose examples for Notarization (or Identity, or ...) and reference it from other products.
Option 2: Our [Product-Integration](https://github.com/iotaledger/product-core/issues/34) docs (not existing at the moment)
Contributor guide
Assessment
This issue has not been assessed yet.