前の頁では、アプリが利用者のwalletへallocationを求める依頼を見ました。
この頁は、求められたwalletが、registryにallocationをどう作らせるかを追います。
registryがallocationを直に作らず、複数の段で作る時は、AllocationInstructionで状態を追い、送り手が取り下げられます。
registryは、トークンを管理するアプリで、instrumentは、registryが管理するトークンの種類です。 holdingは、partyの持つ1つのトークンの保有で、allocationを作る時の資金になります。 adminは、registryのアプリを表すpartyです。 これらの語は、章「Token StandardのDaml API」の頁「Token Standardで資産を送る」と「holdingとmetadataの型を知る」が追います。
walletがfactoryでallocationを作らせる
Splice.Api.Token.AllocationInstructionV1は、walletがregistryにallocationを作るよう指示するためのinterfaceをまとめます。
AllocationFactoryを実装するコントラクトは、registryのアプリから取り出し、walletが、allocation instructionか、直にallocationを作るのに使います。
factoryの取り出し方は、章「registryのAPI」の頁「allocationの文脈を受け取る」が追います。
viewAllocationFactoryViewは、このfactoryを使えるinstrumentを管理するregistryのアプリを表すpartyadminと、拡張のためのmetaを持ちます。
factoryのAllocationFactory_Allocateは、送り手のwalletが、settlementの特定のlegに資産のallocationを求める、汎用のchoiceです。
controllerはallocation.transferLeg.senderです。
結果として、allocationが直に作られるか、代わりにallocation instructionが作られるかは、registryしだいです。
次の表は、V1のAllocationFactory_Allocateの引数と返す物を並べます。
| 欄 | 中身 |
|---|---|
expectedAdmin |
factoryを出すadminのpartyの見込み |
allocation |
作るAllocationSpecification |
requestedAt |
依頼の時刻 |
inputHoldingCids |
allocationの資金に使うholding |
extraArgs |
追加の引数 |
| 返す物 | AllocationInstructionResult |
AllocationSpecificationは、settlementの特定のlegへの資産のallocationの指定で、頁「資産を取り置いてsettleする」が追います。
実装は、expectedAdminがfactoryのadminと一致する事を必ず確かめます。
呼ぶ側は、expectedAdminを、自分のParticipant Nodeから読むなど、信頼できる出どころから得るべきです。
そうすれば、vetした全てのDamlのpackageが、expected adminを確かめるinterfaceの実装だけを持つ限り、信頼できない出どころから得たfactoryでも、choiceを安全にexerciseできます。
vetは、packageをvettingすることです。
vettingは、Participant Nodeが他のParticipant Nodeに、どのpackageを支えるかを伝える手段です。 Participant NodeがSynchronizerにVettedPackagesのtopology transactionを登録して行います。 章「packageのuploadとvetting」が追っています。
inputHoldingCidsは、allocationの資金に使うべきholdingです。
holdingを台帳の上に表さないregistryや、allocationのためのholdingを自動で選ぶregistryでは、空でもかまいません。
inputHoldingCidsを指定した時は、成功したallocationが、それらを全てarchiveする決まりです。
そのため、同じholdingを指定した別のallocationは、先に成功した方がholdingを消費していて、作れなくなります。
送り手は、同じholdingを指定して成功時に消費する事で、同じ資金で両方のallocationが作られる事を防ぎ、allocationの重複を防げます。
AllocationFactory_PublicFetchは、actorがcontrollerのchoiceで、expectedAdminとactorを受け取り、AllocationFactoryViewを返します。
各interfaceは、実装するtemplateのsignatoryがcontrollerのArchiveのchoiceを持ちます。
実装は、allocationFactory_allocateImplとallocationFactory_publicFetchImplとallocationInstruction_updateImplとallocationInstruction_withdrawImplなどのmethodで、choiceの中身を与えます。
次の図は、walletがregistryのアプリからfactoryを取り出し、台帳の上のfactoryに作成を求め、allocation instructionができて、registryが状態を更新し、送り手が取り下げるまでを追います。 この図は、registryが複数の段で進める場合を描き、直にallocationを作る場合は、段の説明で触れます。 registryが状態を更新する段と、送り手が取り下げる段は、allocation instructionのコントラクトの段として置きます。
- factoryを取り出す
walletは、registryのアプリから、allocationを作るためのfactoryを取り出します。
- 作成を求める
送り手のwalletは、台帳の上のfactoryに、settlementの特定のlegのために、allocationの作成を求めます。
結果として、allocationが直に作られるか、allocation instructionが作られるかは、registryしだいです。 - allocation instructionができる
registryが複数の段で進める時は、allocation instructionが作られ、作成の状態を追います。
- registryが段を進める
registryは、内部の処理の段を進めて、allocation instructionの状態を更新します。
理由はmetadataで伝えられます。 - 送り手が取り下げる
送り手は、送り手として、allocation instructionのコントラクトに取り下げのchoiceを行えます。
V1のallocation instructionを追う
AllocationInstructionのinterfaceは、registryのアプリにallocationを作るよう求めた、allocation instructionの状態を追います。
registryは、allocation instructionを複数の段で進めてもかまいません。
その時は、このinterfaceのchoiceだけを使うべきです。
interfaceのchoiceだけで進めるのは、walletがトランザクションの履歴を確実に読み、allocationが最後に成功したか失敗したかを判断できるようにするためです。
V1は、allocation instructionに2つのchoiceを持ちます。
| choice | controller | 使う場面 | 受け取る物 | 返す物 |
|---|---|---|---|---|
AllocationInstruction_Update |
instrumentのadminとextraActors |
registryが内部の処理の段を進めて、状態を更新する。理由はmetadataで伝える | extraActorsとextraArgs |
AllocationInstructionResult |
AllocationInstruction_Withdraw |
送り手 | 送り手としてallocation instructionを取り下げる | extraArgs |
AllocationInstructionResult |
AllocationInstruction_Updateでは、実装は、extraActorsが、その更新に見込むactorを含む事を必ず確かめます。
AllocationInstructionResultは、allocationを指示するか、instructionの状態を進めた結果です。
outputとsenderChangeCidsとmetaを持ち、metaは、たとえば、かかった手数料を伝えます。
senderChangeCidsは、資金に使わなかった残額として送り手に返す新しいholdingです。
呼ぶ側は、senderChangeCidsを使って、1つのDamlトランザクションで、複数のallocation instructionをまとめて作るか更新できます。
AllocationInstructionResult_Outputは、3つの形を持ちます。
AllocationInstructionResult_Pendingは、作成がまだ終わらず、さらに段を待つ事を伝えます。
AllocationInstructionResult_CompletedとAllocationInstructionResult_Failedは、作成が終わった結果を伝えます。
| 形 | 伝える事 |
|---|---|
AllocationInstructionResult_Pending |
allocationの作成が、さらに段を待つ事。allocationInstructionCidと共に伝える |
AllocationInstructionResult_Completed |
allocationが作られた事。新しいallocationのコントラクトIDallocationCidと共に伝える |
AllocationInstructionResult_Failed |
allocationの作成が成功せず、資金のために取り置いたholdingを全て放した事 |
viewAllocationInstructionViewは、6つの欄を持ちます。
| 欄 | 中身 |
|---|---|
originalInstructionCid |
元のallocation instructionのコントラクトID。walletが、複数の段を通した更新の流れを追うのに使い、registryが複数の段で進める時だけ入る |
allocation |
作るallocation |
pendingActions |
allocationを作るために、partyごとに残る作業のMap Party Text。allocationの準備に要る、registryごとの処理の進み具合を伝えるのに使える |
requestedAt |
依頼の時刻 |
inputHoldingCids |
資金に使うholding。holdingを台帳の上に表さないregistryでは、空でもかまわない |
meta |
より細かい状態の情報 |
V2は受け入れと取り下げを持つ
V2のAllocationFactory_Allocateは、特定のsettlementのためのallocationの作成を求めます。
controllerはactorsで、直にallocationを作るか、allocation instructionを作るかは、registryしだいです。
V2のAllocationFactory_PublicFetchは、fetchを行うpartyの集まりactorsがcontrollerで、AllocationFactoryViewを返します。
V1との違いを、次の表に並べます。
| 項目 | V1 | V2 |
|---|---|---|
AllocationFactory_Allocateの欄 |
expectedAdminとallocationとrequestedAtとinputHoldingCidsとextraArgs |
settlementとallocationとrequestedAtとinputHoldingCidsとextraArgsとactors |
AllocationFactory_Allocateの返す物 |
AllocationInstructionResult |
AllocationInstructionResult |
| adminの確かめ | expectedAdminがfactoryのadminと一致する事を確かめる |
expectedAdminの欄が無い。allocationのadminのpartyがfactoryのadminと一致する事を確かめる |
| allocation instructionのchoice | AllocationInstruction_UpdateとAllocationInstruction_WithdrawとArchive |
AllocationInstruction_AcceptとAllocationInstruction_WithdrawとArchiveの3つで、Updateは無い |
| 資金に使わなかった残額の欄 | senderChangeCids |
authorizerChangeCids |
V2の実装は、資金に使わなかった入力のholdingと残額を、全てAllocationInstructionResultのauthorizerChangeCidsで返す決まりです。
また、actorsの実際の値を確かめて、許されないallocationの作成を防ぐ決まりです。
actorsは[Party]の型で、authorizerはAccountの型なので、実装は、actorsがauthorizerのaccountを承認できるpartyの組かを確かめ、そうなら、allocationの開始を許すべきです。
accountの提供者が資金を割り当てる権利を持つaccountでは、actorsがaccountの提供者のpartyの組の時も、許すべきです。
V2のAllocationInstruction_Acceptは、allocation instructionを認める必要のある者として受け入れます。
controllerはactorsで、actorsとextraArgsを受け取り、AllocationInstructionResultを返します。
受け入れに要る権限は、registryが自由に決められますが、単独で受け入れられるpartyを、AllocationInstructionView.availableActionsで必ず報告します。
単独で動けるpartyを報告させるのは、walletが、利用者に受け入れの選択肢を見せられるようにするためです。
V2のAllocationInstruction_Withdrawは、allocation instructionを取り下げ、controllerはactorsです。
実装は、許されない取り下げを防ぐため、actorsを必ず確かめます。
取り下げに要る権限もregistryが決められますが、単独で取り下げられるpartyをavailableActionsで必ず報告し、walletが取り下げの選択肢を見せられるようにします。
V2のAllocationInstructionActionは、allocation instructionの状態を進める操作で、3つの形を持ちます。
| 形 | 表す物 |
|---|---|
AIA_Withdraw |
取り下げ |
AIA_Accept |
受け入れ |
AIA_Custom |
名前空間を付けた操作のIDで、metadataのkeyと同じように付ける。allocationを作るために要る、registryごとの操作 |
V2のinterfaceは、各choiceの追加のobserverを返す、allocationFactory_allocateExtraObserversとallocationInstruction_acceptExtraObserversとallocationInstruction_withdrawExtraObserversのmethodを足します。
V2のAllocationInstructionResultは、outputとauthorizerChangeCidsとmetaを持ちます。
outputは、V1と同じく、AllocationInstructionResult_PendingとAllocationInstructionResult_CompletedとAllocationInstructionResult_Failedの3つの形のどれかです。
authorizerChangeCidsは、資金に使わなかったか、残額として作ったauthorizerのholdingを、instrumentId.idをkeyにしたTextMapで持ちます。
V1のsenderChangeCidsと同じく、1つのDamlトランザクションで複数のallocation instructionをまとめて扱うのに使えます。
V2のviewと期限切れ
V2のviewAllocationInstructionViewは、8つの欄を持ちます。
| 欄 | 中身 |
|---|---|
originalInstructionCid |
処理の最初の段でない時に入る、最初のallocation instructionのコントラクトID。walletが、状態の更新をまたいで同じinstructionを結び付けるのに使うべき。同じsettlementの別のallocation instructionの結び付けには使わず、view直下のsettlementの欄を使う |
settlement |
settlement |
allocation |
作るallocation |
requestedAt |
依頼の時刻 |
inputHoldingCids |
資金の要らないallocationでは空。holdingを台帳の上に表さないregistryでも、空でもかまわない |
expiresAt |
Optional Timeで、省略できる。設定された場合は、動きの無いallocation instructionが期限を迎える時刻 |
availableActions |
どの操作を、どのpartyの組が行えるか |
meta |
拡張のための追加のデータ |
expiresAtが設定されている時、その後に、registryは、allocation instructionの期限を切ってもかまいません。
期限を切ると、使われていないallocation instructionが占有する保存領域を回収できます。
また、denial-of-serviceの攻撃から身を守れます。
denial-of-serviceの攻撃は、正規の利用者によるサービスの利用を妨げる攻撃です。
registryは、期限をallocationのsettlementの締め切りにできるだけ近づける事と、allocation instructionへの操作のたびに期限を延ばす事で、要らない期限切れを避けるべきです。
availableActionsは、どの操作を、どのpartyの組が行えるかを表します。
外側のlistは集合の集合として読み、内側のlistのpartyが共に行えば、操作を行えます。
walletは、availableActionsを使って、利用者に操作を取れるかどうかと、どのほかのpartyの操作を待つかを知らせられます。
共同の承認が要る操作には複数のpartyを指定でき、行うには、registryごとの委任のコントラクトが揃っている事が前提です。
次の図は、allocation instructionの戻り値を、まだ終わらない待機中と、終わりの作成済みと失敗に分け、最後に、V2で期限が設定された時だけ起き得る期限切れを別の処理として追います。 この図は、作成済みと失敗と期限切れを、別々の場合として並べます。 資金に使ったholdingが放される段と、期限を切る段は、それぞれ対象のコントラクトの段として置きます。
- 待機中を返す
walletが作成を求めると、registryが複数の段で進める時は、allocation instructionが、さらに段を待つ待機中の戻り値で始まります。
待機中は、作成の終わりではありません。
V1もV2も同じ形です。 - 作成済みを返す場合
allocationが作られた事は、新しいallocationのコントラクトIDと共に伝えられます。
V1もV2も同じ形です。 - 失敗を返す場合
allocationの作成が成功せず、資金のために取り置いたholdingを全て放した事を伝えます。
V1もV2も同じ形です。 - V2だけ 期限を切る
V2で期限が設定されている時は、動きの無いallocation instructionの期限を、registryが期限の時刻の後に切ってもかまいません。
これは、戻り値とは別の処理です。
次に読む頁
次の頁「資産を取り置いてsettleする」は、V1のallocationが、資産を取り置き、締め切りの中でsettleされ、引き出され、取り消されるまでを追います。