0
votes

I have made a flow in Corda which shares a state with two other accounts each hosted on different nodes. While querying the vault of either participant using VaultQuery It is showing some ID in place of the name of the participant. The code of the call function of the flow is this.

public SignedTransaction call() throws FlowException {
    AccountService accountService = getServiceHub().cordaService(KeyManagementBackedAccountService.class);

    //Owner Account
    AccountInfo policyOwnerAccountInfo = accountService.accountInfo(policyOwner).get(0).getState().getData();
    PublicKey policyOwnerKey = subFlow(new NewKeyForAccount(policyOwnerAccountInfo.getIdentifier().getId())).getOwningKey();

    //Insurance Company Account
    AccountInfo insurerAccountInfo = accountService.accountInfo(insuranceCompany).get(0).getState().getData();
    AnonymousParty insuranceCompanyAccount = subFlow(new RequestKeyForAccount(insurerAccountInfo));

    //LSP account
    AccountInfo lspAccountInfo = accountService.accountInfo(lsp).get(0).getState().getData();
    AnonymousParty lspAccount = subFlow(new RequestKeyForAccount(lspAccountInfo));

    List<AccountInfo> parties = new ArrayList<>();
    parties.add(insurerAccountInfo);
    parties.add(lspAccountInfo);


    // Step 1. Get a reference to the notary service on our network and our key pair.
    // Note: ongoing work to support multiple notary identities is still in progress.
    final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);

//        UniqueIdentifier policyLinearId = new UniqueIdentifier(policyID);
    final PolicyState output = new PolicyState(new UniqueIdentifier(), policyID, sellerID, insurerID, policyNo, faceValue, deathBenefits, annualPremium, cashSurrenderValue, policyStartDate,new AnonymousParty(policyOwnerKey), false, Arrays.asList(insuranceCompanyAccount,lspAccount), true);

    progressTracker.setCurrentStep(GENERATING_TRANSACTION);
    final TransactionBuilder builder = new TransactionBuilder(notary);
    //Adding outputState to the transaction
    progressTracker.setCurrentStep(ADDING_POLICY);
    builder.addOutputState(output, PolicyContract.ID);
    builder.addCommand(new PolicyContract.Commands.Create(), Arrays.asList(policyOwnerKey,insuranceCompanyAccount.getOwningKey(),lspAccount.getOwningKey()));

//  self sign Transaction
    progressTracker.setCurrentStep(SIGNING_TRANSACTION);
    builder.verify(getServiceHub());
    SignedTransaction locallySignedTx = getServiceHub().signInitialTransaction(builder, Arrays.asList(getOurIdentity().getOwningKey(),policyOwnerKey));


    progressTracker.setCurrentStep(GATHERING_SIGS);
    FlowSession session = initiateFlow(insurerAccountInfo.getHost());
    List<TransactionSignature> accountToMoveToSignature = (List<TransactionSignature>) subFlow(new CollectSignatureFlow(locallySignedTx,
                    session,insuranceCompanyAccount.getOwningKey()));
    SignedTransaction signedByCounterParty = locallySignedTx.withAdditionalSignatures(accountToMoveToSignature);

    FlowSession session1 = initiateFlow(lspAccountInfo.getHost());
    List<TransactionSignature> accountToMoveToSignature1 = (List<TransactionSignature>) subFlow(new CollectSignatureFlow(signedByCounterParty,
                    session1,lspAccount.getOwningKey()));
    signedByCounterParty = signedByCounterParty.withAdditionalSignatures(accountToMoveToSignature1);

    progressTracker.setCurrentStep(FINALISING_TRANSACTION);
    return subFlow(new FinalityFlow(signedByCounterParty, session,session1));
    getOurIdentity()).collect(Collectors.toList())));
}

Is there any way to show the name of the participant accounts instead of the IDs while querying the vault.

The Output of vault Query is this

1

1 Answers

1
votes

This is an expected behaviour. When we use accounts in a state, we use the AnonymousParty class, which only has a public key and not a legal name. This is inline with the fact that accounts are not Corda identities and don't have a legal name.

You need to build a custom flow to fetch the account name. You could take help of the account service which provides api's to do so. Here is an example you could refer: https://github.com/corda/bootcamp-cordapp/blob/accounts-demo/src/main/java/bootcamp/QuerybyAccount.java