【发布时间】:2018-09-17 06:27:56
【问题描述】:
我正在研究一个简单的用例,在该用例中,我需要将状态作为事务中的输入并生成新的输出状态。但我希望状态的内容是一样的。我只想将输入状态标记为已使用并生成具有相同内容的新输出状态。我正在编写的 Cordapp 是用 Java 编写的。
如何在 Corda 中做到这一点?
【问题讨论】:
标签: java blockchain rpc corda
我正在研究一个简单的用例,在该用例中,我需要将状态作为事务中的输入并生成新的输出状态。但我希望状态的内容是一样的。我只想将输入状态标记为已使用并生成具有相同内容的新输出状态。我正在编写的 Cordapp 是用 Java 编写的。
如何在 Corda 中做到这一点?
【问题讨论】:
标签: java blockchain rpc corda
为此,您需要执行三个步骤:
这是一个代表义务的状态的示例:
// Retrieve the state using its linear ID.
QueryCriteria queryCriteria = new QueryCriteria.LinearStateQueryCriteria(
null,
ImmutableList.of(linearId),
Vault.StateStatus.UNCONSUMED,
null);
List<StateAndRef<Obligation>> obligations = getServiceHub().getVaultService().queryBy(Obligation.class, queryCriteria).getStates();
if (obligations.size() != 1) {
throw new FlowException(String.format("Obligation with id %s not found.", linearId));
}
StateAndRef<Obligation> inputStateAndRef = obligations.get(0);
Obligation input = inputStateAndRef.getState().getData();
// Create the new output state.
Obligation output = new Obligation(input.getAmount(), input.getLender(), input.getBorrower(), input.getPaid(), input.getLinearId());
// Creating the transaction builder (don't forget to add a command!)
final TransactionBuilder builder = new TransactionBuilder(notary)
.addInputState(inputStateAndRef)
.addOutputState(output, OBLIGATION_CONTRACT_ID);
【讨论】: