首先,我已经阅读了Corda中有关使用附件的文档。但是,我仍然对上传和下载附件的过程有疑问。
我的任务是编写一个简单的cordapp,用于将文件从NodeA传输到NodeB。从NodeA shell上传zip文件后,我收到了一个哈希,然后将其包含在事务中。流程成功。但是,在NodeB中,我无法取回文件。然后,我尝试使用该哈希从NodeA取回文件。但是,shell返回了错误消息并显示了invalidInputSteam。
但是当我运行cordaftp(https://github.com/corda/cordaftp)并尝试上传文件并从同一shell下载该文件时,shell正确地询问了存储路径。我阅读了各种文章,并且知道我需要包括其他代码才能成功下载。但是我不知道应该修改哪个文件以及应该编写什么代码。我已经花了几天时间阅读以前的文章和文档,希望有人可以帮助我解决我的问题。
以下是流程部分:
@InitiatingFlow
@StartableByRPC
class FileInitiateFlow(
val receiver: Party,
val comment: String,
val hash: SecureHash.SHA256) : FlowLogic<SignedTransaction>() {
companion object {
object GENERATING_TRANSACTION : Step("Generating transaction")
object VERIFYING_TRANSACTION : Step("Verifying contract constraints.")
object SIGNING_TRANSACTION : Step("Signing transaction with sender private key.")
object GATHERING_SIGS : Step("Gathering the receiver's signature."){
override fun childProgressTracker() = CollectSignaturesFlow.tracker()
}
object FINALISING_TRANSACTION : Step("Obtaining notary signature and recording transaction.") {
override fun childProgressTracker() = FinalityFlow.tracker()
}
fun tracker() = ProgressTracker(
GENERATING_TRANSACTION,
VERIFYING_TRANSACTION,
SIGNING_TRANSACTION,
GATHERING_SIGS,
FINALISING_TRANSACTION
)
}
override val progressTracker = tracker()
@Suspendable
override fun call(): SignedTransaction {
// Obtain a reference to the notary we want to use.
val notary = serviceHub.networkMapCache.notaryIdentities[0]
val sender = serviceHub.myInfo.legalIdentities.first()
// Stage 1.
progressTracker.currentStep = GENERATING_TRANSACTION
// Generate an unsigned transaction.
val fileState = FileState(sender, receiver,comment)
val txCommand = Command(RoamingContract.Commands.FileInitiate(), fileState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary)
.addOutputState(fileState, ID)
.addCommand(txCommand)
.addAttachment(hash)
// Stage 2.
progressTracker.currentStep = VERIFYING_TRANSACTION
// Verify that the transaction is valid.
txBuilder.verify(serviceHub)
// Stage 3.
progressTracker.currentStep = SIGNING_TRANSACTION
// Sign the transaction.
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)
// Stage 4.
progressTracker.currentStep = GATHERING_SIGS
// Send the state to the counterparty, and receive it back with their signature.
val otherPartyFlow = initiateFlow(receiver)
val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(otherPartyFlow), GATHERING_SIGS.childProgressTracker()))
// Stage 5.
progressTracker.currentStep = FINALISING_TRANSACTION
// Notarise and record the transaction in both parties' vaults.
return subFlow(FinalityFlow(fullySignedTx, FINALISING_TRANSACTION.childProgressTracker()))
}
}
@InitiatedBy(FileInitiateFlow::class)
class FileInitiateRespond(val senderFlow: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction{
val signedTransactionFlow = object : SignTransactionFlow(senderFlow) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
val output = stx.tx.outputs.single().data
"This must be an File State" using (output is FileState)
}
}
return subFlow(signedTransactionFlow)
}
}
因此,我首先运行uploadAttachment来上传zip文件,我得到了哈希值,然后以哈希值作为输入开始了流程。该流程已成功完成,但是在接收方方面,我无法通过检查现有状态来获取上载文件的哈希键。
答案 0 :(得分:0)
SecureHash
实例的附件哈希。 Corda 3.2 / 3.3中存在一个错误,该错误使shell无法将字符串转换为SecureHash
对象。
此修复程序位于:https://github.com/corda/corda/pull/3248,将在Corda 4中提供。