对于节点记录的状态,我有一个StateRef
。自StateRef
被记录以来,如何获得节点记录的所有状态的流?
答案 0 :(得分:1)
您需要做两件事:
StateRef
的时间这是一个可以执行此操作的示例RPC客户端:
fun main(args: Array<String>) {
// Getting an RPC connection to the node.
require(args.size == 1) { "Usage: ExampleClientRPC <node address>" }
val nodeAddress = NetworkHostAndPort.parse(args[0])
val client = CordaRPCClient(nodeAddress)
val rpcOps = client.start("user1", "test").proxy
// Change this to an actual StateRef.
val dummyStateRef = StateRef(SecureHash.zeroHash, 0)
// Getting the time the state was recorded.
val queryByStateRefCriteria = VaultQueryCriteria(stateRefs = listOf(dummyStateRef))
val queryByStateRefResults = rpcOps.vaultQueryBy<ContractState>(queryByStateRefCriteria)
val queryByStateRefMetadata = queryByStateRefResults.statesMetadata
val dummyStateRefRecordedTime = queryByStateRefMetadata.single().recordedTime
// Getting the states recorded after that time.
val queryAfterTimeExpression = TimeCondition(
RECORDED, BinaryComparison(BinaryComparisonOperator.GREATER_THAN_OR_EQUAL, dummyStateRefRecordedTime))
val queryAfterTimeCriteria = VaultQueryCriteria(
status = ALL,
timeCondition = queryAfterTimeExpression)
val queryAfterTimeResults = rpcOps.vaultTrackBy<ContractState>(queryAfterTimeCriteria)
val afterTimeStates = queryAfterTimeResults.states
}