corda transactionBuilder接受状态列表作为输入状态

corda transactionBuilder接受状态列表作为输入状态,corda,Corda,我试图通过添加以下内容将列表>作为inputState添加到TransactionBuilder中 TransactionBuilder(notary = notary). withItems(list of states, StateAndContract(output State, CONTRACT_ID),

我试图通过添加以下内容将列表>作为inputState添加到TransactionBuilder中

TransactionBuilder(notary = notary).
                                    withItems(list of states,
                                    StateAndContract(output State, CONTRACT_ID),
                                    Command)
获取错误的参数类型:class java.util.ArrayList,如何将状态列表作为输入传递给TransactionBuilder?

如您所见,
withItems
模式根据类类型匹配状态

/** A more convenient way to add items to this transaction that calls the add* methods for you based on type */
fun withItems(vararg items: Any): TransactionBuilder {
    for (t in items) {
        when (t) {
            is StateAndRef<*> -> addInputState(t)
            is SecureHash -> addAttachment(t)
            is TransactionState<*> -> addOutputState(t)
            is StateAndContract -> addOutputState(t.state, t.contract)
            is ContractState -> throw UnsupportedOperationException("Removed as of V1: please use a StateAndContract instead")
            is Command<*> -> addCommand(t)
            is CommandData -> throw IllegalArgumentException("You passed an instance of CommandData, but that lacks the pubkey. You need to wrap it in a Command object first.")
            is TimeWindow -> setTimeWindow(t)
            is PrivacySalt -> setPrivacySalt(t)
            else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
        }
    }
    return this
}
/**向此事务添加项的更方便的方法,它基于类型为您调用add*方法*/
趣味withItems(vararg items:Any):TransactionBuilder{
对于(t个项目){
时间(t){
is StateAndRef->addInputState(t)
is SecureHash->addAttachment(t)
是TransactionState->addOutputState(t)
is StateAndContract->addOutputState(t.state,t.contract)
is ContractState->throw UnsupportedOperationException(“从V1起删除:请改用StateAndContract”)
is命令->添加命令(t)
is CommandData->throw IllegalArgumentException(“您传递了CommandData的一个实例,但该实例缺少pubkey。您需要先将其包装到命令对象中。”)
是时间窗口->设置时间窗口(t)
is PrivacyStat->SetPrivacyStat(t)
else->抛出IllegalArgumentException(“错误的参数类型:${t.javaClass}”)
}
}
还这个
}
从这段代码片段可以清楚地看出,withItems不接受状态列表。因此,如果您希望添加输入状态,则必须单独输入它们(即
withItems(state1、state2、state3等)
)。请小心添加正确的状态类型(输入状态为state类型,如果输出状态为TransactionState类型。

如您所见,
with items
模式根据类类型匹配状态

/** A more convenient way to add items to this transaction that calls the add* methods for you based on type */
fun withItems(vararg items: Any): TransactionBuilder {
    for (t in items) {
        when (t) {
            is StateAndRef<*> -> addInputState(t)
            is SecureHash -> addAttachment(t)
            is TransactionState<*> -> addOutputState(t)
            is StateAndContract -> addOutputState(t.state, t.contract)
            is ContractState -> throw UnsupportedOperationException("Removed as of V1: please use a StateAndContract instead")
            is Command<*> -> addCommand(t)
            is CommandData -> throw IllegalArgumentException("You passed an instance of CommandData, but that lacks the pubkey. You need to wrap it in a Command object first.")
            is TimeWindow -> setTimeWindow(t)
            is PrivacySalt -> setPrivacySalt(t)
            else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
        }
    }
    return this
}
/**向此事务添加项的更方便的方法,它基于类型为您调用add*方法*/
趣味withItems(vararg items:Any):TransactionBuilder{
对于(t个项目){
时间(t){
is StateAndRef->addInputState(t)
is SecureHash->addAttachment(t)
是TransactionState->addOutputState(t)
is StateAndContract->addOutputState(t.state,t.contract)
is ContractState->throw UnsupportedOperationException(“从V1起删除:请改用StateAndContract”)
is命令->添加命令(t)
is CommandData->throw IllegalArgumentException(“您传递了CommandData的一个实例,但该实例缺少pubkey。您需要先将其包装到命令对象中。”)
是时间窗口->设置时间窗口(t)
is PrivacyStat->SetPrivacyStat(t)
else->抛出IllegalArgumentException(“错误的参数类型:${t.javaClass}”)
}
}
还这个
}

从这段代码片段可以清楚地看出,withItems不接受状态列表。因此,如果您希望添加输入状态,则必须单独输入它们(即,
withItems(state1、state2、state3等)
)。请小心添加正确的状态类型(输入状态为state类型,如果输出状态为TransactionState类型。

请尝试
使用items(*listOfStates.toTypedArray())
而不是调用
使用items(listOfStates)
,尝试
使用items(*listOfStates.toTypedArray())