在Corda,我如何监控保险库中的状态的破坏和创建?

时间:2018-03-15 10:18:28

标签: corda

我已经实现了此处描述的用户互动流程:Corda: User interaction for verifying the transaction request received from the initiator node

作为提议者,我如何检查交易是被接受还是被拒绝?

1 个答案:

答案 0 :(得分:0)

您可以使用RPC客户端,例如:

fun main(args: Array<String>) {
    val nodeAddress = parse(args[0])
    val client = CordaRPCClient(nodeAddress)
    val proxy = client.start("user1", "test").proxy

    // Observe FooState updates from the vault.
    val (_, updates) = proxy.vaultTrack(FooState::class.java)

    // Check each update.
    updates.toBlocking().subscribe { update ->

        // If the update produced a state with the `accepted` flag, the proposal was accepted.
        if (update.produced.size == 1 && update.produced.single().state.data.accepted) {
            logger.info("Proposal was accepted.")

        // If the update didn't produce a state, the proposal was rejected.
        } else if (update.produced.isEmpty()) {
            logger.info("Proposal was rejected.")
        }
    }
}