Skip to content

Commit

Permalink
ES-1992: Replace deprecated methods with recommended usage (#75)
Browse files Browse the repository at this point in the history
CorDapps code includes Corda API methods which were marked as terminally deprecated since 5.0 GA.
When building CPIs, it results in Deprecated warnings in the IDE console.
This change fixes the warnings by using the recommended methods.
Flows were manually tested following the "Running the Chat CorDapp" from Corda 5 documentation.
  • Loading branch information
anton-subbotin authored Mar 1, 2024
1 parent e96ba09 commit d94576d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String call(@NotNull ClientRequestBody requestBody) {
StateAndRef<AppleStamp> appleStampStateAndRef;
try {
appleStampStateAndRef = utxoLedgerService
.findUnconsumedStatesByType(AppleStamp.class)
.findUnconsumedStatesByExactType(AppleStamp.class, 100, Instant.now()).getResults()
.stream()
.filter(stateAndRef -> stateAndRef.getState().getContractState().getId().equals(stampId))
.iterator()
Expand All @@ -90,7 +90,7 @@ public String call(@NotNull ClientRequestBody requestBody) {
StateAndRef<BasketOfApples> basketOfApplesStampStateAndRef;
try {
basketOfApplesStampStateAndRef = utxoLedgerService
.findUnconsumedStatesByType(BasketOfApples.class)
.findUnconsumedStatesByExactType(BasketOfApples.class, 100, Instant.now()).getResults()
.stream()
.filter(
stateAndRef -> stateAndRef.getState().getContractState().getOwner().equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.util.*;
import static java.util.Objects.*;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -41,7 +42,7 @@ public String call(ClientRequestBody requestBody) {
// Note, this code brings all unconsumed states back, then filters them.
// This is an inefficient way to perform this operation when there are a large number of chats.
// Note, you will get this error if you input an id which has no corresponding ChatState (common error).
List<StateAndRef<ChatState>> chatStateAndRefs = ledgerService.findUnconsumedStatesByType(ChatState.class);
List<StateAndRef<ChatState>> chatStateAndRefs = ledgerService.findUnconsumedStatesByExactType(ChatState.class, 100, Instant.now()).getResults();
List<StateAndRef<ChatState>> chatStateAndRefsWithId = chatStateAndRefs.stream()
.filter(sar -> sar.getState().getContractState().getId().equals(flowArgs.getId())).collect(toList());
if (chatStateAndRefsWithId.size() != 1) throw new CordaRuntimeException("Multiple or zero Chat states with id " + flowArgs.getId() + " found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -33,7 +34,7 @@ public String call(ClientRequestBody requestBody) {
log.info("ListChatsFlow.call() called");

// Queries the VNode's vault for unconsumed states and converts the result to a serializable DTO.
List<StateAndRef<ChatState>> states = utxoLedgerService.findUnconsumedStatesByType(ChatState.class);
List<StateAndRef<ChatState>> states = utxoLedgerService.findUnconsumedStatesByExactType(ChatState.class, 100, Instant.now()).getResults();
List<ChatStateResults> results = states.stream().map( stateAndRef ->
new ChatStateResults(
stateAndRef.getState().getContractState().getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String call(ClientRequestBody requestBody) {
// Note, this code brings all unconsumed states back, then filters them.
// This is an inefficient way to perform this operation when there are a large number of chats.
// Note, you will get this error if you input an id which has no corresponding ChatState (common error).
List<StateAndRef<ChatState>> chatStateAndRefs = ledgerService.findUnconsumedStatesByType(ChatState.class);
List<StateAndRef<ChatState>> chatStateAndRefs = ledgerService.findUnconsumedStatesByExactType(ChatState.class, 100, Instant.now()).getResults();
List<StateAndRef<ChatState>> chatStateAndRefsWithId = chatStateAndRefs.stream()
.filter(sar -> sar.getState().getContractState().getId().equals(flowArgs.getId())).collect(toList());
if (chatStateAndRefsWithId.size() != 1) throw new CordaRuntimeException("Multiple or zero Chat states with id " + flowArgs.getId() + " found");
Expand Down

0 comments on commit d94576d

Please sign in to comment.