问题
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