Corda交易时间从保管库查询中获取

时间:2018-10-01 15:32:06

标签: corda

是否可以通过Vault查询在vault_state中看到事务消耗的时间?

1 个答案:

答案 0 :(得分:0)

是的。您可以使用查询结果的statesMetadata字段来找到消耗状态的时间。

在流程中:

@Suspendable
override fun call() {
    val results = serviceHub.vaultService.queryBy(ContractState::class.java)
    val statesAndMetadata = results.states.zip(results.statesMetadata)
    statesAndMetadata.forEach { (stateAndRef, metadata) ->
        val consumedTime = metadata.consumedTime
    }
}

在RPC客户端中:

fun main(args: Array<String>) {
    require(args.size == 1) { "Usage: TemplateClient <node address>" }
    val nodeAddress = parse(args[0])
    val client = CordaRPCClient(nodeAddress)

    // Can be amended in the com.template.MainKt file.
    val cordaRPCOps = client.start("user1", "test").proxy

    val results = cordaRPCOps.vaultQueryBy<ContractState>()
    val statesAndMetadata = results.states.zip(results.statesMetadata)
    statesAndMetadata.forEach { (stateAndRef, metadata) ->
        val consumedTime = metadata.consumedTime
    }
}