从 corda 中的交易中检索帐户名
Retrieving account name from a transaction in corda
我在 Corda 中创建了一个流程,它与另外两个分别托管在不同节点上的帐户共享一个状态。
在使用 VaultQuery 查询任一参与者的保险库时,它会显示一些 ID 来代替参与者的姓名。流的调用函数的代码是这样的
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())));
}
有什么方法可以在查询保险库时显示参与者帐户的名称而不是 ID。
这是预期的行为。当我们在状态下使用帐户时,我们使用 AnonymousParty class,它只有一个 public 密钥,而不是合法名称。这符合账户不是 Corda 身份并且没有合法名称的事实。
您需要构建自定义流程来获取帐户名称。您可以借助提供 api 的帐户服务来这样做。这是您可以参考的示例:
https://github.com/corda/bootcamp-cordapp/blob/accounts-demo/src/main/java/bootcamp/QuerybyAccount.java
我在 Corda 中创建了一个流程,它与另外两个分别托管在不同节点上的帐户共享一个状态。 在使用 VaultQuery 查询任一参与者的保险库时,它会显示一些 ID 来代替参与者的姓名。流的调用函数的代码是这样的
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())));
}
有什么方法可以在查询保险库时显示参与者帐户的名称而不是 ID。
这是预期的行为。当我们在状态下使用帐户时,我们使用 AnonymousParty class,它只有一个 public 密钥,而不是合法名称。这符合账户不是 Corda 身份并且没有合法名称的事实。
您需要构建自定义流程来获取帐户名称。您可以借助提供 api 的帐户服务来这样做。这是您可以参考的示例: https://github.com/corda/bootcamp-cordapp/blob/accounts-demo/src/main/java/bootcamp/QuerybyAccount.java