我正在探索Corda。我从cordapp-template-java
开始。我试图添加一个流NewFlow
,该流具有一个Item作为成员变量。项目的定义
@CordaSerializable
public class Item {
private final String name;
private final Party owner;
public Item(String name, Party owner) {
this.name = name;
this.owner = owner;
}
public String getName() {
return name;
}
public Party getOwner() {
return owner;
}
}
部署节点后,我无法调用此流程。这就是我调用NewFlow
的方式:
start NewFlow price: 100, item: { name: Item1, owner: "O=PartyB,L=New York,C=US" }, timeFrame: "toTimeStr=12-DEC-2019 12:26:45", parties:["O=PartyB,L=New York,C=US"]
它引发错误-
No matching constructor found:
- [java.lang.Integer, com.template.states.Item, com.template.states.TimeFrame, net.corda.core.identity.Party[]]: Could not parse as a command: Cannot construct instance of `com.template.states.Item` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; line: -1, column: -1]
我需要对类Item
做些什么?还是这只是一些序列化问题?
编辑:
Flow类的摘录-
public class NewFlow extends FlowLogic<Void> {
private final int price;
private final Item item;
private final TimeFrame timeframe;
private final List<Party> parties;
/**
* The progress tracker provides checkpoints indicating the progress of the flow to observers.
*/
private final ProgressTracker progressTracker = new ProgressTracker();
public PostTenderFlow(Integer price, Item item, TimeFrame timeframe, Party[] parties) {
this.price = price;
this.item = item;//new Item(itemName, getOurIdentity());
this.timeframe = timeframe;
this.parties= Arrays.asList(parties);
}
答案 0 :(得分:1)
您的错误提示“未找到匹配的构造函数”。问题出在您定义的Flow类上。您需要在流类中有一个构造函数,该构造函数接受您从命令行传递的参数。
例如,如果您的NewFlow类具有构造函数:
public NewFlow(int price, String someData){
...
}
您可以使用以下方法开始流程:
flow start NewFlow price: 100, someData: "My Data"