如何在Corda中为CorDapp提供自定义配置? [英] How to provide a CorDapp with custom config in Corda?

查看:105
本文介绍了如何在Corda中为CorDapp提供自定义配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要与Corda flow内部的外部系统进行通信,因此应该有一种方法可以进行一些配置(例如,外部API的用户名和密码)。例如,它可能是.properties或.yaml文件。

I need to communicate with external system inside Corda flow so there should be a way to deliver some configuration (e.g. username and password for external API). It may be .properties or .yaml file for example.

是否存在最佳做法?

推荐答案

Corda 3不具有向节点提供任意配置文件的内置支持。将使用CorDapp配置文件在Corda 4中添加对此的支持: https://docs.corda.net/head/cordapp-build-systems.html#cordapp-configuration-files

Corda 3 doesn't have built-in support for providing arbitrary configuration files to nodes. Support for this will be added in Corda 4 using CorDapp configuration files: https://docs.corda.net/head/cordapp-build-systems.html#cordapp-configuration-files.

,您可以将本地文件放在节点目录中,并在流中直接从中读取。例如,如果我在节点的根目录中放置一个名为 properties.txt 的配置文件,则可以使用以下流程读取其内容:

In the meantime, you can place a local file within the node directory and read from it directly within a flow. For example, if I place a configuration file called properties.txt in the node's root directory, I can then read back its contents using the following flow:

@InitiatingFlow
@StartableByRPC
class ReadPropertiesFlow : FlowLogic<String>() {
    override val progressTracker = ProgressTracker()

    @Suspendable
    override fun call() = File("./properties.txt").readText()
}

节点的工作目录始终是节点的根目录(使用 MockNetwork 时除外)流测试)。

The node's working directory is always the node's root directory (except for when using the MockNetwork for flow tests).

或者,您可以将信息直接存储在节点的数据库中。有关示例,请参见数据库中的NODE_PROPERTIES表

Alternatively, you could store information directly in the node's database. See NODE_PROPERTIES table in database for an example.

这篇关于如何在Corda中为CorDapp提供自定义配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆