# Canton Coinを送る

> AmuletRulesの一括の送金を、入力と出力とcontextの中身と、関数の型の合い方まで、表と2つの図で追います。

- URL: https://cardene.dev/diagrams/canton-amulet-transfer
- 公開日: 2026-11-22
- 更新日: 2026-11-22
- トピック: Blockchain
- タグ: Canton
- 親の図解: [Amuletの送金](https://cardene.dev/diagrams/canton-amulet-transfers.md): Canton Coinを表すAmuletの一括の送金を、入力と出力とcontextの中身から、章の中の図解で追います。

Canton Coin(CC)は、`Amulet`のコントラクトで表されます。
この頁では、`AmuletRules`のコントラクトの`AmuletRules_Transfer`が受け取る一括の送金を追います。
一括の送金は、入力の列と出力の列を持ちます。
そこで、送金の中身である入力と出力、送金が参照するコントラクトをまとめるcontextの型、送金に関わる型と関数、返される結果を、表と図で追います。

mining roundは、頁「Canton Coinの役と料金を知る」で見ました。

https://cardene.dev/diagrams/canton-coin-tokenomics

CCと`Amulet`のコントラクトは、頁「packageとDSO partyを知る」で見ました。

https://cardene.dev/diagrams/canton-splice-packages

choiceとcontrollerは、頁「誰が変更を頼めるかを決める」で見ました。

https://cardene.dev/diagrams/canton-ledger-authorization

Optionalは、値がある時と無い時を分ける型で、値が無い時はNoneです。
reward couponは、報酬の引換券です。

## 一括の送金のchoice

`AmuletRules_Transfer`は、次の表の3つの欄を受け取り、`TransferResult`を返します。

| 欄 | 型 |
|---|---|
| `transfer` | `Transfer` |
| `context` | `TransferContext` |
| `expectedDso` | `Optional Party` |

controllerは、決まったpartyではなく、`Set.toList (transferControllers transfer)`で、送金の中身から決まります。
関数`transferControllers`は、`Transfer`を受け取り、その送金のcontrollerを`Set Party`で返します。

図Aは、`expectedDso`をDSOのpartyの任意の欄と呼びます。

次の図Aでは、呼び出しが受け取る3つの欄を、送金の中身、context、DSOのpartyの任意の欄の枝として足して追います。
結果は図に描かず、「結果を受け取る」の節の表で言います。
この図では、枝は欄と型の入れ子だけを示します。

```dragon
mind 呼び出しが受け取る欄

step 呼び出しの3つの欄
  say 呼び出しは、送金の中身と、送金が参照するコントラクトのcontextと、DSOのpartyの任意の欄を受け取ります。
  idea root as "呼び出し" [color: slate]
  idea t as "送金の中身" of root [color: blue]
  idea c as "contextのコントラクト" of root [color: rose]
  idea d as "DSOのpartyの任意の欄" of root [color: slate]
  source CantonのSplice.AmuletRules [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules]

step 送金の中身
  say 送金の中身は、入力の列と出力の列と、送り手と提供者のparty、app rewardを分け合う任意の受取人の列を持ちます。
  idea i as "入力の列" of t [color: blue]
  idea o as "出力の列" of t [color: blue]
  idea s as "送り手のparty" of t [color: blue]
  idea p as "提供者のparty" of t [color: blue]
  idea b as "app rewardを分け合う任意の受取人の列" of t [color: blue]
  source CantonのSplice.AmuletRules [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules]

step contextが指す物
  say contextは、open mining roundとissuing mining roundとvalidatorの権利のコントラクトと、featured appの任意の証明を、コントラクトのIDで指します。
  idea c1 as "open mining round" of c [color: rose]
  idea c2 as "issuing mining round" of c [color: rose]
  idea c3 as "validatorの権利" of c [color: rose]
  idea c4 as "featured appの任意の証明" of c [color: rose]
  source CantonのSplice.AmuletRules [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules]
```

## 送金の中身

`Transfer`は、一括の送金を表し、次の表の5つの欄を持ちます。

| 欄 | 型 |
|---|---|
| `sender` | `Party` |
| `provider` | `Party` |
| `inputs` | `[TransferInput]` |
| `outputs` | `[TransferOutput]` |
| `beneficiaries` | `Optional [AppRewardBeneficiary]` |

`beneficiaries`は、app rewardを分け合う受取人を指します。
図Aは、`sender`を送り手、`provider`を提供者と呼びます。

## 入力の8つの形

`TransferInput`は、一括の送金の1つの入力を表す型で、Damlでvariantと呼ぶ、8つの形のうち1つを取ります。
8つのうち7つの形は、次の表のコントラクトを、コントラクトのIDで送金の入力にします。

| 形 | 指すコントラクト |
|---|---|
| `InputAmulet` | `Amulet` |
| `InputAppRewardCoupon` | `AppRewardCoupon` |
| `InputValidatorRewardCoupon` | `ValidatorRewardCoupon` |
| `InputSvRewardCoupon` | `SvRewardCoupon` |
| `InputValidatorLivenessActivityRecord` | `ValidatorLivenessActivityRecord` |
| `InputUnclaimedActivityRecord` | `UnclaimedActivityRecord` |
| `InputDevelopmentFundCoupon` | `DevelopmentFundCoupon` |

残る1つの`ExtTransferInput`は、欄`dummyUnitField`と`optInputValidatorFaucetCoupon`を持ちます。
`optInputValidatorFaucetCoupon`は、CIP-3で足された、送金へ入れる任意のvalidator faucet couponで、型は`Optional (ContractId ValidatorFaucetCoupon)`です。
関数`mkInputValidatorFaucetCoupon`は、validator faucet couponを送金へ入れるための関数で、`ContractId ValidatorFaucetCoupon`を受け取り、`TransferInput`を返します。

CIPは、頁「CIPが承認され効力を持つまで」で見ました。

https://cardene.dev/diagrams/canton-cip-process

`ExtTransferInput`と`ExtCreatedAmulet`と`ExtInvalidTransferReason`は、Daml 3.0で今はvariantをアップグレードできない状況を回避するために置かれた拡張の形です。
欄`dummyUnitField`も、同じ理由で置かれています。

## 出力の4つの欄

`TransferOutput`は、一括の送金の1つの出力を表し、次の表の4つの欄を持ちます。

| 欄 | 型 | 中身 |
|---|---|---|
| `receiver` | `Party` | 作られる出力の`Amulet`を持つ受取人 |
| `receiverFeeRatio` | `Decimal` | 出力の料金のうち、受取人の出力の量から払う割合 |
| `amount` | `Decimal` | 受取人が負う出力の料金を引く前の、受け取る`Amulet`の量 |
| `lock` | `Optional TimeLock` | 付けるロック |

`receiverFeeRatio`が1.0なら、出力の料金の全てを、指定した出力の量から引きます。
0.0なら、料金の全てを、送り手の入力の残高から引きます。
受取人の料金が指定した出力の量で賄えない時、送金は中止されます。

次の図Bでは、送金の中身の入力の8つの形と出力の4つの欄を、本文の表と同じ名前の枝で追います。
この図では、枝は型の形と欄の入れ子だけを示します。

```dragon
mind 入力の形と出力の欄

step 入力と出力
  say 送金の中身は、入力の列と出力の列を持ちます。入力は8つの形のうち1つを取り、出力は4つの欄を持ちます。
  idea root as "送金の中身" [color: blue]
  idea i as "入力の形" of root [color: blue]
  idea o as "出力の欄" of root [color: blue]
  source CantonのSplice.AmuletRules [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules]

step 入力の8つの形
  say 入力の8つの形は、コントラクトのIDで入力を指す7つの形と、validator faucet couponを入れる拡張の形です。
  idea i1 as "InputAmulet" of i [color: blue]
  idea i2 as "InputAppRewardCoupon" of i [color: blue]
  idea i3 as "InputValidatorRewardCoupon" of i [color: blue]
  idea i4 as "InputSvRewardCoupon" of i [color: blue]
  idea i5 as "InputValidatorLivenessActivityRecord" of i [color: blue]
  idea i6 as "InputUnclaimedActivityRecord" of i [color: blue]
  idea i7 as "InputDevelopmentFundCoupon" of i [color: blue]
  idea i8 as "ExtTransferInput" of i [color: blue]
  source CantonのSplice.AmuletRules [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules]

step 出力の4つの欄
  say 出力の4つの欄は、受取人と、料金を受取人が負う割合と、受け取る量と、付けるロックです。
  idea o1 as "receiver" of o [color: blue]
  idea o2 as "receiverFeeRatio" of o [color: blue]
  idea o3 as "amount" of o [color: blue]
  idea o4 as "lock" of o [color: blue]
  source CantonのSplice.AmuletRules [url: https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules]
```

## contextで参照するコントラクトを渡す

`TransferContext`は、キーでなくコントラクトのIDで参照できるように、送金へ渡す必要のあるコントラクトをまとめた型です。
次の表の4つの欄を持ちます。

| 欄 | 型 |
|---|---|
| `openMiningRound` | `ContractId OpenMiningRound` |
| `issuingMiningRounds` | `Map Round (ContractId IssuingMiningRound)` |
| `validatorRights` | `Map Party (ContractId ValidatorRight)` |
| `featuredAppRight` | `Optional (ContractId FeaturedAppRight)` |

`validatorRights`は、ユーザーから`ValidatorRight`のコントラクトへの対応です。
`featuredAppRight`は、`provider`がfeatured app providerである任意の証明です。

送金の呼び出し方ごとにcontextをまとめる型は、次の表の2つです。

| 型 | 欄 |
|---|---|
| `AppTransferContext` | 型が`ContractId AmuletRules`の`amuletRules`、型が`ContractId OpenMiningRound`の`openMiningRound`、型が`Optional (ContractId FeaturedAppRight)`の`featuredAppRight` |
| `PaymentTransferContext` | 型が`ContractId AmuletRules`の`amuletRules`、型が`TransferContext`の`context` |

contextを受け取る関数は、次の表の3つです。

| 関数 | 受け取る物 | 返す物 |
|---|---|---|
| `exerciseAppTransfer` | `Party`、`AppTransferContext`、`Transfer` | `Update TransferResult` |
| `exercisePaymentTransfer` | `Party`、`PaymentTransferContext`、`Transfer` | `Update TransferResult` |
| `amuletTransferContext` | `ContractId OpenMiningRound`、`Optional (ContractId FeaturedAppRight)` | `TransferContext` |

`amuletTransferContext`は、`Amulet`の入力だけを持つ送金のcontextを作る補助です。

## 要約の型と関数

`executeTransfer`は、送金を実行する関数です。
`executeTransfer'`は、`TransferContext`の代わりに、contextの要約の`TransferContextSummaryV2`を受け取ります。
`TransferContextSummaryV2`は、次の表の7つの欄を持ちます。

| 欄 | 型 |
|---|---|
| `dso` | `Party` |
| `featuredAppProvider` | `Optional Party` |
| `config` | `TransferConfigV2 Amulet` |
| `openRoundNumber` | `Round` |
| `amuletPrice` | `Decimal` |
| `issuingMiningRounds` | `Map Round IssuingMiningRound` |
| `validatorRights` | `Map Party (ContractId ValidatorRight)` |

`TransferContext`か要約の型を受け取る、または返す関数は、次の表の7つです。

| 関数 | 受け取る物 | 返す物 |
|---|---|---|
| `executeTransfer` | `RewardsIssuanceConfig`、`TransferContext`、`Party`、`Transfer` | `Update TransferResult` |
| `executeTransfer'` | `RewardsIssuanceConfig`、`TransferContextSummaryV2`、`Party`、`Transfer` | `Update TransferResult` |
| `summarizeAndValidateContext` | `TransferContext`、`Party`、`Transfer` | `Update TransferContextSummaryV2` |
| `summarizeAndConsumeInputs` | `TransferContextSummaryV2`、2つの`Party`、`[TransferInput]` | `Update TransferInputsSummary` |
| `preprocessOutputs` | `TransferConfigV2 Amulet`、`[TransferOutput]` | `Update TransferOutputsSummary` |
| `summarizeTransfer` | `Party`、`Round`、`Decimal`、`TransferConfigV2 Amulet`、`TransferInputsSummary`、`TransferOutputsSummary` | `Update TransferSummary` |
| `createTransferOutputs` | `Round`、`TransferConfigV2 Amulet`、2つの`Party`、`TransferSummary`、`TransferOutputsSummary` | 作った出力の`[CreatedAmulet]`と、送り手へのお釣りの`Optional (ContractId Amulet)`の組を返す`Update` |

関数`dedupOutputLockHolders`は、`TransferOutput`のロックのholderの重なりを除きます。
これで、holderを保存して料金を取るのを、多くても1回にします。

上の表では、同じ型の名前が、ある関数の返す物と、別の関数の受け取る物に並びます。
`TransferContextSummaryV2`は、`summarizeAndValidateContext`が返し、`summarizeAndConsumeInputs`と`executeTransfer'`が受け取ります。

`TransferInputsSummary`は`summarizeAndConsumeInputs`が返し、`summarizeTransfer`が受け取ります。
`TransferOutputsSummary`は`preprocessOutputs`が返し、`summarizeTransfer`と`createTransferOutputs`が受け取ります。
`TransferSummary`は`summarizeTransfer`が返し、`createTransferOutputs`が受け取ります。

この節は、型の名前が同じ所を挙げるだけで、関数を呼ぶ順と、ある関数が中で別の関数を呼ぶかは示しません。

## 結果を受け取る

`TransferResult`は、次の表の5つの欄を持ちます。

| 欄 | 型 | 中身 |
|---|---|---|
| `round` | `Round` | 送金を登録した`Round` |
| `summary` | `TransferSummary` | 入力と出力の量と、払った料金の要約 |
| `createdAmulets` | `[CreatedAmulet]` | 作った出力の`Amulet`への参照 |
| `senderChangeAmulet` | `Optional (ContractId Amulet)` | 送り手へ返すお釣りの`Amulet`への任意の参照 |
| `meta` | `Optional Metadata` | 任意のメタデータ |

`senderChangeAmulet`は、お釣りを返す料金を引いた後にお釣りが残った時だけ作られます。

`CreatedAmulet`は、送金で作られた出力を表す型で、次の表の3つの形を持ちます。

| 形 | 指す物 |
|---|---|
| `TransferResultAmulet` | `ContractId Amulet` |
| `TransferResultLockedAmulet` | `ContractId LockedAmulet` |
| `ExtCreatedAmulet` | 欄`dummyUnitField`を持つ拡張の形 |

関数`createdAmuletToHolding`は、`CreatedAmulet`を受け取り、`ContractId Holding`を返します。

## 次に読む頁

次の頁「送金の料金と失敗の理由を知る」は、`TransferResult`の`summary`が持つ`TransferSummary`の欄と、料金と時と共に減る量の型と、送金が失敗する理由を追います。

https://cardene.dev/diagrams/canton-amulet-fees

## 出典

https://docs.canton.network/sdks-tools/api-reference/splice-daml/splice-amulet/splice-amuletrules
