问题
We have a use case which requires the following steps: (1) Initiator triggers the transaction flow through UI (2) The flow is initiated, signed by the initiator and sent to recipient for his verification and signatures (in Corda) (3) The initiator's flow should get suspended until the recipient validates the transaction by verifying the contract code and submits "verified" again through the UI (4) This should restart the initiator's flow and the remaining process should be followed as expected in Corda
It was mentioned a few weeks back that user interaction is not yet supported in Corda; is this feature still not present? In the future, we may even want to add the state's attributes through a UI since it gives us the flexibility to propose a transaction we want rather than have it hard-coded. Any idea if this could be possible in future releases?
回答1:
See the Negotiation Cordapp sample for an example of how this would work in practice here.
Suspending a flow for human interaction isn't currently implemented (as of Corda V3.0).
Instead, you'd implement this by adding a status flag to your state:
class FooState(
override val participants: List<Party>,
val accepted: Boolean) : ContractState
You'd have three commands:
interface Commands : CommandData {
class Propose : Commands
class Reject: Commands
class Accept: Commands
}
And two flows:
A proposal flow: In this flow, the initiator creates and signs a
Propose
transaction to issue the state onto the ledger with aPropose
command and theaccepted
flag set tofalse
An accept flow: In this flow, the recipient either:
- Creates a
Reject
transaction that consumes the proposed state and outputs nothing. The state has been removed from the ledger and is effectively rejected - Creates an
Accept
transaction that updates the proposed state so thataccepted
istrue
. The state has now been accepted, and this fact is registered on the ledger
- Creates a
You'd give the accept flow a parameter which determines whether or not to accept the proposal. This parameter would be provided by the user when the flow is kicked off either via an API or directly over RPC.
来源:https://stackoverflow.com/questions/45845262/corda-user-interaction-for-verifying-the-transaction-request-received-from-the