Skip to content

Commit

Permalink
update deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
peterli-r3 committed May 1, 2024
1 parent cdba445 commit 7b78bb8
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberX500Name>,
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class IOUIssueFlow : ClientStartableFlow {

@Suspendable
fun getSanctionsList(sanctionsBody: MemberX500Name): StateAndRef<SanctionList>? {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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{
Expand Down

0 comments on commit 7b78bb8

Please sign in to comment.