首页 > 解决方案 > 在 corda 中使用帐户编写流

问题描述

我在 Corda 中使用帐户。在我的代码中成功创建了新帐户,但是,我在做这两件事时遇到了困难。1.) 如何检查帐户是否实际创建并存在于节点中,这意味着我们是否可以检查 Corda 中所有帐户的列表。

2.) 如何为账户编写响应流程,意味着我的交易流程无法正常工作。如果我们现在开始使用帐户库,响应者流程经典代码是否有任何更改?

我的代码如下:

@InitiatedBy(Proposal.class)
public static class ProposalAcceptance extends FlowLogic<Void> {

    //private variable
    private FlowSession counterpartySession;

    //Constructor
    public ProposalAcceptance(FlowSession counterpartySession) {
        this.counterpartySession = counterpartySession;
    }

    @Suspendable
    @Override
    public Void call() throws FlowException {
        SignedTransaction signedTransaction = subFlow(new SignTransactionFlow(counterpartySession) {
            @Suspendable
            @Override
            protected void checkTransaction(SignedTransaction stx) throws FlowException {
                /*
                 * SignTransactionFlow will automatically verify the transaction and its signatures before signing it.
                 * However, just because a transaction is contractually valid doesn’t mean we necessarily want to sign.
                 * What if we don’t want to deal with the counterparty in question, or the value is too high,
                 * or we’re not happy with the transaction’s structure? checkTransaction
                 * allows us to define these additional checks. If any of these conditions are not met,
                 * we will not sign the transaction - even if the transaction and its signatures are contractually valid.
                 * ----------
                 * For this hello-world cordapp, we will not implement any aditional checks.
                 * */
            }
        });
        //Stored the transaction into data base.
        subFlow(new ReceiveFinalityFlow(counterpartySession));
        return null;
    }
}

标签: blockchaincorda

解决方案


  1. 内部帐户只是类型的corda状态AccountInfo,因此您可以查询保险库以列出节点知道使用的所有帐户:

    run vaultQuery contractStateType: com.r3.corda.lib.accounts.contracts.states.AccountInfo

  2. 响应者流程中没有任何特定的更改,请确保您在发起者流程中使用正确的会话。在此处查看示例存储库中可用的一些示例:https ://github.com/corda/samples-java/tree/master/Accounts


推荐阅读