blockchain - 在 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;
}
}
解决方案
内部帐户只是类型的corda状态
AccountInfo
,因此您可以查询保险库以列出节点知道使用的所有帐户:run vaultQuery contractStateType: com.r3.corda.lib.accounts.contracts.states.AccountInfo
响应者流程中没有任何特定的更改,请确保您在发起者流程中使用正确的会话。在此处查看示例存储库中可用的一些示例:https ://github.com/corda/samples-java/tree/master/Accounts
推荐阅读
- swift - 测试 NSURLSession“无法将简历发送到类 NSURLSessionDataTask 的抽象实例”
- algorithm - 有效地在由整数重复子字符串形成的字符串中查找字符
- bash - 如何先扩展字符串然后评估?
- jquery - 将 div 定位到展开到顶部
- python - python import swig库失败,动态模块未定义init函数
- css - CSS 不工作/在 Codepen 反应笔上加载
- postgresql - Odoo V12 CE 分段错误(核心转储)在安装 Odoo 12 后创建数据库时面临此问题
- python - 如果滚动 7 天间隔中出现的次数大于 x,则熊猫计数
- php - laravel 5.7 中的 mysqli multi_query
- php - 如何设置 Laravel 和 Vuejs 可以访问的全局变量?