# consoleの最上位の道具を使う

> Canton Consoleの最上位から呼べる道具を、説明とノードの集まりとtimeoutとログの水準とファイルの読み書きと待ち方に分けて、返す物と失敗する所まで追います。

- URL: https://cardene.dev/diagrams/canton-console-toolbox
- 公開日: 2026-11-24
- 更新日: 2026-11-24
- トピック: Blockchain
- タグ: Canton
- 親の図解: [Canton Console](https://cardene.dev/diagrams/canton-ops-console.md): 本番のノードを運用者がCanton Consoleで操る手順を、consoleへのつなぎ方から、スクリプトと最上位の道具と複数のノードの管理と、DARとSequencerとMediatorとtestingのコマンドまで追います。

前の頁は、consoleの作業を`.canton`のスクリプトで回す所を追いました。
この頁は、そのスクリプトの中で何度も使う、Canton Consoleの最上位から呼べる道具を追います。
どの道具も、何を返し、どこで失敗するかを見ます。

https://cardene.dev/diagrams/canton-console-scripting

## この頁が追う最上位の道具は6つの組に分かれる

資料のCanton Console Commandsの頁は、Cantonのadmin consoleのコマンドの参照で、Participant NodeとMediatorとSequencerとtopologyのコマンドを扱います。
この頁が追うTop-level Commandsの節のコマンドは、便宜のために、consoleの最上位から呼べます。

Top-level Commandsの節には、`bootstrap`の組もあります。
`bootstrap.synchronizer_local`のようなSynchronizerを初期化するコマンドは、前の頁の節「bootstrapのスクリプトでノードをつなぐ」が使いました。
この頁は、それ以外の6つの組をコマンドの分類として追います。

下の図は、最上位の道具を、組ごとに足していきます。
図の中は、コマンドの名前でなく、何をするかを日本語で書き、名前は本文の表が挙げます。

```dragon
mind consoleの最上位の道具

step 6つの組
  say この頁が追う最上位の道具は、説明を出す道具と、ノードの集まりと、timeoutと、Ledger APIのコマンドを作る道具と、ログの水準と、補助の道具の6つの組に分かれます。
  idea root as "最上位の道具" [color: slate]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 説明と抜け方
  say consoleを抜けるコマンドと、コマンドの説明を出すコマンドがあり、説明は組ごとにも出せます。
  idea a as "consoleの基本" of root [color: blue]
  idea a1 as "抜ける" of a [color: blue]
  idea a2 as "説明を出す" of a [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step ノードの集まりと参照
  say ノードの種類ごとの全ノードの集まりと、設定に書いた名前のノードを操作する参照があります。
  idea b as "ノードを指す" of root [color: blue]
  idea b1 as "種類ごとの集まり" of b [color: blue]
  idea b2 as "名前を付けた参照" of b [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step timeout
  say consoleのコマンドのtimeoutを返す道具と、設定する道具があります。
  idea c as "待つ時間" of root [color: blue]
  idea c1 as "返す" of c [color: blue]
  idea c2 as "設定する" of c [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step Ledger APIのコマンドを作る道具
  say createとexerciseのコマンドを作る道具があります。
  idea d as "コマンドを作る" of root [color: blue]
  idea d1 as "createを作る" of d [color: blue]
  idea d2 as "exerciseを作る" of d [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step ログの水準
  say ログの水準を調べる道具と、動いたまま変える道具があります。
  idea e as "ログの水準" of root [color: blue]
  idea e1 as "調べる" of e [color: blue]
  idea e2 as "変える" of e [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 補助の道具の4つの働き
  say 補助の道具は、条件が満たされるまで待つ道具と、ファイルを読み書きする道具と、調べて登録する道具と、Damlスクリプトの設定を作る道具を持ちます。
  idea f as "補助の道具" of root [color: blue]
  idea f1 as "条件の確認を待つ" of f [color: blue]
  idea f2 as "ファイルを読み書きする" of f [color: blue]
  idea f3 as "調べて登録する" of f [color: blue]
  idea f4 as "Damlスクリプトの設定を作る" of f [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## consoleを抜ける道具と説明を出す道具

`exit`は、consoleを抜けます。
`help`は、consoleのコマンドの説明を出し、`help("methodName")`と打つと、そのコマンドの詳しい説明を出します。

最上位のコマンドの組は、`bootstrap.help`と`console.help`と`ledger_api_utils.help`と`logging.help`と`utils.help`を持ちます。
どれも引数`methodName`を取り、`help()`か`help("methodName")`の形で、その組のコマンドの説明を出します。

## ノードの集まりと参照を使う

`mediators`と`nodes`と`participants`と`sequencers`は、種類ごとの全ノードの集まりで、それぞれ`.all`と`.local`と`.remote`を持ちます。

| 集まり | 中身 |
|---|---|
| `mediators` | Mediatorのノード |
| `nodes` | 全てのノード |
| `participants` | Participant Node |
| `sequencers` | Sequencerのノード |

`mediator1`と`participant1`と`participant2`と`sequencer1`は、設定に書いた名前のノードを操作する参照です。
前の頁と同じく、打つ形は`participant1.help`か`participant1.help("methodName")`です。
資料は、ドットを省いた`participant1 help`の形で示します。

## consoleのコマンドのtimeoutを決める

`console.command_timeout`は、consoleのコマンドのtimeoutを、`NonNegativeDuration`の型で返します。
timeoutが過ぎると、consoleは結果を待つのをやめますが、コマンド自体は背後で実行が続きます。
`console.set_command_timeout`は、引数`newTimeout`でtimeoutを設定します。
新しいtimeoutは、正の値にします。

下の図は、timeoutが過ぎた時に、consoleとコマンドがどう分かれるかを追います。

```dragon
sequence timeoutが過ぎた時のconsoleとコマンド

box Con as console [note: 結果を待つ, color: blue, icon: user]
box Cmd as コマンド [note: 実行されている, color: slate, icon: app]

step コマンドを実行して結果を待つ
  say consoleはコマンドを実行して、結果を待ちます。待つ長さは、consoleのコマンドのtimeoutが決めます。
  Con -> Cmd: 実行して待つ
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step timeoutが過ぎる
  say timeoutが過ぎると、consoleは結果を待つのをやめます。
  act Con: 待つのをやめる
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step コマンドは実行が続く
  say consoleが待つのをやめても、コマンド自体は背後で実行が続きます。
  act Cmd: 背後で実行が続く
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## Ledger APIのコマンドを作る

`ledger_api_utils`の組は、Ledger APIに渡すコマンドを作ります。
どれも、`com.daml.ledger.api.v2.commands.Command`を返します。
`exercise`は、同じ名前で2つの形を持ち、渡す引数の型で選び分けます。

| コマンド | 作る物 | 渡す物 |
|---|---|---|
| `ledger_api_utils.create` | createのコマンド | `packageId`と`module`と`template`と`arguments` |
| `ledger_api_utils.exercise` | exerciseのコマンド | `CreatedEvent`と`choice`と`arguments` |
| `ledger_api_utils.exercise` | exerciseのコマンド | `packageId`と`module`と`template`と`choice`と`arguments`と`contractId` |

## ログの水準を調べて変える

`logging.get_level`は、引数`loggerName`の今のログの水準を、`Option[Level]`の型で返します。
`Some`と`None`は、Scalaで値がある時と無い時を分けて返す形で、値がある時は`Some(値)`を、無い時は`None`を返します。

`logging.set_level`は、`loggerName`のログの水準を、動いたまま変えます。
水準の値は、`TRACE`と`DEBUG`と`INFO`と`WARN`と`ERROR`と`OFF`と`null`です。

## utilsの道具を使う

utilsの組は、待つ道具と、ファイルを読み書きする道具と、調べて登録する道具と、Damlスクリプトの設定を作る道具を持ちます。

### 条件が満たされるまで待つ

`utils.retry_until_true`は、同じ名前で2つの形を持ち、渡す引数の数と型で選び分けます。

`timeout`と`maxWaitPeriod`と`condition`と`failure`を渡す形は、`timeout`の間、`condition`がtrueになるまで待ちます。
評価をやり直す間隔は、`maxWaitPeriod`まで指数的に伸びます。
引数`failure`で、失敗の文を渡します。

`condition`だけを渡す形は、既定のtimeoutで、`condition`がtrueになるまで待ちます。
既定のtimeoutは、設定の`parameters.timeouts.console.bounded`から取ります。
`bounded`は、前の頁で見た、決まった時間で終わる見込みのコマンドに適用するtimeoutです。

`utils.synchronize_topology`は、届く全てのノードで、全てのtopologyの変更が反映されるまで待ちます。
引数に`timeoutO`を取ります。

### ファイルを読み書きする

Protobufのメッセージをファイルへ書き、ファイルから読む道具があります。

:::details Protobuf
Protobufは、Protocol Buffersの略で、Googleが開発した、データを決まった形式のバイト列に変換してやり取りするための仕組みです。
送るデータの形を先に定義しておき、その定義から送る側と受ける側のコードを作ります。
:::

読む道具は次の3つです。

| コマンド | 返す物 | 失敗する時 |
|---|---|---|
| `utils.read_all_messages_from_file` | ファイルから読んだ複数のProtobufのメッセージ | ファイルを読めないか解釈できない時、例外で失敗する |
| `utils.read_byte_string_from_file` | ファイルから読んだ`ByteString` | ファイルを読めない時、例外で失敗する |
| `utils.read_first_message_from_file` | ファイルから読んだ1つのProtobufのメッセージ | ファイルを読めないか解釈できない時、例外で失敗する |

書く道具は、`utils.write_to_file`の1つの名前で、引数`data`の型で選び分けます。
引数`fileName`には、書き込むファイルの名前を渡します。

| 渡す`data` | 書く物 |
|---|---|
| `ByteString` | `ByteString` |
| 1つのProtobufのメッセージ | 1つのProtobufのメッセージ |
| 複数のProtobufのメッセージ | 複数のProtobufのメッセージ |

### 調べて登録する

| コマンド | 返す物 | 使う時 |
|---|---|---|
| `utils.object_args` | 渡したオブジェクトのフィールド名のリスト | ケースクラスの返り値を調べる時 |
| `utils.type_args` | 型のフィールド名のリスト | 要求のオブジェクトを新しく作る時 |
| `utils.auto_close` | | Cantonが止まる時に一緒に閉じる`AutoCloseable`のオブジェクトを登録する時 |
| `utils.cantonprocesslogger` | プロセスのログをCantonのログへ転送する`ProcessLogger` | 引数に`TracedLogger`を渡す時 |

### Damlスクリプトの設定を作る

`utils.generate_daml_script_participants_conf`は、Damlスクリプト用のParticipant Nodeの設定を作ります。
`daml script`の`--participant-config`のフラグに渡せるJSONのファイルを、`java.io.File`で返します。

:::details JSON
JSONは、データを文字で表すための形式で、Webのプログラムどうしのデータのやり取りに広く使われています。
:::

JSONは、`default_participant`と`participants`と`party_participants`の欄を持ちます。
`default_participant`は`host`と`port`を持ちます。
引数`defaultParticipant`でParticipant Nodeを渡した時に、既定のParticipant Nodeが足されます。
引数`file`は書き出すファイルの名前で、省略した時のファイル名は`participant-config.json`です。

| 引数 | 省略した時 | 働き |
|---|---|---|
| `file` | `participant-config.json` | 書き出すファイルの名前 |
| `useParticipantAlias` | `true` | UIDの代わりにParticipant Nodeのエイリアスを使う |
| `defaultParticipant` | `None` | 渡した時だけ、既定のParticipant Nodeを足す |

## 次に読む頁

次の頁「consoleで複数のノードを管理する」は、運用者がCanton Consoleから、手元とリモートの複数のノードをどう操作するかを追います。

https://cardene.dev/diagrams/canton-console-admin

## 出典

https://docs.canton.network/global-synchronizer/reference/canton-console-commands
