我已经实现了几个命令,其中公证签名可以满足用例的要求。尽管有2个问题,但我有未解决的问题:
我有一个从输入/输出状态更改的所有者字段,一切都很好,但是我希望新所有者在其上注销,例如我需要一种机制来通过保管库检索状态(最后未消费?),我想我需要对参与者进行身份验证和过滤,并让新所有者对其进行签名,例如“按下按钮”,我该怎么做?
如何确定线性状态,例如以后不能再参与任何形式的交易/命令了?
@InitiatingFlow
@StartableByRPC
class DeviceFlow(private val deviceState: DeviceState,
private val stateAndRef: Optional<StateAndRef<DeviceState>>,
private val command: DeviceContract.Commands)
: FlowLogic<SignedTransaction>() {
override val progressTracker = tracker()
companion object {
object GENERATING_TRANSACTION : Step("Generating transaction based on new IOU.")
object VERIFYING_TRANSACTION : Step("Verifying contract constraints.")
object SIGNING_TRANSACTION : Step("Signing transaction with our private key.")
object GATHERING_SIGS : Step("Gathering the counterparty'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
)
}
@Suspendable
override fun call(): SignedTransaction {
progressTracker.currentStep = GENERATING_TRANSACTION
val notary = serviceHub.networkMapCache.getNotary(CordaX500Name("Notary", "London", "GB"))
val transactionBuilder = TransactionBuilder(notary = notary)
.addCommand(command, deviceState.participants.map { it.owningKey })
.addOutputState(deviceState, DeviceContract.ID)
if (stateAndRef.isPresent)
transactionBuilder.addInputState(stateAndRef.get())
progressTracker.currentStep = VERIFYING_TRANSACTION
transactionBuilder.verify(serviceHub)
progressTracker.currentStep = SIGNING_TRANSACTION
val signedTransaction = serviceHub.signInitialTransaction(transactionBuilder)
val otherPartySession = initiateFlow(notary!!)
val fullySignedTx = subFlow(
CollectSignaturesFlow(signedTransaction, setOf(otherPartySession), GATHERING_SIGS.childProgressTracker()))
progressTracker.currentStep = FINALISING_TRANSACTION
return subFlow(FinalityFlow(fullySignedTx, setOf(otherPartySession), FINALISING_TRANSACTION.childProgressTracker()))
}
}
@InitiatedBy(DeviceFlow::class)
class DeviceCreateFlowResponder(val flowSession: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val signTransactionFlow = object : SignTransactionFlow(flowSession) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
val output = stx.tx.outputs.single().data
"This must be a Device transaction." using (output is DeviceState)
}
}
val txId = subFlow(signTransactionFlow).id
return subFlow(ReceiveFinalityFlow(flowSession, expectedTxId = txId))
}
}
答案 0 :(得分:0)
新所有者退出
最终确定线性(或任何状态)