在Corda中,如何查询库中特定时间后记录的所有状态?

时间:2018-10-02 12:45:19

标签: corda

我想检索时间x之后我的节点记录的所有状态。自那时以来,如何获得我的节点记录的所有状态的流?

1 个答案:

答案 0 :(得分:0)

这是一个示例RPC客户端,它在时间x之后流回该节点存储的所有状态:

fun main(args: Array<String>) {
    // Getting an RPC connection to the node.
    require(args.size == 2) { "Usage: ExampleClientRPC <node address> <time>" }
    val nodeAddress = NetworkHostAndPort.parse(args[0])
    val client = CordaRPCClient(nodeAddress)
    val rpcOps = client.start("user1", "test").proxy

    val startTime = Instant.parse(args[2])

    val queryAfterTimeExpression = TimeCondition(
            RECORDED, BinaryComparison(GREATER_THAN_OR_EQUAL, startTime))
    val queryAfterTimeCriteria = VaultQueryCriteria(
            status = Vault.StateStatus.ALL,
            timeCondition = queryAfterTimeExpression)
    val queryAfterTimeResults = rpcOps.vaultTrackBy<ContractState>(queryAfterTimeCriteria)
    val afterTimeStates = queryAfterTimeResults.updates
}