【问题标题】:TokenPointer’s & SendStateAndRefFlow()/ReceiveStateAndRefFlow()TokenPointer 的 & SendStateAndRefFlow()/ReceiveStateAndRefFlow()
【发布时间】:2021-12-19 00:27:33
【问题描述】:

设置:

  • Corda 4.6
  • 使用 MockNode 进行测试

场景:

我正在构建原子交换,我将指向 EvolvableTokenType 的 FungibleToken 交换为代表 USD 的 FungibleToken。 过去我一直这样使用 SendTransactionFlow()/ReceiveTransactionFlow():

SignedTransaction stx = subFlow(new ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE));

效果很好,因为它将所有状态保存到接收方节点上的保险库中——包括参考状态(即 FungibleToken 指向的 EvolvableTokenType)。然而在thisstackoverflow 的回答中,Mike Hearn 提到:

“您也可以使用 SendStateAndRefFlow,这将减少 支持新交所账本加密的迁移工作 未来。”

所以我正在尝试切换到 SendStateAndRefFlow()/ReceiveStateAndRefFlow()。

问题:

我无法使用 ReceiveStateAndRefFlow() 强制将状态保存在保管库中。交易存储中只存储交易链。

当我尝试将指向 EvolvableTokenType 的 FungibleToken 添加到接收方节点(构建交换的节点)上的 TransactionBuilder 时:

List<StateAndRef<FungibleToken>> inputs = subFlow(new ReceiveStateAndRefFlow<>(otherSideSession));
txBuilder.addInputState(inputs.get(0));

…我会得到一个错误:

java.lang.IllegalStateException: The LinearState with ID 598e1d3e-3b89-428c-b343-21c54a066856 is unknown to this node or it has been exited from the ledger.

错误所指的 UUID 是 FungibleToken 指向的 EvolvableTokenType 的 LinearId。

问题:

  1. Mike 的 cmets 还有效吗?我是否应该避免使用 SendTransactionFlow/ReceiveTransactionFlow,因为 SGX 会破坏其功能?

  2. 我如何发送和保存 EvolvableTokenType FungibleToken 的点,以便 TransactionBuilder 可以使用状态?

【问题讨论】:

    标签: corda


    【解决方案1】:

    如果 R3 或更有经验的 CorDapp 开发人员对此进行权衡并回答我的第一个问题,我仍然会很感激。我很好奇搬到新交所是否也会破坏我确定的解决方案,因为它基本上是一个手动的 SendTransactionFlow/ReceiveTransactionFlow:

    解决方案 1:

    在通知观察者的documentation 中使用相同的代码:

    在出售 FungibleToken 的节点上(他们有一个 SignedTransaction 的副本,该副本创建了 FungibleToken 指向的 EvolvableTokenType)

    SignedTransaction forwardFtStx = getServiceHub().getValidatedTransactions().getTransaction(forwardFtStateAndRef.getRef().getTxhash());
    
    if(forwardFtStx != null) {
        otherSideSession.send(forwardFtStx);
    } else {
        throw new FlowException("Unable to locate SignedTransaction that created ForwardFt");
    }
    

    在购买 FungibleToken 的节点上:

    SignedTransaction forwardFtStx = otherSideSession.receive(SignedTransaction.class).unwrap(stx -> {
    
        if (stx.getId().equals(forwardFtStateAndRef.getRef().getTxhash())) {
            return stx;
        } else {
            throw new FlowException("SignedTransaction received by seller that created ForwardFt does not match StateAndRef<ForwardFt> sent earlier");
        }
    });
    
    getServiceHub().recordTransactions(StatesToRecord.ALL_VISIBLE, Collections.singletonList(forwardFtStx));
    

    解决方案 2:

    您可以撤消事务,以便在其保管库中具有 EvolvableTokenType 的节点构建 TransactionBuilder。这种方法的问题是它无法处理指向 EvolvableTokenType 的 FungibleToken 被交易为指向 EvolvableTokenType 的不同 FungibleToken 的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 2011-09-26
      • 2019-12-17
      • 2017-12-26
      • 2015-04-21
      相关资源
      最近更新 更多