前の頁では、V1のallocationが、legごとに資産を取り置き、締め切りの中でsettleされる所を見ました。
この頁は、V2のAllocationが、authorizerの承認をどう表し、executorが、allocationの束をどう正味でsettleし、繰り返しのsettlementをどう続けるかを追います。
Splice.Api.Token.AllocationV2が定める型も、図の後に表で並べます。
settlementは、アプリが実行したい、受け渡しのまとまりで、settleは、それを実行する事です。 transfer legは、settlementの中の、2つのaccountの間の1つの受け渡しで、legは、その短い呼び名です。 executorは、settlementを実行するparty、adminは、資産を管理するregistryのアプリを表すpartyです。 authorizerは、settlementのtransferを承認するaccountで、accountは、章「Token StandardのDaml API」の頁「holdingとmetadataの型を知る」が追います。
authorizerのaccountのpartyは、そのaccountに関わる、accountの所有者と提供者のpartyです。 正味は、同じinstrumentについて、accountごとに全てのtransferの入金と引き落としを差し引いた結果の量です。
choiceとconsumingとnonconsumingは、章「Damlのtemplateとchoice」の頁「choiceでコントラクトを変える」が追っています。
V2のallocationは承認を表す
V2のAllocationは、settlementの一部として、transfer legの正味の量の資産を送るか受け取る事への、authorizerの承認を表すコントラクトです。
V2のsettlementでは、executorと、instrumentのadminが、全てのtransfer legに、相手の側からの合う承認がある事を確かめます。
instrumentは、registryが管理するトークンの種類です。
V1のAllocationは資産の取り置きを表し、V2のAllocationは承認を表します。
同じinstrumentのadminを持つallocationの束を正味でsettleする仕組みは、2つ後の節で見ます。
3つのchoiceを呼ぶ者
V2のAllocationは、Allocation_SettleとAllocation_CancelとAllocation_Withdrawの3つのchoiceを持ち、どれもactorsをcontrollerにします。
actorsは、そのchoiceを実行するpartyの集まりで、accountそのものではありません。
| choice | 行う事 | 呼ぶ者 | 返す物 |
|---|---|---|---|
Allocation_Settle |
transfer legの正味の量を動かして、allocationをsettleする | 既定では、actorsがallocationのadminとexecutorsに等しい事を求める |
AllocationResult |
Allocation_Cancel |
allocationを取り消して資金を放し、settlementを実行する承認を無効にする | 普通は、settlementが実行されないと分かった時のexecutorと、期限の切れたallocationを取り消すadmin | AllocationResult |
Allocation_Withdraw |
authorizerがallocationを引き出して資金を放し、settlementを実行する承認を無効にする。誤って作ったallocationを取り消すのに使える | 既定では、authorizerのaccountのparty | AllocationResult |
3つのchoiceで、実装は、actorsを確かめて、許されない操作を防ぐ決まりです。
Allocation_Cancelでは、既定で、actorsがallocationのexecutorsに等しい事を求めるべきです。
Allocation_Settleでは、既定で、actorsがallocationのadminとexecutorsに等しい事を求め、両者が共にatomicなsettlementを保証できるようにするべきです。
atomicは、全体が成功するか、何も起きないかのどちらかになる事です。
Allocation_Withdrawでは、既定で、authorizerのaccountのpartyに引き出しを許すべきです。
Allocation_Settleの承認は、普通、SettlementFactory_SettleBatchのchoiceの一部として与えられ、executorは、V2のallocationをsettleするのに、このSettlementFactory_SettleBatchを使うべきです。
settlementの締め切りを設けた時、実装は、締め切りが過ぎた後にAllocation_Settleを呼ばせてはいけません。
committedがTrueのallocationは、settlementの締め切りが過ぎた後にしか、Allocation_Withdrawをexerciseできません。
V2のAllocation_CancelとAllocation_SettleとAllocation_Withdrawは、nonconsumingです。
nonconsumingにするのは、トランザクションの読み取りの互換のために、consumingのV1のchoiceのAllocation_CancelとAllocation_ExecuteTransferとAllocation_Withdrawを呼ぶなど、別の消し方を許すためです。
そのため、3つのchoiceのどれでも、実装は、choiceの本体でallocationを必ず消費します。
Allocation_Settleには、繰り返しのsettlementのための2つの欄があります。
| 欄 | 中身 | 設定できる時 |
|---|---|---|
extraTransferLegSides |
settlementの一部としてsettleする、追加のtransfer legの側 | allocationのauthorizerが、繰り返しのsettlementを有効にしている時だけ |
nextIterationFunding |
この回の後に、次のsettlementの回のために取り置く資金として渡す値。Noneは、この回の後にもう回が無い事を表す |
同上 |
この欄は、AllocationSpecificationの同名の欄とは別の値です。
AllocationSpecificationの欄は、元のallocationで繰り返しのsettlementを有効にしたかと、取り置いた資金を表し、次の節の後で見ます。
実装は、V2のAllocationに、Archiveのchoiceと、3つのchoiceの中身を与えるallocation_cancelImplとallocation_settleImplとallocation_withdrawImplのmethod、各choiceの追加のobserverを返す3つの*ExtraObserversのmethodを持たせます。
AllocationActionは、allocationに対して取れる操作で、4つの形を持ちます。
| 形 | 表す物 |
|---|---|
AA_Settle |
settle |
AA_Cancel |
取り消し |
AA_Withdraw |
引き出し |
AA_Custom |
名前空間を付けたIDで表す、registryごとの操作 |
束を正味でsettleする
SettlementFactoryのinterfaceは、同じinstrumentのadminのallocationの束を、正味でsettleできるようにします。
SettlementFactory_SettleBatchのchoiceは、同じinstrumentのadminを持つinstrumentのallocationの束をsettleします。
controllerはactorsで、SettlementFactory_SettleBatchResultを返します。
この形なのは、効率とプライバシーのためです。 instrumentのadminがsettleする全てのtransferをまたいで、accountごとの正味の引き落としと入金だけを行えます。 また、各入金と引き落としが見える範囲を、executorとadminと、影響を受けるaccountのpartyだけに制限できます。
SettlementFactoryは、Archiveのchoiceと、actorsがcontrollerでSettlementFactoryViewを返すSettlementFactory_PublicFetchと、SettlementFactory_SettleBatchを持ちます。
methodは、settlementFactory_publicFetchImplとsettlementFactory_settleBatchExtraObserversとsettlementFactory_settleBatchImplを持ちます。
次の図は、executorがallocationの束を、factoryでsettleして、正味の入金と引き落としが行われるまでを、正味で動かす場合の例として追います。
個々のallocationはauthorizer側の承認で、渡すallocationsの一覧全体が、送り手と受け手の両方の承認の証明になります。
allocationごとの承認の確かめ方は、実装が決めます。
正味の入金と引き落としの段は、factoryの段として置きます。
- executorが束を確定させる
executorは、settlementのために確定させたallocationの束を、factoryのchoiceに渡します。
束の中のtransfer legは、少なくとも1つ要り、全てfactoryと同じinstrumentのadminを持ちます。 - 承認を確かめる
個々のallocationは、authorizer側の承認です。
渡された一覧全体が、送り手と受け手の両方が、settlementの一部として行う全てのtransferを承認した証明になります。
holderが作ったallocationをsettleする時にadminが何を確かめるかは、choiceの実装が決めます。 - 正味で動かす
この例では、instrumentのadminがsettleする全てのtransferをまたいで、accountごとの正味の引き落としと入金だけを行います。
この形は、各入金と引き落としが見える範囲を、executorとadminと、影響を受けるaccountのpartyだけに制限できる設計です。 - 結果が束の順に返る
結果は、束の中の各allocationをsettleした結果を、choiceの引数と同じ順で持ちます。
次の表は、SettlementFactory_SettleBatchの欄と、関わる型を並べます。
| 項目 | 中身 |
|---|---|
settlement |
settlement |
transferLegs |
少なくとも1つ要り、全てのtransfer legが、factoryと同じinstrumentのadminを持つ。この全てのlegをまたいで、accountごとの正味を求める |
allocations |
FinalizedAllocationのlist。個々のallocationはauthorizer側の承認で、一覧全体が、settlementの一部として行う全てのtransferを、送り手と受け手の両方が承認した証明 |
actors |
実装ごとの承認の形に、既定でないcontrollerを設定できる。実装は、許されない実行を防ぐため、これを確かめる決まりで、既定では、アプリとの互換を最大にするため、settlement.executorsに等しい事を確かめるべき |
extraArgs |
追加の引数 |
FinalizedAllocation |
executorがsettlementのために確定させたallocation。欄はallocationCidとextraTransferLegSidesとnextIterationFunding。extraTransferLegSidesは、authorizerが繰り返しのsettlementを有効にしていない限り空にする決まりで、nextIterationFundingも、有効にしていない限り設定しない |
SettlementFactoryView |
このSettlementFactoryを使えるinstrumentを管理するregistryのアプリを表すadminと、拡張のためのmeta |
SettlementFactory_SettleBatchResult |
束の中の各allocationをsettleした結果allocationSettleResultsを、choiceの引数のallocationsと同じ順で持つ。metaも持つ |
allocationの指定と繰り返しのsettlement
V2のAllocationSpecificationは、settlementの一部として、資産を受け取るか送る事への、authorizerの承認です。
欄は、次の7つです。
| 欄 | 中身 |
|---|---|
admin |
settlementで移すinstrumentの資産のadmin |
authorizer |
settlementのtransferを承認するAccount |
transferLegSides |
承認するlegの側 |
settlementDeadline |
executorとauthorizerが合意した、allocationの有効期限 |
nextIterationFunding |
次のsettlementの回の資金として取り置く量 |
committed |
authorizerがallocationに責任を持つかを表す |
meta |
繰り返しのsettlementで使うallocationの情報を蓄える、追加のデータ |
settlementDeadlineを設定した時は、この時刻の後にallocationをsettleできず、authorizerは、allocationを引き出して資金を放せます。
committedは、executorがallocationをsettleするか、executorが取り消すか、settlementの締め切りが過ぎるか、adminが期限を切るまで、authorizerがallocationに責任を持つかを表します。
Trueなら、authorizerは、settlementの締め切りまで、allocationを引き出せません。
executorが、settlementまでallocationがある事の保証を要する場合に、committedのallocationを使います。
AllocationSpecificationのnextIterationFundingは、次のsettlementの回の資金として取り置く量で、instrumentのIDをkeyにし、量は必ず正にします。
この欄は、元のallocationで繰り返しのsettlementを有効にしたかを表し、Allocation_SettleやFinalizedAllocationに渡す、同名の欄とは別の値です。
次の図は、AllocationSpecificationのnextIterationFundingの3つの値が、繰り返しのsettlementをどう変えるかを追います。
- 値で繰り返しが変わる
allocationの指定の次の回の資金は、繰り返しのsettlementを使うか、次の回の資金を取り置くかを決めます。
- 値が無い
値が無い時は、繰り返しのsettlementは無効で、allocationは、指定したtransfer legで、ちょうど1回だけsettleできます。
- 空のmap
空のmapなら、繰り返しのsettlementは有効ですが、authorizerは次の回の資金を取り置きません。
次の回に入ってくるtransferを見込むauthorizerが使えます。 - 量を入れる
量を入れた時は、その量を、instrumentのIDをkeyにして、次の回の資金として取り置きます。
量は必ず正にします。
結果とviewの欄
AllocationResultは、allocationのchoiceの結果で、outputと、settlementでauthorizerに作った新しいholdingをinstrumentのIDをkeyに持つauthorizerHoldingCidsと、metaを持ちます。
AllocationResult_Outputは、4つの形を持ちます。
| 形 | 伝える事 |
|---|---|
AllocationResult_Pending |
allocationが、さらに段を待つ事。処理が続く、今のallocationのコントラクトIDをallocationCidで伝える |
AllocationResult_Settled |
Allocation_Settleでsettleした結果。settleが終わった後に、次のsettlementの回のために作った新しいallocationがあれば、そのコントラクトIDをnextIterationAllocationCidに持つ |
AllocationResult_Cancelled |
Allocation_Cancelが十分に承認された時の結果 |
AllocationResult_Withdrawn |
Allocation_Withdrawが十分に承認された時の結果 |
V2のAllocationViewは、settleできる状態のallocationのviewです。
| 欄 | 中身 |
|---|---|
originalAllocationCid |
元のallocationのコントラクトID。元のallocation自身ではNoneになる。walletは、状態の更新をまたいで同じallocationを結び付けるのに使うべきです。同じsettlementの別のallocationを結び付ける時は、view直下のsettlementを使います |
settlement |
settlement |
allocation |
allocationの指定 |
holdingCids |
allocationを裏付けるholding。walletがallocationとholdingを結び付けるために示し、holdingを台帳の上に表さないregistryでは、空でもかまわない |
createdAt |
allocationを最初に作った時刻 |
numIterations |
これまでに、このallocationで行ったsettlementの回の数 |
expiresAt |
Optional Timeで、省略できる。時刻が指定された場合は、動きの無いallocationが期限を迎える時刻 |
availableActions |
操作を、どのpartyの組が行えるかを、集合の集合で表す |
meta |
拡張のための追加のデータ |
expiresAtが指定されている時、その後に、registryは、allocationの期限を切り、固めた資金をauthorizerに返してもかまいません。
期限を切ると、使われていないallocationが占有する保存領域を回収できます。
また、denial-of-serviceの攻撃から身を守れます。
denial-of-serviceの攻撃は、正規の利用者によるサービスの利用を妨げる攻撃です。
registryは、期限をsettlementの締め切りにできるだけ近づける事と、settlementの回ごとに期限を延ばす事で、要らない更新を避けるべきです。
availableActionsは、walletの利用者に、操作を取れるかと、誰を待つかを知らせます。
共同の承認を要する操作には、registryごとの委任のコントラクトが要ります。
settlementとlegの型
V2のSettlementInfoは、settlementを一意に指す参照で、walletが、同じsettlementへのallocationを結び付けるのに使えます。
executorは、(id, cid, meta)の3つの組が、settlementをまたいで一意である事を保証する決まりです。
| 型 | 欄 | 中身 |
|---|---|---|
SettlementInfo |
executors、id、cid、meta |
executorsは、settlementを実行して、資産のadminをまたぐatomicなsettlementを保証するparty。idは文字列の識別子、cidはOptional AnyContractId |
TransferLeg |
transferLegId、sender、receiver、amount、instrumentId、meta |
senderとreceiverはAccount。instrumentIdは、instrumentのadminが使う識別子で、Text |
TransferLegSide |
transferLegId、side、otherside、amount、instrumentId、meta |
transfer legの片側で、allocationが承認するのはこの片側。sideはTransferSideで、othersideは相手の側のaccountで、ReceiverSideなら送り手、SenderSideなら受け手 |
TransferSide |
SenderSide、ReceiverSide |
資産を送る外向きの側と、資産を受け取る内向きの側の2つの形 |