如何从corda自定义表中获取数据? 我的示例代码如下: -
Api layer -- getIous() method
{
Field attributeValue=IOUSchemaV1.PersistentIOU.class.getDeclaredField("value");
CriteriaExpression currencyIndex = Builder.equal(attributeValue, "12");
QueryCriteria.VaultCustomQueryCriteria criteria = new
QueryCriteria.VaultCustomQueryCriteria(currencyIndex);
vaultStates = services.vaultQueryByCriteria(criteria,IOUState.class);
}
在ExamplePlugin中,我添加了以下代码进行架构注册
public class ExamplePlugin extends CordaPluginRegistry implements
WebServerPluginRegistry
{
@NotNull
@Override
public Set<MappedSchema> getRequiredSchemas()
{
Set<MappedSchema> requiredSchemas = new HashSet<>();
requiredSchemas.add(new IOUSchemaV1());
return requiredSchemas;
}
}
我的架构类是---
public final class IOUSchema {
}
@CordaSerializable
public class IOUSchemaV1 extends MappedSchema
{
public IOUSchemaV1() {
super(IOUSchema.class, 1, ImmutableList.of(PersistentIOU.class));
}
@Entity
@Table(name = "iou_states")
public static class PersistentIOU extends PersistentState {
@Column(name = "sender_name") private final String senderName;
@Column(name = "recipient_name") private final String recipientName;
@Column(name = "value") private final int value;
public PersistentIOU(String senderName, String recipientName, int value) {
this.senderName = senderName;
this.recipientName = recipientName;
this.value = value;
}
public String getSenderName() {
return senderName;
}
public String getRecipientName() {
return recipientName;
}
public int getValue() {
return value;
}
} }
我的州有: -
public class IOUState implements LinearState, QueryableState
{
--- some code goes here and below methods as well.---
@Override
public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof IOUSchemaV1) {
return new IOUSchemaV1.PersistentIOU(
this.sender.getName().toString(),
this.recipient.getName().toString(),
this.iou.getValue());
} else {
throw new IllegalArgumentException("Unrecognised schema $schema");
}
}
@Override
public Iterable<MappedSchema> supportedSchemas() {
return ImmutableList.of(new IOUSchemaV1());
}
}
但是我一直在低于例外。
引起:net.corda.core.node.services.VaultQueryException:
请在CorDapp的CordaPluginRegistry配置中注册实体'com.example.schema.IOUSchemaV1'(requiredSchemas属性) 并确保已声明(在supportedSchemas()中)并映射(在generateMappedObject()中) 相关合同状态的QueryableState接口实现中的模式。
任何人都可以帮忙解决这个问题。
答案 0 :(得分:0)
尝试从插件声明中删除implements WebServerPluginRegistry
。