我有两个聚会(A和B)。A使用SignTransactionFlow,将Corda国家发送给B,因此也可以获得交易对手方的签名。
如果不使用sendAndReceive调用,而不使用SignTransactionFlow,那么共享Corda状态是否可能呢?如果是这样的话,通过sendAndReceive接收Corda国家的对手方是否能够消费该状态?
发布于 2021-12-17 23:20:58
是的,可以使用send()和receive()发送状态。下面是我测试过的代码示例,以确定它是否有效:
class TestContract : Contract{
companion object{
@JvmStatic
val ID = "package net.corda.sample.TestContract"
}
override fun verify(tx: LedgerTransaction) {
}
}
@BelongsToContract(TestContract::class)
class TestState(val owner : Party, val value : String) : ContractState {
override val participants: List<AbstractParty>
get() = listOf(owner)
}
@InitiatingFlow
@StartableByRPC
class receiveStateFlow(private val counterparty: Party) : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
val log = loggerFor<receiveStateFlow>()
@Suspendable
override fun call() {
val counterpartySession = initiateFlow(counterparty)
val counterpartyData = counterpartySession.sendAndReceive<TestState>("hello")
counterpartyData.unwrap { msg ->
log.warn(msg.value)
assert((msg.participants.first()) == counterparty)
}
}
}
@InitiatedBy(receiveStateFlow::class)
class sendStateFlow(private val counterpartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val counterpartyData = counterpartySession.receive<String>()
counterpartyData.unwrap { msg ->
assert(msg == "hello")
}
val newState = TestState(serviceHub.myInfo.legalIdentities.first(), "someValue")
counterpartySession.send(newState)
}
}但是,此方法不会消耗任何状态。只有当您将这些状态用作Transaction的输出时,才会发生这种情况。因此,接收州的一方应该在相同的流程中使用这些确切的状态作为TransactionBuilder中的输出,并继续签署和完成事务。
https://stackoverflow.com/questions/70303006
复制相似问题