这里有一个示例:https://github.com/corda/blacklist。
首先,我使用以下命令运行节点 1. gradlew deployNodes 2.通过运行runnodes启动节点 3. gradlew uploadBlacklist
现在需要做什么?我们如何查看上传和下载的文件。如果我在浏览器中打开localhost:10006,则不会显示任何内容。
如何在其他项目中重用该代码?
答案 0 :(得分:0)
在建立交易时引用了附件:
val txBuilder = TransactionBuilder(notary)
.addOutputState(agreementState, AGREEMENT_CONTRACT_ID)
.addCommand(agreeCmd, agreeCmdRequiredSigners)
.addAttachment(untrustedPartiesAttachment)
一旦将其添加到交易中,便可以在合同中引用它:
val attachmentJar = attachment.openAsJAR()
while (attachmentJar.nextEntry.name != "blacklist.txt") {
// Calling `attachmentJar.nextEntry` causes us to scroll through the JAR.
}
val blacklistedCompanies = mutableListOf<String>()
val bufferedReader = attachmentJar.bufferedReader()
var company = bufferedReader.readLine()
while (company != null) {
blacklistedCompanies.add(company)
company = bufferedReader.readLine()
}
您还可以扩展客户端以通过RPC下载附件。请参见downloadAttachment
方法。