Getting CONTRACT_NOT_FOUND error when trying to submit "Archive" choice on a found contract

Hi there,

After reaching to a point in the code where i managed to find a given contract, when trying to submit an “Archive” choice i get the below exception:

Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: CONTRACT_NOT_FOUND(11,0825c84e): Contract could not be found with id 0054ff9fd1c537ece135de287c8fa14ff169ec9d6e16796ff7fe40562b6fb5d441

I know for certain that i managed to find this contract since i printed its package’s details and also debugged it.

Description of The flow:

processTransaction gets as a parameter the Transaction object from the Observer (Flowable client) and for each of its contained events we call processEvent which returns List of Commands (exerciseCommands var) that we try to submit but we fail

private void processTransaction(Transaction tx) {

        List<Event> exerciseEvents = tx.getEvents();

        List<Command> exerciseCommands =
        exerciseEvents.stream()
            .filter(e -> e instanceof CreatedEvent)
            .map(e -> (CreatedEvent) e)
            .flatMap(e -> processEvent(tx.getWorkflowId(), e))
            .collect(Collectors.toList());

        if (!exerciseCommands.isEmpty()) {
            client.getCommandClient().submitAndWait(     // <--- This line throws the Exception
                    tx.getWorkflowId(), APPLICATION_ID, UUID.randomUUID().toString(), tpaPartyId, exerciseCommands)
                    .blockingGet();
        }
    }

private Stream<Command> processEvent(String workflowId, CreatedEvent event) {
        Identifier template = event.getTemplateId();

        boolean isPolicyPagesNotification = template.equals(policyPagesNotificationIdentifier);

        if (!isPolicyPagesNotification) {
            return Stream.empty();
        }
        else {
            System.out.println("Found module " + policyPagesNotificationIdentifier.toString() + " !!");
            PolicyPagesNotification.Contract contract = PolicyPagesNotification.Contract.fromCreatedEvent(event);

            // assemble the Archive command
            Command cmd = new ExerciseCommand(
                    template,
                    event.getContractId(),
                    "Archive",
                    new DamlRecord(Collections.emptyList()));

            return Stream.of(cmd);
        }
    }

It sounds like the contract got archived after the transaction where you see the create. Maybe remove the exercise and go through all transactions and see if you can find a corresponding archive of this contract id in a later transaction.

Thanks @cocreature
Is there a way to view archived contracts in the duml hub Ledger?

Not in the UI I believe but you can view historical transactions via the gRPC API (like you’re already doing) to see everything that happened including contracts that have already been archived since.