# TeleporterRegistryOwnableApp

> TeleporterRegistryOwnableAppは、TeleporterRegistryAppの機能にOpenZeppelinのOwnableによる所有者ベースのアクセス制御を組み合わせた抽象コントラクトです。

- URL: https://cardene.dev/books/avalanche-teleporter/adb6a6
- 本: Avalanche Teleporter (https://cardene.dev/books/avalanche-teleporter.md)
- 章: 10 / 11
- 前の章: https://cardene.dev/books/avalanche-teleporter/dbd0a1.md
- 次の章: https://cardene.dev/books/avalanche-teleporter/fbcdfb.md
- 公開日: 2025-09-12
- 更新日: 2025-09-12
- トピック: Blockchain
- タグ: ブロックチェーン, solidity, ethereum, smartcontract

## 概要

`TeleporterRegistryOwnableApp`は、`TeleporterRegistryApp`の機能にOpenZeppelinの`Ownable`による所有者ベースのアクセス制御を組み合わせた抽象コントラクトです。
これにより、Teleporterのバージョン管理に関する重要な操作をコントラクトの所有者（Owner）のみに制限します。

このコントラクトは、`TeleporterRegistryApp`を継承し、その中で定義されている抽象的なアクセス制御チェック関数 `_checkTeleporterRegistryAppAccess` を実装します。
実装には`Ownable`コントラクトの`_checkOwner`関数が用いられており、`updateMinTeleporterVersion`や`pauseTeleporterAddress`といった管理者権限が必要な関数は、コントラクトの所有者だけが呼び出せるようになります。

開発者はこのコントラクトを継承することで、自身でアクセス制御ロジックを記述することなく、標準的で安全な所有者ベースの権限管理を持つTeleporter対応アプリケーションを容易に構築できます。

## 機能

このコントラクトの主な機能は、`TeleporterRegistryApp`が持つバージョン管理機能（最低バージョンの更新、特定バージョンの停止・再開）に対して、`Ownable`パターンを用いたアクセス制御を提供することです。

## フロー

- **所有者による最低バージョンの更新**

### 所有者による最低バージョンの更新

```mermaid
sequenceDiagram
    participant Owner as 所有者
    participant App as TeleporterRegistryOwnableApp (継承先コントラクト)

    Owner->>+App: updateMinTeleporterVersion(新しいバージョン)
    App->>App: _checkTeleporterRegistryAppAccess()
    Note over App: 内部でOwnableの_checkOwner()を呼び出し、<br/>msg.senderが所有者であることを検証
    App->>App: _setMinTeleporterVersion(新しいバージョン)
    App-->>-Owner: 成功
```

## コード

https://github.com/ava-labs/icm-contracts/blob/main/contracts/teleporter/registry/TeleporterRegistryOwnableApp.sol

```solidity
// (c) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// SPDX-License-Identifier: LicenseRef-Ecosystem

pragma solidity 0.8.25;

import {TeleporterRegistryApp} from "./TeleporterRegistryApp.sol";
import {Ownable} from "@openzeppelin/contracts@5.0.2/access/Ownable.sol";

/**
 * @dev Contract that inherits {TeleporterRegistryApp} and allows
 * only owners of the contract to update the minimum Teleporter version or
 * pause and unpause specific Teleporter versions.
 *
 * @custom:security-contact https://github.com/ava-labs/icm-contracts/blob/main/SECURITY.md
 */
abstract contract TeleporterRegistryOwnableApp is TeleporterRegistryApp, Ownable {
    constructor(
        address teleporterRegistryAddress,
        address initialOwner,
        uint256 minTeleporterVersion
    )
        TeleporterRegistryApp(teleporterRegistryAddress, minTeleporterVersion)
        Ownable(initialOwner)
    {}

    /**
     * @dev See {TeleporterRegistryApp-_checkTeleporterRegistryAppAccess}
     *
     * Checks that the caller is the owner of the contract for updating {minTeleporterVersion},
     * and pausing/unpausing specific Teleporter version interactions.
     */
    function _checkTeleporterRegistryAppAccess() internal view virtual override {
        _checkOwner();
    }
}
```

## 関数

### `constructor`

```sol
constructor(
    address teleporterRegistryAddress,
    address initialOwner,
    uint256 minTeleporterVersion
)
    TeleporterRegistryApp(teleporterRegistryAddress, minTeleporterVersion)
    Ownable(initialOwner)
{}
```

コントラクトを初期化する関数。
デプロイ時に、継承している`TeleporterRegistryApp`と`Ownable`の両方のコンストラクタを呼び出して初期化します。
`TeleporterRegistryApp`にはレジストリのアドレスと最低バージョン番号を、`Ownable`にはコントラクトの初期所有者のアドレスを渡します。

**処理フロー**

1. `TeleporterRegistryApp`のコンストラクタを`teleporterRegistryAddress`と`minTeleporterVersion`を引数に呼び出します。
2. `Ownable`のコンストラクタを`initialOwner`を引数に呼び出し、コントラクトの所有者を設定します。

**引数**

- **teleporterRegistryAddress**
    `TeleporterRegistry`コントラクトのアドレス。
- **initialOwner**
    このコントラクトの初期所有者となるアドレス。
- **minTeleporterVersion**
    メッセージ受信を許可する`TeleporterMessenger`の最低バージョン番号。

### `_checkTeleporterRegistryAppAccess`

```sol
function _checkTeleporterRegistryAppAccess() internal view virtual override {
    _checkOwner();
}
```

`TeleporterRegistryApp`の管理機能へのアクセス権を検証する内部関数。
親コントラクト`TeleporterRegistryApp`で`virtual`として定義された関数を`override`して実装しています。
この関数は、`updateMinTeleporterVersion`などの重要な関数から呼び出されます。

**処理フロー**

1. `Ownable`コントラクトから継承した内部関数`_checkOwner()`を呼び出します。
2. (`_checkOwner()`内) `msg.sender`がコントラクトの所有者（owner）と一致するかどうかを確認します。一致しない場合はエラーを返します。
