【问题标题】:Error While Fetching Data from Corda Custom Tables从 Corda 自定义表中获取数据时出错
【发布时间】:2017-09-15 20:21:39
【问题描述】:

如何从 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);
}
  1. 在 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;
    }
    

    }

  2. 我的 Schema 类是 ---

    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;
    }
    

    } }

  3. 我的州有:-

    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 接口实现中的架构。

谁能帮忙解决这个问题。

【问题讨论】:

    标签: corda


    【解决方案1】:

    尝试从插件声明中删除implements WebServerPluginRegistry

    【讨论】:

    • 感谢乔尔的回复...但我尝试删除上述更改..它没有工作..
    • @Jayant 您使用的是哪个corda_gradle_plugins_version 版本?你能检查一下build.gradle文件的顶部吗?
    • ext.corda_release_version = '0.14.0' ext.corda_gradle_plugins_version = '0.14.0' ext.kotlin_version = '1.1.2' ext.quasar_version = '0.7.6' ext.junit_version = '4.12 '
    • @@Joel.. 它现在可以工作了.. 我分离了插件... 谢谢你的帮助.. 干杯..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多