Corda 在java中使用QueryableState运行NodeDriver测试时出现未知实体错误
当运行使用QueryableState的NodeDriver测试时,我会收到一个错误,显示“未知实体”。我确认如果我从状态中删除QueryableState代码,测试将成功运行 java.util.concurrent.ExecutionException: net.corda.core.CORDARUNTIMEEException: java.lang.IllegalArgumentException:未知实体: com.template.states.IOUCustomSchema$PersistentIOUCorda 在java中使用QueryableState运行NodeDriver测试时出现未知实体错误,corda,Corda,当运行使用QueryableState的NodeDriver测试时,我会收到一个错误,显示“未知实体”。我确认如果我从状态中删除QueryableState代码,测试将成功运行 java.util.concurrent.ExecutionException: net.corda.core.CORDARUNTIMEEException: java.lang.IllegalArgumentException:未知实体: com.template.states.IOUCustomSchema$Pers
super(IOUCustomSchema.class, 1, ImmutableList.of(PersistentIOU.class));
以下是QueryableState的实现:
@BelongsToContract(IOUContract.class)
public class IOUState implements ContractState, LinearState, QueryableState {
public final Amount<TokenType> amount;
public final Party lender;
public final Party borrower;
public final Amount<TokenType> paid;
private final UniqueIdentifier linearId;
// Private constructor used only for copying a State object
@ConstructorForDeserialization
private IOUState(Amount<TokenType> amount, Party lender, Party borrower, Amount<TokenType> paid, UniqueIdentifier linearId){
this.amount = amount;
this.lender = lender;
this.borrower = borrower;
this.paid = paid;
this.linearId = linearId;
}
public IOUState(Amount<TokenType> amount, Party lender, Party borrower) {
this(amount, lender, borrower, new Amount<>(0, amount.getToken()), new UniqueIdentifier());
}
/** omitting boiletplate */
/**
* This method will return a list of the nodes which can "use" this state in a valid transaction. In this case, the
* lender or the borrower.
*/
@Override
public List<AbstractParty> getParticipants() {
return ImmutableList.of(lender, borrower);
}
@Override
public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof IOUCustomSchema) {
return new IOUCustomSchema.PersistentIOU(linearId.getId(), lender.getName().toString(),
borrower.getName().toString(), amount.getQuantity());
} else{
throw new IllegalArgumentException("Unrecognised schema " + schema);
}
}
@Override
public Iterable<MappedSchema> supportedSchemas() {
return ImmutableList.of(new IOUCustomSchema());
}
}
您没有正确实现自定义架构;你应该至少有两门课:
IOUCustomSchema
应该只是一个空类,它表示ioState的模式族。请看这里:IOUCustomSchemaV1
;因此,在您的代码中:
a。将类重命名为IOUCustomSchemaV1
B将构造函数重命名为
IOUCustomSchemaV1
C保持
super(IOUCustomSchema.class…
原样。d、 在您所在的州,在所有情况下也将
IOUCustomSchema
重命名为IOUCustomSchemaV1
cordapp example
项目下看到正确的实施:
这实际上只是一个复制粘贴错误。我需要更改下面的行以使事情正常进行
super(IOUCustomSchema.class, 1, ImmutableList.of(PersistentState.class));
我在这里使用的是通用PersistentState,而不是我的自定义PersistentYou
super(IOUCustomSchema.class, 1, ImmutableList.of(PersistentIOU.class));