How to provide a CorDapp with custom config in Corda?

对着背影说爱祢 提交于 2019-12-17 19:55:41

问题


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.

Is there a best practice how to do that? Maybe even sample?


回答1:


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.

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()
}

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

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



来源:https://stackoverflow.com/questions/48500297/how-to-provide-a-cordapp-with-custom-config-in-corda

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!