问题
I am using Corda 3.2. Given a SignedTransaction
, how can I establish when it was recorded?
回答1:
There is no direct API for determining when a transaction was recorded. However, you can achieve this by checking either:
When one of the transaction's inputs was consumed:
val inputStateRef = signedTx.inputs[0] val queryCriteria = QueryCriteria.VaultQueryCriteria(stateRefs = listOf(inputStateRef)) val results = serviceHub.vaultService.queryBy<ContractState>(queryCriteria) val consumedTime = results.statesMetadata.single().consumedTime!!
When one of the transaction's outputs was recorded:
val ledgerTx = signedTx.toLedgerTransaction(serviceHub) val outputStateRef = StateRef(signedTx.id, 0) val queryCriteria = QueryCriteria.VaultQueryCriteria(stateRefs = listOf(outputStateRef)) val results = serviceHub.vaultService.queryBy<ContractState>(queryCriteria) val recordedTime = results.statesMetadata.single().recordedTime
来源:https://stackoverflow.com/questions/51855450/in-corda-how-to-get-the-timestamp-of-when-a-transaction-happened