【问题标题】:How do get rid of java.lang.IllegalArgumentException: Unable to match key(s) in corda?如何摆脱 java.lang.IllegalArgumentException: Unable to match key(s) in corda?
【发布时间】:2021-08-25 12:05:42
【问题描述】:

我创建了一个交易对手会话,发行人通过将其密钥传递给 signInitialTransaction 来签署交易。然后,当我调用 CollectSignaturesFlow 来获取买家的签名时,它会抛出“无法匹配密钥”异常。

不知道出了什么问题。

这是我的发起人流程。

package com.template.flows;

@InitiatingFlow
@StartableByRPC
public class InitiateTicketMovementFlow extends FlowLogic<String> {
private final String buyer;
private final String issuer;
private final StateRef assetReference;

public InitiateTicketMovementFlow(String buyer, String issuer, String hash, int index) {
    this.buyer = buyer;
    this.issuer = issuer;
    this.assetReference = new StateRef(SecureHash.parse(hash), index);
}

@Override
@Suspendable
public String call() throws FlowException {

    final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);

    AccountInfo issuerAccountInfo = UtilitiesKt.getAccountService(this)
            .accountInfo(issuer).get(0).getState().getData();

    AccountInfo receiverAccountInfo = UtilitiesKt.getAccountService(this)
            .accountInfo(buyer).get(0).getState().getData();

    AnonymousParty buyerAccount = subFlow(new RequestKeyForAccount(receiverAccountInfo));

    QueryCriteria.VaultQueryCriteria queryCriteria = new QueryCriteria.VaultQueryCriteria()
            .withStateRefs(ImmutableList.of(assetReference));

    StateAndRef<CustomTicket> ticketStateStateAndRef = getServiceHub().getVaultService()
            .queryBy(CustomTicket.class, queryCriteria).getStates().get(0);

    CustomTicket ticketState = ticketStateStateAndRef.getState().getData();

    TransactionBuilder txBuilder = new TransactionBuilder(notary);

    MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(),
            ticketState.toPointer(CustomTicket.class), receiverAccountInfo.getHost());

    FlowSession buyerSession = initiateFlow(receiverAccountInfo.getHost());
    buyerSession.send(ticketState.getValuation());

    List<StateAndRef<FungibleToken>> inputs = subFlow(new ReceiveStateAndRefFlow<>(buyerSession));

    List<FungibleToken> moneyReceived = buyerSession.receive(List.class).unwrap(value -> value);

    MoveTokensUtilities.addMoveTokens(txBuilder, inputs, moneyReceived);

    SignedTransaction selfSignedTransaction = getServiceHub().
            signInitialTransaction(txBuilder, ImmutableList.of(issuerAccountInfo.getHost().getOwningKey()));


    SignedTransaction signedTransaction = subFlow(new CollectSignaturesFlow(
            selfSignedTransaction, Arrays.asList(buyerSession), Collections.singleton(issuerAccountInfo.getHost().getOwningKey())));

    SignedTransaction stx = subFlow(new FinalityFlow(
            signedTransaction, ImmutableList.of(buyerSession)));

    subFlow(new UpdateDistributionListFlow(stx));

    return "\nTicket is sold to "+ buyer;
    }
}

【问题讨论】:

  • 这给出了公钥 - issuerAccountInfo.getHost().getOwningKey()。在签署交易时已包含此内容。

标签: blockchain corda


【解决方案1】:

这里的问题似乎是您以错误的方式获取买家帐户?或者最终流程调用可能已关闭。看看我们的样本。

也许可以尝试这样的方法来获取您的帐户信息

AccountInfo targetAccount = accountService.accountInfo(<STRING NAME OF ACCOUNT >).get(0);

src 是我们的 corda 示例仓库:https://github.com/corda/samples-java/blob/master/Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/SendShippingRequest.java#L80

另外,请注意最终调用的不同之处:

https://github.com/corda/samples-java/blob/master/Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/SendShippingRequest.java#L112

【讨论】:

    猜你喜欢
    • 2018-10-14
    • 2022-12-27
    • 2011-10-15
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    相关资源
    最近更新 更多