【问题标题】:How to fetch data from custom table in Corda如何从 Corda 中的自定义表中获取数据
【发布时间】:2020-05-29 18:50:15
【问题描述】:

我们正在尝试使用带有状态作为查询条件的保险库查询从我们的自定义表中获取数据。但是我们得到一个模型类的状态,它包含旧值而不是数据库中的新值。有人可以指出一个从自定义表中获取数据并将其映射到corda中的模型类的示例。

【问题讨论】:

  • 您是否实现了自己的架构?
  • 是的..它在状态类中映射..
  • 你能粘贴你的代码吗?干杯

标签: kotlin corda


【解决方案1】:

通过覆盖 QueryableState 类的方法 generateMappedObject,可以在状态类中提供从模式到状态属性的映射。确保你的状态实现了 QueryableState 类。

@Override public PersistentState generateMappedObject(MappedSchema schema) {
        if (schema instanceof IOUSchemaV1) {
            return new IOUSchemaV1.PersistentIOU(
                    this.lender.getName().toString(),
                    this.borrower.getName().toString(),
                    this.value,
                    this.linearId.getId());
        } else {
            throw new IllegalArgumentException("Unrecognised schema $schema");
        }
    }

然后您可以使用诸如

之类的保管库查询来查询数据库
QueryCriteria queryCriteria = new QueryCriteria.VaultQueryCriteria().withStatus(Vault.StateStatus.UNCONSUMED);

List<StateAndRef<IOUState>> iouStates = getServiceHub().getVaultService()
                .queryBy(IOUState, queryCriteria).getStates();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 2021-04-24
    • 2014-11-29
    • 1970-01-01
    相关资源
    最近更新 更多