diff --git a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetAssetFlow.kt b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetAssetFlow.kt index 5b9733a..ec2e528 100644 --- a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetAssetFlow.kt +++ b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetAssetFlow.kt @@ -9,6 +9,7 @@ import net.corda.v5.base.annotations.Suspendable import net.corda.v5.base.types.MemberX500Name import net.corda.v5.ledger.utxo.UtxoLedgerService import org.slf4j.LoggerFactory +import java.time.Instant data class AssetDetail( val owner: MemberX500Name, @@ -36,7 +37,7 @@ class GetAssetFlow : ClientStartableFlow { log.info("GetAssetFlow.call() called") // Queries the VNode's vault for unconsumed states and converts the result to a serializable DTO. - val states = ledgerService.findUnconsumedStatesByType(Asset::class.java) + val states = ledgerService.findUnconsumedStatesByExactType(Asset::class.java, 100, Instant.now()).results val results = states.map {it -> AssetDetail( it.state.contractState.owner.name, diff --git a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetLoanFlow.kt b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetLoanFlow.kt index d15b699..741df80 100644 --- a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetLoanFlow.kt +++ b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/GetLoanFlow.kt @@ -9,6 +9,7 @@ import net.corda.v5.base.annotations.Suspendable import net.corda.v5.base.types.MemberX500Name import net.corda.v5.ledger.utxo.UtxoLedgerService import org.slf4j.LoggerFactory +import java.time.Instant data class LoanDetail(val loanId:String, val lender: MemberX500Name, @@ -36,7 +37,7 @@ class GetLoanFlow : ClientStartableFlow { log.info("GetLoanFlow.call() called") // Queries the VNode's vault for unconsumed states and converts the result to a serializable DTO. - val states = ledgerService.findUnconsumedStatesByType(Loan::class.java) + val states = ledgerService.findUnconsumedStatesByExactType(Loan::class.java, 100, Instant.now()).results val results = states.map {it -> LoanDetail( it.state.contractState.loanId, diff --git a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/RequestLoanFlow.kt b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/RequestLoanFlow.kt index 316ae7f..2b9d69b 100644 --- a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/RequestLoanFlow.kt +++ b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/RequestLoanFlow.kt @@ -54,7 +54,7 @@ class RequestLoanFlow : ClientStartableFlow { val otherMember = memberLookup.lookup(MemberX500Name.parse(lenderArgs)) ?: throw CordaRuntimeException("MemberLookup can't find otherMember specified in flow arguments.") val lender = Member(otherMember.name,otherMember.ledgerKeys[0]) - val stateAndRef = ledgerService.findUnconsumedStatesByType(Asset::class.java).singleOrNull { + val stateAndRef = ledgerService.findUnconsumedStatesByExactType(Asset::class.java, 100, Instant.now()).results.singleOrNull { it.state.contractState.assetId == collateral } ?: throw CordaRuntimeException("Multiple or zero Asset states with id ${collateral} found.") diff --git a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/SettleLoanFlow.kt b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/SettleLoanFlow.kt index c6778cc..9634369 100644 --- a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/SettleLoanFlow.kt +++ b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/SettleLoanFlow.kt @@ -45,13 +45,13 @@ class SettleLoanFlow: ClientStartableFlow { try { val (loanId) = requestBody.getRequestBodyAs(jsonMarshallingService, SettleLoanFlowArgs::class.java) - val loanStateAndRef = ledgerService.findUnconsumedStatesByType(Loan::class.java).singleOrNull { + val loanStateAndRef = ledgerService.findUnconsumedStatesByExactType(Loan::class.java, 100, Instant.now()).results.singleOrNull { it.state.contractState.loanId == loanId } ?: throw CordaRuntimeException("Multiple or zero Loan states with id ${loanId} found.") val loan = loanStateAndRef.state.contractState - val assetStateAndRef = ledgerService.findUnconsumedStatesByType(Asset::class.java).singleOrNull { + val assetStateAndRef = ledgerService.findUnconsumedStatesByExactType(Asset::class.java, 100, Instant.now()).results.singleOrNull { it.state.contractState.assetId == loan.collateral } ?: throw CordaRuntimeException("Multiple or zero Asset states with id ${loan.collateral} found.") diff --git a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/TransferAssetFlow.kt b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/TransferAssetFlow.kt index 944a572..ffbb35a 100644 --- a/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/TransferAssetFlow.kt +++ b/kotlin-samples/encumbrance-pawn-shop/workflows/src/main/kotlin/com/r3/developers/samples/encumbrance/workflows/TransferAssetFlow.kt @@ -47,7 +47,7 @@ class TransferAssetFlow: ClientStartableFlow { val otherMember = memberLookup.lookup(MemberX500Name.parse(flowArgs.buyer)) ?: throw CordaRuntimeException("MemberLookup can't find otherMember specified in flow arguments.") val buyer = Member(otherMember.name,otherMember.ledgerKeys[0]) - val stateAndRef = ledgerService.findUnconsumedStatesByType(Asset::class.java).singleOrNull { + val stateAndRef = ledgerService.findUnconsumedStatesByExactType(Asset::class.java, 100, Instant.now()).results.singleOrNull { it.state.contractState.assetId == flowArgs.assetId } ?: throw CordaRuntimeException("Multiple or zero Asset states with id ${flowArgs.assetId} found.") diff --git a/kotlin-samples/persistence-carinsurance/workflows/src/main/kotlin/com/r3/developers/samples/persistence/workflows/InsuranceClaim.kt b/kotlin-samples/persistence-carinsurance/workflows/src/main/kotlin/com/r3/developers/samples/persistence/workflows/InsuranceClaim.kt index 4a51d0c..0cac151 100644 --- a/kotlin-samples/persistence-carinsurance/workflows/src/main/kotlin/com/r3/developers/samples/persistence/workflows/InsuranceClaim.kt +++ b/kotlin-samples/persistence-carinsurance/workflows/src/main/kotlin/com/r3/developers/samples/persistence/workflows/InsuranceClaim.kt @@ -60,7 +60,7 @@ class InsuranceClaimFlow : ClientStartableFlow { // to fetch the desired Insurance state from the vault. This filtered state would be used as input to the // transaction. val filteredInsuranceStateAndRefs = - ledgerService.findUnconsumedStatesByType(InsuranceState::class.java).filter { + ledgerService.findUnconsumedStatesByExactType(InsuranceState::class.java, 100, Instant.now()).results.filter { it.state.contractState.policyNumber.equals(flowArgs.policyNumber) } diff --git a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetIOUFlow.kt b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetIOUFlow.kt index f0fcffd..c313e43 100644 --- a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetIOUFlow.kt +++ b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetIOUFlow.kt @@ -1,5 +1,6 @@ package com.r3.developers.samples.referencestate.workflows +import com.r3.developers.samples.referencestate.states.SanctionList import com.r3.developers.samples.referencestate.states.SanctionableIOUState import net.corda.v5.application.flows.ClientRequestBody import net.corda.v5.application.flows.ClientStartableFlow @@ -9,6 +10,7 @@ import net.corda.v5.base.annotations.Suspendable import net.corda.v5.base.types.MemberX500Name import net.corda.v5.ledger.utxo.UtxoLedgerService import org.slf4j.LoggerFactory +import java.time.Instant import java.util.* data class IOU(val value: Int, @@ -34,7 +36,7 @@ class GetIOUFlow : ClientStartableFlow { log.info("GetIOUFlow.call() called") // Queries the VNode's vault for unconsumed states and converts the result to a serializable DTO. - val states = ledgerService.findUnconsumedStatesByType(SanctionableIOUState::class.java) + val states = ledgerService.findUnconsumedStatesByExactType(SanctionableIOUState::class.java, 100, Instant.now()).results val results = states.map {it -> IOU( it.state.contractState.value, diff --git a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetSanctionListFlow.kt b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetSanctionListFlow.kt index 5fa3428..fc71d34 100644 --- a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetSanctionListFlow.kt +++ b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/GetSanctionListFlow.kt @@ -9,6 +9,7 @@ import net.corda.v5.base.annotations.Suspendable import net.corda.v5.base.types.MemberX500Name import net.corda.v5.ledger.utxo.UtxoLedgerService import org.slf4j.LoggerFactory +import java.time.Instant import java.util.* data class SanctionListDetail(val badPeople:List, @@ -33,7 +34,7 @@ class GetSanctionListFlow : ClientStartableFlow { log.info("GetSanctionListFlow.call() called") // Queries the VNode's vault for unconsumed states and converts the result to a serializable DTO. - val states = ledgerService.findUnconsumedStatesByType(SanctionList::class.java) + val states = ledgerService.findUnconsumedStatesByExactType(SanctionList::class.java, 100, Instant.now()).results val results = states.map {it -> SanctionListDetail( it.state.contractState.badPeople.map { it.name }.toList(), diff --git a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/IOUIssueFlow.kt b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/IOUIssueFlow.kt index b92eab5..819ae73 100644 --- a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/IOUIssueFlow.kt +++ b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/IOUIssueFlow.kt @@ -81,7 +81,7 @@ class IOUIssueFlow : ClientStartableFlow { @Suspendable fun getSanctionsList(sanctionsBody: MemberX500Name): StateAndRef? { - val sanctionLists = ledgerService.findUnconsumedStatesByType(SanctionList::class.java).stream().filter { it -> + val sanctionLists = ledgerService.findUnconsumedStatesByExactType(SanctionList::class.java, 100, Instant.now()).results.stream().filter { it -> it.state.contractState.issuer.name.equals(sanctionsBody) }.toList()[0] return sanctionLists diff --git a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/UpdateSanctionListFlow.kt b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/UpdateSanctionListFlow.kt index 35240d7..18745cd 100644 --- a/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/UpdateSanctionListFlow.kt +++ b/kotlin-samples/referencestates-sanctionsbody/workflows/src/main/kotlin/com/r3/developers/samples/referencestate/workflows/UpdateSanctionListFlow.kt @@ -54,7 +54,7 @@ class UpdateSanctionListFlow : ClientStartableFlow { val partyToSanction = memberLookup.lookup(partyToSanctionName) ?: throw CordaRuntimeException("MemberLookup can't find partyToSanctionName specified in flow arguments.") val allParties = memberLookup.lookup().filter { it -> !it.name.commonName.equals("NotaryRep1") }.toList() - val oldSanctionListRef = ledgerService.findUnconsumedStatesByType(SanctionList::class.java).singleOrNull()?: throw CordaRuntimeException("Sanction List not found.") + val oldSanctionListRef = ledgerService.findUnconsumedStatesByExactType(SanctionList::class.java, 100, Instant.now()).results.singleOrNull()?: throw CordaRuntimeException("Sanction List not found.") val oldSanctionList =oldSanctionListRef.state.contractState val badPeople = ArrayList(oldSanctionList.badPeople) badPeople.add(Member(partyToSanctionName,partyToSanction.ledgerKeys[0])) diff --git a/kotlin-samples/shinny-tokens/workflows/src/main/kotlin/com/r3/developers/samples/tokens/workflows/ListGoldTokens.kt b/kotlin-samples/shinny-tokens/workflows/src/main/kotlin/com/r3/developers/samples/tokens/workflows/ListGoldTokens.kt index 9fc32e7..e9228a5 100644 --- a/kotlin-samples/shinny-tokens/workflows/src/main/kotlin/com/r3/developers/samples/tokens/workflows/ListGoldTokens.kt +++ b/kotlin-samples/shinny-tokens/workflows/src/main/kotlin/com/r3/developers/samples/tokens/workflows/ListGoldTokens.kt @@ -10,6 +10,7 @@ import net.corda.v5.crypto.SecureHash import net.corda.v5.ledger.utxo.UtxoLedgerService import org.slf4j.LoggerFactory import java.math.BigDecimal +import java.time.Instant import java.util.stream.Collectors // This flow is used to list all the gold tokens available in the vault. @@ -28,9 +29,7 @@ class ListGoldTokens: ClientStartableFlow { @Suspendable override fun call(requestBody: ClientRequestBody): String { - val states = utxoLedgerService.findUnconsumedStatesByType( - GoldState::class.java - ) + val states = utxoLedgerService.findUnconsumedStatesByExactType(GoldState::class.java, 100, Instant.now()).results // Queries the VNode's vault for unconsumed states and converts the result to a serializable DTO. val results = states.stream().map{