Corda:合同附件如何在交易中转移?

edw*_*ong 2 corda

使用附件页面状态:

附件是通过哈希从事务引用的ZIP / JAR文件,但不包含在事务本身中。

但是,“ API:合同约束”页面指出:

包含状态和合同类以及可选的依赖关系的JAR都附加到事务中。

这里有一个代码片段,显示了如何添加合同约束:

transaction.addOutputState(state, constraint = HashAttachmentConstraint(serviceHub.cordappProvider.getContractAttachmentID(CONTRACT_ID)!!))
Run Code Online (Sandbox Code Playgroud)

但是,在签出HashAttachment代码时,我看不到它包含Contract Jar文件的内部信息。

我的假设是我们不会随交易一起转移合约罐。发生的情况可以描述为:

  1. During Nodes start-up Corda scans all CorDapps and load jars that consists of Contract classes into local Attachment Storage.
  2. Each Output state in the Transaction can have a Contract Constraint.
  3. During the verification stage, verifyConstraints(contractAttachmentsByContract) will be invoked and those constraints (e.g. HashAttachmentConstraint) will be validated against attachments that Node has in its local storage.

Questions:

  1. Does Transaction include the Contract Attachment?
  2. Will that Contract Attachment be transferred over the network or attachments from the local attachment storage will be used for verification?
  3. What am I missing something in my assumption?

Aus*_*art 5

您是正确的,该附件不会在事务内转移。事务仅包含对附件的哈希引用,以用于数据引用。这也意味着附件可以在许多事务中重复使用,因为它们在自己的数据库表中脱链维护。

当节点收到包含附件的交易时,Corda会自动从交易对手那里获取附件:https : //docs.corda.net/tutorial-attachments.html#protocol

通常,交易的附件是通过自动获取的ReceiveTransactionFlow

只要附件小于网络参数的maxTransactionSize,就可以进行这种传输,而无需任何开发工作:https ://docs.corda.net/network-map.html#network-parameters

maxTransactionSize:事务的最大允许大小(以字节为单位)。这是事务对象及其附件的大小。

此时,合同附件通常由Cordapp开发人员预先分发和签名,并由Corda节点的所有者部署。此时,通常不以编程方式安装Cordapps。