# transferの文脈を受け取る

> transferのchoiceの前に、registryかScan Proxyから受け取るfactoryとchoice contextの要求と応答を2つの図で追い、transferの種類は表で比べます。

- URL: https://cardene.dev/diagrams/canton-transfer-choice-context
- 公開日: 2026-11-24
- 更新日: 2026-11-24
- トピック: Blockchain
- タグ: Canton
- 親の図解: [registryのAPI](https://cardene.dev/diagrams/canton-ext-registry-api.md): walletがregistryかScan Proxyから、instrumentの情報とtransferとallocationのchoice contextを受け取る所を、章の中の図解で追います。

前の頁「instrumentの情報と表示の決まりを引く」では、walletがregistryからinstrumentの情報を取得する所を見ました。

https://cardene.dev/diagrams/canton-token-instrument-metadata

この頁では、walletがtransferのchoiceを実行する前に、registryの台帳の外のAPIから受け取る物を追います。
図Aは要求と応答の順、図Bは応答の欄を追い、transferの種類は表で比べます。
受け取るエンドポイントは、registryが自ら出す版と、validatorのAPIの下のScan Proxyの版の2か所にあります。

## factoryとchoice contextの語

`TransferInstruction`は、進行中の送金の状態を追うコントラクトです。
`TransferFactory`は、消費されないfactoryのコントラクトで、walletはregistryの台帳の外のAPIからfactoryのIDを取ってきて、choiceの`TransferFactory_Transfer`をexerciseし、送金を始めます。

factoryのchoiceを実行する前には、registryの台帳の外のAPIから、exerciseの成功に要る`disclosedContracts`、choiceの引数の`context`として渡す`choiceContextData`を得ます。
`ChoiceContext`は、registryの台帳の外のAPIから得る中身の見えないデータで、registryの内部のデータを台帳の上の実行へ渡します。

choice、exercise、archiveは、章「Damlのtemplateとchoice」の頁「choiceでコントラクトを変える」が追っています。

https://cardene.dev/diagrams/canton-daml-contract-choice

explicit disclosureは、章「多者の合意と権限の設計」の頁「見えないコントラクトを渡して使う」が追っています。
この頁のdisclosureは、explicit disclosureでトランザクションに付けて渡すコントラクトを指します。

https://cardene.dev/diagrams/canton-explicit-disclosure

## 受け取るエンドポイントは4つの用途とV1とV2

Scan Proxyは、transfer instructionに対して、acceptとrejectとwithdrawの3つのchoiceのcontextを返すエンドポイントと、factoryを返すエンドポイントを持ちます。
各エンドポイントは、V1とV2の2つの版を持ち、V2は0.6.11で足されました。
transfer instructionのIDは、パスの`:transferInstructionId`で渡し、acceptやrejectやwithdrawの対象になるtransfer instructionのコントラクトIDです。

| 用途 | V1のパス | V2のパス |
|---|---|---|
| transfer instructionをacceptするchoiceのcontext | `transfer-instruction/v1/:transferInstructionId/choice-contexts/accept` | `transfer-instruction/v2/:transferInstructionId/choice-contexts/accept` |
| transfer instructionをrejectするchoiceのcontext | `transfer-instruction/v1/:transferInstructionId/choice-contexts/reject` | `transfer-instruction/v2/:transferInstructionId/choice-contexts/reject` |
| transfer instructionをwithdrawするchoiceのcontext | `transfer-instruction/v1/:transferInstructionId/choice-contexts/withdraw` | `transfer-instruction/v2/:transferInstructionId/choice-contexts/withdraw` |
| transferを始めるためのfactoryとchoice context | `transfer-instruction/v1/transfer-factory` | `transfer-instruction/v2/transfer-factory` |

表の8つのパスは全てPOSTで、Scan Proxyの版では`/v0/scan-proxy/registry/`の下、registryが自ら出す版では`/registry/`の下に、同じ形で置かれます。
どの版も、4つの用途のエンドポイントを持ちます。

V1の4つのエンドポイントは、400と404のエラーで、必須の`error`の欄を返します。
V2の4つのエンドポイントは、400と404に加えて409のエラーも、必須の`error`の欄で返します。
V1の応答の一覧には409がなく、409は`synchronizerId`の欄の説明にだけ出ます。

## factoryを受け取ってからchoiceを実行する順

図Aでは、walletがV2のtransfer-factoryのエンドポイントを呼んで、factoryとchoice contextを受け取り、Participant Nodeでchoiceを実行する所を追います。
段4は、段1の要求が409になる別の場合で、この時、walletはchoiceの実行へ進みません。
この図では、registryは、Scan Proxyの版でも自ら出す版でも同じ箱で描きます。

transfer instructionのacceptとrejectとwithdrawの前も、choice contextを受け取りますが、応答の形が違います。
factoryの応答は、`factoryId`と`transferKind`を持ち、`choiceContextData`と`disclosedContracts`は`choiceContext`の中にあります。
acceptなどの応答は、`factoryId`と`transferKind`を持たず、`choiceContextData`と`disclosedContracts`が最上位にあります。

```dragon
sequence factoryとchoice contextを受け取って実行する順と、409の別の場合

box R as registry [note: transferのfactoryを持つ, color: rose, icon: server]
box W as wallet [note: transferを始める側, color: blue, icon: user]
box P as Participant Node [note: choiceを実行する, color: slate, icon: server]

step factoryを頼む
  say walletは、transferを実行する前に、registryのV2のtransfer-factoryのエンドポイントを呼び、factoryとchoice contextを頼みます。
  W -> R: factoryを頼む
  source CantonのPOST /registry/transfer-instruction/v2/transfer-factory [url: https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2transfer-factory]

step 文脈が返る
  say registryは、factoryのコントラクトのIDのfactoryIdと、transferの種類のtransferKindと、choice contextを返します。choice contextの中に、choiceを実行するための追加のデータと、開示するコントラクトが入ります。
  R -> W: 文脈を返す
  source CantonのPOST /registry/transfer-instruction/v2/transfer-factory [url: https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2transfer-factory]

step choiceを実行する
  say walletは、factoryIdで指したfactoryのchoiceを、choiceContextDataをchoiceの引数のcontextに入れ、disclosedContractsをParticipant Nodeへ開示して、実行します。
  W -> P: 開示して実行
  source CantonのPOST /registry/transfer-instruction/v2/transfer-factory [url: https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2transfer-factory]

step 別の場合は409
  say 段1の要求で、開示するコントラクトがreassignmentの途中なら、registryの応答は200でなく409になります。この場合は、choiceの実行へ進みません。
  R -> W: 409を返す
  source CantonのPOST /registry/transfer-instruction/v2/transfer-factory [url: https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2transfer-factory]
```

reassignmentは、移す元のSynchronizerへunassignmentを、移す先のSynchronizerへassignmentを送る2段の手順です。
unassignmentは、コントラクトを移す元のSynchronizerから外す段で、assignmentは、移す先のSynchronizerへ入れる段です。

## 返るtransferの種類

V1とV2のtransfer-factoryのエンドポイントは、どちらも応答の必須の`transferKind`で、使うtransferの手順を返します。
値は3つで、それぞれ移すための条件が違います。

| `transferKind` | 移す条件 |
|---|---|
| `offer` | 受け手にtransferを申し出て、受け手がacceptした時だけ移す |
| `direct` | 受け手が直接のtransferを事前に承認した時だけ選ばれ、承認を求めずに移す |
| `self` | 送り手と受け手が同じpartyで、承認が要らず、たいていすぐ終わる |

## 応答の欄

図Bでは、transfer instructionのacceptのエンドポイントの応答の欄を、枝に分けて追います。
reject、withdrawの応答も、同じ形です。
この図では、枝は応答の欄の置き場だけを示し、欄どうしの関係は示しません。

```dragon
mind acceptの応答が持つ欄

step 応答の2つの欄
  say transfer instructionのacceptの200の応答は、最上位に、choiceを実行する時に使う必須の追加のデータのchoiceContextDataと、Participant Nodeへ開示する必須のコントラクトのdisclosedContractsを持ちます。
  idea root as "acceptの応答" [color: slate]
  idea ccd as "choiceContextData" of root [color: blue]
  idea dc as "disclosedContracts" of root [color: blue]
  source CantonのPOST /v0/scan-proxy/registry/transfer-instruction/v1/:transferInstructionId/choice-contexts/accept [url: https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1:transferinstructionidchoice-contextsaccept]

step 開示するコントラクトの必須の欄
  say 開示するコントラクトの各要素は、必須のtemplateIdとcontractIdとcreatedEventBlobとsynchronizerIdの4つの欄を持ちます。synchronizerIdは、コントラクトが今割り当てられているSynchronizerの識別子です。
  idea tid as "templateId" of dc [color: blue]
  idea cid as "contractId" of dc [color: blue]
  idea blob as "createdEventBlob" of dc [color: blue]
  idea sid as "synchronizerId" of dc [color: blue]
  source CantonのPOST /v0/scan-proxy/registry/transfer-instruction/v1/:transferInstructionId/choice-contexts/accept [url: https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1:transferinstructionidchoice-contextsaccept]

step 任意のdebugの欄
  say 任意のdebugPackageNameとdebugPayloadとdebugCreatedAtは、createdEventBlobの中身と一致しないことがあります。
  idea dpn as "debugPackageName" of dc [color: blue]
  idea dpl as "debugPayload" of dc [color: blue]
  idea dca as "debugCreatedAt" of dc [color: blue]
  source CantonのPOST /v0/scan-proxy/registry/transfer-instruction/v1/:transferInstructionId/choice-contexts/accept [url: https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1:transferinstructionidchoice-contextsaccept]
```

debugで始まる3つの欄は、`createdEventBlob`の中身と一致しないことがあるので、データの提供者を信頼する時だけ使います。

## 要求の本文の欄

transfer instructionのacceptのエンドポイントの要求の本文は、任意の`meta`と、`excludeDebugFields`の2つの欄を持ちます。
`meta`は、choiceに渡すmetadataで、choice contextに取り込むべき物で、拡張のためにあります。
`excludeDebugFields`は、既定がfalseで、trueにすると、応答は`debug`で始まる欄を持たず、帯域を節約できます。

factoryのエンドポイントの要求の本文は、これと違い、必須の`choiceArguments`と、`excludeDebugFields`を持ち、最上位に`meta`を持ちません。
`choiceArguments`は、factoryのchoiceに渡すつもりの引数です。

## 次に読む頁

次の頁「allocationの文脈を受け取る」は、allocationを作り、settleし、cancelやwithdrawをする前に、registryかScan Proxyから、factoryとchoice contextをどう受け取り、何に気を付けるかを追います。

https://cardene.dev/diagrams/canton-allocation-choices

## 出典

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1:transferinstructionidchoice-contextsaccept

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1:transferinstructionidchoice-contextsreject

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1:transferinstructionidchoice-contextswithdraw

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-api/post-v0scan-proxyregistrytransfer-instructionv1transfer-factory

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-v2-api/post-v0scan-proxyregistrytransfer-instructionv2:transferinstructionidchoice-contextsaccept

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-v2-api/post-v0scan-proxyregistrytransfer-instructionv2:transferinstructionidchoice-contextsreject

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-v2-api/post-v0scan-proxyregistrytransfer-instructionv2:transferinstructionidchoice-contextswithdraw

https://docs.canton.network/reference/splice-scan-proxy-transfer-instruction-v2-api/post-v0scan-proxyregistrytransfer-instructionv2transfer-factory

https://docs.canton.network/reference/splice-transfer-instruction-api/post-registrytransfer-instructionv1:transferinstructionidchoice-contextsaccept

https://docs.canton.network/reference/splice-transfer-instruction-api/post-registrytransfer-instructionv1:transferinstructionidchoice-contextsreject

https://docs.canton.network/reference/splice-transfer-instruction-api/post-registrytransfer-instructionv1:transferinstructionidchoice-contextswithdraw

https://docs.canton.network/reference/splice-transfer-instruction-api/post-registrytransfer-instructionv1transfer-factory

https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2:transferinstructionidchoice-contextsaccept

https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2:transferinstructionidchoice-contextsreject

https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2:transferinstructionidchoice-contextswithdraw

https://docs.canton.network/reference/splice-transfer-instruction-v2-api/post-registrytransfer-instructionv2transfer-factory
